[英]Using Command Line Arguments in C# Unit Testing
我正在運行C#單元測試以運行硒測試,因此我需要登錄不同的用戶帳戶。 我正在嘗試將用戶名和密碼作為命令行參數進行檢索,但是找不到在C#visual studio單元測試中執行此操作的方法。
有人知道我該怎么做嗎?
我的部分代碼:
[TestMethod]
public void Login()
{
driver = new FirefoxDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(this.baseURL);
driver.FindElementById("ctl00_ContentPlaceHolder1_Login1_UserName").SendKeys(userID);
driver.FindElementById("ctl00_ContentPlaceHolder1_Login1_Password").SendKeys(password);
driver.FindElementById("ctl00_ContentPlaceHolder1_Login1_LoginButton").Click();
}
這里的“ userID”和“ password”應該是我的命令行參數。
預先感謝您的幫助。
在單元測試中,您不應使用來自命令行的變量輸入,而應使其恆定。
例如,您的測試應為:
[TestMethod]
public void Login()
{
driver = new FirefoxDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(this.baseURL);
driver
.FindElementById("ctl00_ContentPlaceHolder1_Login1_UserName")
.SendKeys("testuser");
driver
.FindElementById("ctl00_ContentPlaceHolder1_Login1_Password")
.SendKeys("testpass");
driver
.FindElementById("ctl00_ContentPlaceHolder1_Login1_LoginButton")
.Click();
}
然后,您應該確保在運行測試之前,已正確模擬數據庫或使用正確的狀態初始化了數據庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.