Unit testing Selenium Java测试用例不工作
我从FireFox创建了一个测试用例并执行了它。它工作得很好 我将其导出为Java测试用例。我在Eclipse中运行,但它不工作。我得到的错误如下:Unit testing Selenium Java测试用例不工作,unit-testing,testing,selenium,selenium-webdriver,Unit Testing,Testing,Selenium,Selenium Webdriver,我从FireFox创建了一个测试用例并执行了它。它工作得很好 我将其导出为Java测试用例。我在Eclipse中运行,但它不工作。我得到的错误如下: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":"Incidents"} 我的测试用例: <?xml version="1.0" encoding="UTF-8"?> <!
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":"Incidents"}
我的测试用例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://myapphost:8080/" />
<title>IncidentsListTest22</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">IncidentsListTest22</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/myapp/login/auth?usrMsg=SE</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=username</td>
<td>username</td>
</tr>
<tr>
<td>type</td>
<td>id=password</td>
<td>password</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=loginForm_submit</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Incidents</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
HTML页面
<a class="dc-mega" href="#">
Network Details
<span class="dc-mega-icon"></span>
</a>
<div class="sub-container non-mega" style="left: 138px; top: 31px; z-index: 1000;">
<ul class="sub" style="display: none;">
<li class="">
<a href="/myapp/incident/list">Incidents</a>
</li>
-
根据我的经验,硒元素在寻找元素时非常脆弱。我建议尝试使用一个非常好的Firefox插件,并导出JUnit测试用例,您可以运行它来测试您的页面。
是一个ul
标记的子项,该标记对于webdriver来说似乎是不可见的(
)。您必须首先使其可见…它告诉您无法找到文本为“事件”的链接。如果此时不查看页面的DOM(至少是元素所在的源HTML),我们将很难使用HTML测试用例提供帮助。“事件”存在于html页面中,但不直接存在于菜单栏项“详细信息”选项卡中。我的测试用例是@test
public void testIncidentsList()抛出异常{
driver.get(baseUrl+“myapp/login/auth?usrMsg=SE”);
driver.findElement(By.id(“username”)。clear()
driver.findElement(By.id(“用户名”)).sendKeys(“用户名”);
driver.findElement(By.id(“密码”)).clear();
driver.findElement(By.id(“密码”).sendKeys(“密码”);
driver.findElement(By.id(“loginForm提交”))。单击()
硒一点也不脆。测试人员需要知道正在做什么。我大量使用硒元素,并且总能找到一种方法来识别和找到我的元素
@Test
public void testIncidentsList() throws Exception { driver.get(baseUrl + "myapp/login/auth?usrMsg=SE"); driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("username");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("password");
driver.findElement(By.id("loginForm_submit")).click();
driver.findElement(By.linkText("Incidents")).click();
}
<a class="dc-mega" href="#">
Network Details
<span class="dc-mega-icon"></span>
</a>
<div class="sub-container non-mega" style="left: 138px; top: 31px; z-index: 1000;">
<ul class="sub" style="display: none;">
<li class="">
<a href="/myapp/incident/list">Incidents</a>
</li>