我有以下示例代碼,使用一個用戶名和密碼登錄到Facebook,如何使用Selenium WebDriver優雅地測試同一網站的不同用戶名和密碼?
@Test
public void fb() {
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.setPreference("general.useragent.override", "iPhone"); //this will change the user agent which will open mobile browser
WebDriver driver = new FirefoxDriver(ffprofile);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(400, 800)); //just to change the window size so that it will look like mobile ;)
driver.get("http://www.fb.com/");
driver.findElement(By.name("email")).sendKeys("user1");
driver.findElement(By.name("pass")).sendKeys("password");
driver.findElement(By.name("login")).click();
}
接着我有5個Facebook個人說用戶2用戶3,USER4,USER5和user6。我想使用這些配置文件登錄到Facebook,並進行一些自動測試。
我的問題是我應該重新寫上面的代碼5次不同的用戶名,或者有沒有其他優雅的方式來實現這個?
在此先感謝!
基於關鍵字的測試。 https://en.wikipedia.org/wiki/Keyword-driven_testing你會重複測試一組給定的關鍵字(在這種情況下,用戶/密碼對)。你的函數需要將值作爲參數:'public void fb(String user,String password){... .sendKeys(user).... sendKeys(password)....' –