我试图一个接一个地导航到两个页面。在我的主类中,我调用方法从Class1单击登录超链接,然后是45秒的超时,然后调用方法调用从class2输入凭据。理想情况下,必须先调用class1中的方法,然后在45秒后调用class2中的方法。在我的情况下,首先执行class2中的方法,然后执行class1中的方法。 PFB代码和输出。
第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