Selenium C# - methods executed in program.cs are executed in a non sequential manner

34 views Asked by At

I am trying to navigate to two pages one after another. In my main class, I am calling the method to click the login hyperlink from Class1 followed by 45 seconds of timeout and then calling calling the method to enter credentials from class2. Ideally Method from class1 must be called first then after 45 seconds method from class2 must be called. In my case method from class2 is executed first and then method from class1. PFB the code and the Output.

Class 1

class LoginPage1
    {
        public TBL_Login_Page_Object()
        {
            PageFactory.InitElements(Properties_Collection.driver, this); // this will initialize the current page
        }

        [FindsBy(How = How.XPath, Using = "html/body/div[1]/div[1]/div/div/div[5]/a")]
        public IWebElement LoginHyperlink { get; set; }

        public Login_Page_Object Click_Login_Hyperlink()
        {
           Login_Page_Object Loginpage = new Login_Page_Object();
           LoginHyperlink.Click();
       return new Login_Page_Object();
        }
}

**Second Class:**



class Login_Page_Object
    {
        public Login_Page_Object()
        {
            PageFactory.InitElements(Properties_Collection.driver, this); // this will initialize the current page
        }
public TBL_Compass_Page_Object Login(string username_input, string password_input)
        {
            Properties_Collection.driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(40));
Login_Page_Object Loginpage = new Login_Page_Object();

                Set_Data.Enter_Text("username", username_input, PropertyType.Id);
                Set_Data.Enter_Text("password", password_input, PropertyType.Id);
                Set_Data.click("Login", PropertyType.Id);

        return new TBL_Compass_Page_Object();
        }
}

**Program.cs**
[Test]
public void Login()
        { int i =1;
if (i == 1)
            {TBL_Login_Page_Object LoginHyperLink = new TBL_Login_Page_Object();
                Console.WriteLine("First Login Page Milliseconds " + DateTime.Now.Millisecond);
                LoginHyperLink.Click_Login_Hyperlink();
                Console.WriteLine("Click Hyper Link Milliseconds " + DateTime.Now.Millisecond);
                i = i++;
                Properties_Collection.driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(45));
                Console.WriteLine("Explicit Wait Milliseconds " + DateTime.Now.Millisecond);
                goto Login;
            }
 Login:
                Login2();
                Console.WriteLine("Second Login Page Milliseconds " + DateTime.Now.Millisecond);
}

**Output**
First Login age Milliseconds 250
Click Hyperlink  Milliseconds 279
Explicit Wait Milliseconds 290
Second Login Page Milliseconds 141
0

There are 0 answers