0
我對Selenium自動化測試相當新穎,並且遇到了某些我在視頻和教程中看不到的東西。Selenium IDE to Java
我用硒IDE記錄的測試: 通過 編輯個人資料信息的網站 記錄導航 提交更改 驗證更改
它正常工作,當我在Firefox中重播。我的問題是,當我將它導出到Java - Junit Webdriver並通過Eclipse運行測試時,需要花費很長時間才能完成這些步驟,從而導致失敗或整體失敗。
我試圖甚至一步一步地做到這一點,似乎也可以工作,但最長的部分是輸入用戶登錄信息(用戶名爲&密碼)。
有沒有這個新手沒有意識到的東西? 當通過Eclipse Junit運行導出的IDE時,它應該是「開箱即用」嗎?
package Profile;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ProfileChangeTestCase {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://gaming.twlstaging.com/";
}
@Test
public void testOpen() throws Exception {
driver.get(baseUrl);
//Click LogIn
driver.findElement(By.className("logged-out")).click();
//Enter User name
driver.findElement(By.xpath("//input[@id='login']")).clear();
driver.findElement(By.xpath("//input[@id='login']")).sendKeys("Demo");
//Enter Password
driver.findElement(By.xpath("//input[@id='login_password']")).clear();
driver.findElement(By.xpath("//input[@id='login_password']")).sendKeys("Blam!");
//Click LogIn Button
driver.findElement(By.className("login-button")).click();
//Security Alert - Selecting continue
Alert alert = driver.switchTo().alert();
alert.accept();
//Buffer for page to load
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Verify user name login by echo name to console
String text = driver.findElement(By.className("user-name")).getText();
System.out.println("Username is :" + text);
//Buffer for contents to load
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Click on Edit Profile
driver.findElement(By.xpath("//div[@id='user-navigation']/ul/li[2]/a")).click();
//Change description in profile
driver.findElement(By.name("interests")).clear();
driver.findElement(By.name("interests")).sendKeys("This was done in Selenium Eclipse");
//Update Profile
driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
}