Variables not being bound to my code module
Posted: Mon Jan 25, 2021 10:18 pm
I have a code module set up, to check for which browser is open. We have a few environments that require a login that is triggered by the browser itself (so not on the page that the tests are running). It worked in December when I set it up. But now it doesn't seem like my variables for browser and URL are being passed into the code. The only thing that changed was, I made test cases for each group of tests. So a test case for testing the global navigation, another for another part of the website. I was noticing more errors if I didn't do it that way. Global Parameters won't let me bind to the variables I have listed in my code module, but I am able to bind them on the test case level. I have a report trigger to run before my if statement and the environment is blank. That's how I know it's not getting passed. I'm not sure what else to do. I've only been using Ranorex a few months, and I'm not entirely familiar with C# at all.
Code: Select all
namespace HondaAutosTest
{
/// <summary>
/// Checks for URL that requires login and performs login sequence.
/// </summary>
[TestModule("5FED145A-A1EB-4AAD-A7E1-FC291B85C6ED", ModuleType.UserCode, 1)]
public class Login : ITestModule
{
string _BrowserName = ""; // gets name of the opened browser
public string BrowserName
{
get { return _BrowserName; }
set { _BrowserName = value; }
}
string _Environment = ""; // gets url of the environment
public string Environment
{
get { return _Environment; }
set { _Environment = value; }
}
/// <summary>
/// Constructs a new instance.
/// </summary>
public Login()
{
// Do not delete - a parameterless constructor is required!
}
/// <summary>
/// Performs the playback of actions in this module.
/// </summary>
/// <remarks>You should not call this method directly, instead pass the module
/// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
/// that will in turn invoke this method.</remarks>
void ITestModule.Run()
{
Mouse.DefaultMoveTime = 300;
Keyboard.DefaultKeyPressTime = 100;
Delay.SpeedFactor = 1.0;
var repo = HondaAutosTestRepository.Instance;
Report.Log(ReportLevel.Info, Environment);
// test for environment as some do not need a login
if (Environment == "https://staging" || Environment == "https://pat" || Environment == "https://release") {
// test for which browser is open in order to sign in properly
switch (BrowserName) {
case "chrome":
//repo.Chrome.ServerSignIn.Username.Element.SetAttributeValue("Text", "username);
//repo.Chrome.ServerSignIn.Password.Element.SetAttributeValue("Text", "password");
//repo.Chrome.ServerSignIn.SignIn.Click();
repo.Chrome.ServerSignIn.Username.Click("150;10");
repo.Chrome.ServerSignIn.Username.EnsureVisible();
Keyboard.Press("username");
repo.Chrome.ServerSignIn.Password.Click("150;10");
repo.Chrome.ServerSignIn.Password.EnsureVisible();
Keyboard.Press("password");
repo.Chrome.ServerSignIn.SignIn.Click("35;15");
break;
case "firefox":
repo.Firefox.ServerSignIn.Username.Element.SetAttributeValue("Text", "username);
repo.Firefox.ServerSignIn.Password.Element.SetAttributeValue("Text", "password");
repo.Firefox.ServerSignIn.SignIn.Click();
break;
// edge does not work on Windows Server 2016
// case "edge":
// repo.Edge.ServerSignIn.Username.Element.SetAttributeValue("Text", "username");
// repo.Edge.ServerSignIn.Password.Element.SetAttributeValue("Text", "password");
// repo.Edge.ServerSignIn.SignIn.Click();
// break;
// there is an open ticket that prevents the vehicle drop down from working
// case "IE":
// repo.IE.Username.Element.SetAttributeValue("Text", "username");
// repo.IE.Password.Element.SetAttributeValue("Text", "password");
// repo.IE.SignIn.Click();
// break;
case "default":
Report.Log(ReportLevel.Failure, "Browser was not found on system. Allowed browsers are Chrome, Edge (Chromium), Firefox or IE.");
break;
}
} Delay.Seconds(5);
}