我是一个新的测试人员,我有两个关于测试脚本的问题,我从selenium ide导出测试脚本(导出到Junit4 webdriver),然后将其粘贴到我的eclipse indigo中。但是,当我运行我的测试脚本,它只会持续到
driver.findElement(By.name("j_idt61")).click();
我的编码driver.findElement(By.linkText(“Logout”))。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;
}
}
}
请人帮我。我刚开始我的工作,确实需要这样AU tomation testing to be working properly .. THANKS :)
请把你对正在运行的HTML或尝试与公共重现这个面对网站。没有它,我们什么都不能做。 – Arran
@Arran,把IDE的HTML?你是这个意思吗 ? –