Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Selenium中传递用户名和电子邮件_C#_Selenium_Selenium Webdriver_Pageobjects - Fatal编程技术网

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

我正在使用C#,Selenium和页面对象模型

我需要了解如何将用户名和密码从测试代码传递到页面对象

我当前的测试示例如下:

[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");
}