Page 1 of 1

Variables not being bound to my code module

Posted: Mon Jan 25, 2021 10:18 pm
by tiffin.filion
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);
		}
Screenshot 2021-01-25 131648.png

Re: Variables not being bound to my code module

Posted: Tue Jan 26, 2021 10:45 am
by Stub
Do you have any module groups that don't maintain the variable binding correctly? I find that it's easy to miss these, especially when copy/paste duplicating things. Also when created from a Test Case, I think they can get default parameters bound to them, or something along those lines as I forget precisely now. I tend to work through the chain of bound variables to find the misconnection.

Do you have any Unbound Variable warnings anywhere e.g. in the test report or in the Data binding column of the Test Suite?

Re: Variables not being bound to my code module

Posted: Tue Jan 26, 2021 6:13 pm
by tiffin.filion
Stub wrote:
Tue Jan 26, 2021 10:45 am
Do you have any module groups that don't maintain the variable binding correctly? I find that it's easy to miss these, especially when copy/paste duplicating things. Also when created from a Test Case, I think they can get default parameters bound to them, or something along those lines as I forget precisely now. I tend to work through the chain of bound variables to find the misconnection.

Do you have any Unbound Variable warnings anywhere e.g. in the test report or in the Data binding column of the Test Suite?
I currently don't have any groups set up yet. And no warnings about unbound variables. I was getting a warning, but then I went through and removed and rebound everything and the warning went away. But the login code module still isn't working.