C# 如何在Selenium中传递用户名和电子邮件
我正在使用C#,Selenium和页面对象模型 我需要了解如何将用户名和密码从测试代码传递到页面对象 我当前的测试示例如下:C# 如何在Selenium中传递用户名和电子邮件,c#,selenium,selenium-webdriver,pageobjects,C#,Selenium,Selenium Webdriver,Pageobjects,我正在使用C#,Selenium和页面对象模型 我需要了解如何将用户名和密码从测试代码传递到页面对象 我当前的测试示例如下: [TestMethod] public void Registeruser() { Registrationpage.GoTo(); Registrationpage.Enterusername(); Registrationpage.EnterEmail(); } 从注册页面提取(页面对象) 如您所见,目前我的入口位于pageobject
[TestMethod]
public void Registeruser()
{
Registrationpage.GoTo();
Registrationpage.Enterusername();
Registrationpage.EnterEmail();
}
从注册页面提取(页面对象)
如您所见,目前我的入口位于pageobject的sendkeys
中
相反,我希望能够在测试代码中指定testusername
和testemail
条目,这样我就可以改变每次测试中输入的文本
我知道我需要将它们指定为字符串,但我不太明白如何在pageobject代码中实现这一点,我希望这是有意义的,感谢您的帮助(以下是我想要做的)
您可能需要更改方法以接受
string
参数
public static void Enterusername(string testusername)
{
Driver.Instance.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).SendKeys(testusername);
}
public static void EnterEmail(string testemail)
{
Driver.Instance.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Email")).SendKeys(testemail);
}
然后使用字符串调用这些方法:
[TestMethod]
public void Registeruser()
{
Registrationpage.GoTo();
Registrationpage.Enterusername("user3451887");
Registrationpage.EnterEmail("user3451887@stackoverflow.com");
}
public static void Enterusername(string testusername)
{
Driver.Instance.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_UserName")).SendKeys(testusername);
}
public static void EnterEmail(string testemail)
{
Driver.Instance.FindElement(By.Id("MainContent_RegisterUser_CreateUserStepContainer_Email")).SendKeys(testemail);
}
[TestMethod]
public void Registeruser()
{
Registrationpage.GoTo();
Registrationpage.Enterusername("user3451887");
Registrationpage.EnterEmail("user3451887@stackoverflow.com");
}