我是一个新的测试人员,我有两个关于我的测试脚本的问题,我从 selenium ide 导出我的测试脚本(导出到 Junit4 webdriver),然后将它粘贴到我的 eclipse indigo 中。但是当我运行我的测试脚本时,它只会运行到
driver.findElement(By.name("j_idt61")).click();
在那行代码之后实际上又多了一行,即单击注销链接driver.findElement(By.linkText("Logout")).click();
但硒似乎找不到linkText“ Logout
”..
这是我的代码
package admin ;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class login {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = " here I put my website URL";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testLogin() throws Exception {
driver.get(baseUrl + "/admin/pages/login.xhtml");
driver.findElement(By.id("j_username")).click();
driver.findElement(By.id("j_username")).clear();
driver.findElement(By.id("j_username")).sendKeys("sasa");
driver.findElement(By.id("j_password")).click();
driver.findElement(By.id("j_password")).clear();
driver.findElement(By.id("j_password")).sendKeys("sasasamsudin");
driver.findElement(By.name("j_idt61")).click();
driver.findElement(By.linkText("Logout")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
public boolean isElementPresent(By id) {
try {
driver.findElements(By.id("J_idt16:J_idt30"));
return true;
} catch (org.openqa.selenium.NoSuchElementException e) {
return false;
}
}
public boolean isElementVisible(By id)
{
return driver.findElement(By.id("J_idt16:J_idt30")).isDisplayed();
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
if (acceptNextAlert) {
alert.accept();
} else {`enter code here`
alert.dismiss();
}
return alert.getText();
} finally {
acceptNextAlert = true;
}
}
}
请任何人帮助我。我刚开始我的工作,真的需要这个自动化测试才能正常工作..谢谢:)