【发布时间】:2015-02-17 13:05:15
【问题描述】:
实际上我正在尝试使用 selenium 测试 extjs 应用程序。我在 chrome 上使用基于 eclipse 的 Firefox 和 javasrcipt 的 selenium ide。我阅读了数小时以找到解决问题的方法,但在我的代码中找不到错误。
我能想到的唯一问题是 extjs 应用程序对于 selenium 来说太慢了。
因为问题如下:我编写了测试用例并使用了 waitforElementPresent 然后单击。如果我使用 selenium ID 并将速度设置为最慢点,则整个测试用例工作正常。如果我将速度增加到最大或一半,则在随机点它没有单击按钮。这可能发生在第一次尝试或最后一次尝试时。 eclipse 也会发生同样的情况,我试图通过一个有效的暂停来解决它,但没有它它也应该有效。
希望有人可以在这里帮助我。
这是我在 IDE 中的代码的一部分:
<?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="+++" />
<title>Login</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Login</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/login</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>xpath=(//input[@name='data[User][loginUsername]'])</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>xpath=(//input[@name='data[User][loginUsername]'])</td>
<td>+++</td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>xpath=(//input[@name='data[User][loginUserpassword]'])</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>xpath=(//input[@name='data[User][loginUserpassword]'])</td>
<td>+++</td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>xpath=(//button[text()='Login'])</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//button[text()='Login'])</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>xpath=(//a[contains(text(),'neue Projekte in Ihrer Region (')])</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>xpath=(//a[contains(text(),'neue Projekte in Ihrer Region (')])</td>
<td></td>
</tr>
<tr>
<td>waitForElementNotPresent</td>
<td>xpath=(//div[text()='Übertrage Daten ...'])</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>xpath=(//div[@class='x-grid3-hd-checker'])</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>xpath=(//button[text()='Logout'])</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>xpath=(//button[text()='Logout'])</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>xpath=(//button[text()='Login'])</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>2000</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
这是我的 Eclipse 代码的一部分:
public void testFirmaanlegen() throws Exception {
driver.get("+++");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa1");
try { if (isElementPresent(By.xpath("(//input[@name='data[User][loginUsername]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[User][loginUsername]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[User][loginUsername]'])")).sendKeys("****");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa2");
try { if (isElementPresent(By.xpath("(//input[@name='data[User][loginUserpassword]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[User][loginUserpassword]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[User][loginUserpassword]'])")).sendKeys("*****");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa3");
try { if (isElementPresent(By.xpath("(//button[text()='Login'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//button[text()='Login'])")).click();
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa4");
try { if (isElementPresent(By.xpath("(//button[text()='Eigene Infos'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
Thread.sleep(1000); //musste ich einbauen.
try{
driver.findElement(By.xpath("(//button[text()='Eigene Infos'])")).click();
}
catch(Exception e){
if (checkForSession() == true){
driver.findElement(By.xpath("(//button[text()='Eigene Infos'])")).click();
}
}
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa5");
try { if (isElementPresent(By.xpath("(//span[text()='Eigene Firma anlegen'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//span[text()='Eigene Firma anlegen'])")).click();
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa6");
try { if (isElementPresent(By.xpath("(//input[@id='owncompany_searchfield_name1'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@id='owncompany_searchfield_name1'])")).clear();
driver.findElement(By.xpath("(//input[@id='owncompany_searchfield_name1'])")).sendKeys("automated Test");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa7");
try { if (isElementPresent(By.xpath("(//input[@id='owncontact_searchfield_lastname'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@id='owncontact_searchfield_lastname'])")).clear();
driver.findElement(By.xpath("(//input[@id='owncontact_searchfield_lastname'])")).sendKeys("iBau");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa8");
try { if (isElementPresent(By.xpath("(//input[@id='owncompany_searchfield_postcode'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@id='owncompany_searchfield_postcode'])")).clear();
driver.findElement(By.xpath("(//input[@id='owncompany_searchfield_postcode'])")).sendKeys("48163");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa9");
try { if (isElementPresent(By.xpath("(//input[@id='owncompany_searchfield_town'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@id='owncompany_searchfield_town'])")).clear();
driver.findElement(By.xpath("(//input[@id='owncompany_searchfield_town'])")).sendKeys("Münster");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa10");
try { if (isElementPresent(By.xpath("(//input[@id='owncompany_searchfield_street'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@id='owncompany_searchfield_street'])")).clear();
driver.findElement(By.xpath("(//input[@id='owncompany_searchfield_street'])")).sendKeys("Teststreet");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa11");
try { if (isElementPresent(By.xpath("(//input[@id='owncompany_searchtype_company'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@id='owncompany_searchtype_company'])")).click();
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa12");
try { if (isElementPresent(By.xpath("(//button[text()='neue Firma anlegen'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//button[text()='neue Firma anlegen'])")).click();
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa13");
try { if (isElementPresent(By.xpath("(//input[@name='data[Company][title]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[Company][title]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[Company][title]'])")).sendKeys("Tester");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa14");
try { if (isElementPresent(By.xpath("(//input[@name='data[Company][firstname]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[Company][firstname]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[Company][firstname]'])")).sendKeys("This is an");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa15");
try { if (isElementPresent(By.xpath("(//input[@name='data[Company][name2]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[Company][name2]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[Company][name2]'])")).sendKeys("of");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa16");
try { if (isElementPresent(By.xpath("(//input[@name='data[Company][pobox]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[Company][pobox]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[Company][pobox]'])")).sendKeys("501");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa17");
try { if (isElementPresent(By.xpath("(//input[@name='data[Company][pobox_postcode]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[Company][pobox_postcode]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[Company][pobox_postcode]'])")).sendKeys("5674");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa18");
try { if (isElementPresent(By.xpath("(//input[@name='data[Company][pobox_town]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[Company][pobox_town]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[Company][pobox_town]'])")).sendKeys("jggvf");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa19");
try { if (isElementPresent(By.xpath("(//input[@name='data[Company][phone]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[Company][phone]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[Company][phone]'])")).sendKeys("034674");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa20");
try { if (isElementPresent(By.xpath("(//input[@name='data[Company][mobilephone]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[Company][mobilephone]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[Company][mobilephone]'])")).sendKeys("04745151");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa21");
try { if (isElementPresent(By.xpath("(//input[@name='data[Company][fax]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[Company][fax]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[Company][fax]'])")).sendKeys("0284552");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa22");
try { if (isElementPresent(By.xpath("(//input[@name='data[Company][email]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[Company][email]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[Company][email]'])")).sendKeys("test@test.de");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa23");
try { if (isElementPresent(By.xpath("(//input[@name='data[Company][website]'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//input[@name='data[Company][website]'])")).clear();
driver.findElement(By.xpath("(//input[@name='data[Company][website]'])")).sendKeys("http://www.google.de");
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa24");
try { if (isElementPresent(By.xpath("(//button[text()='Speichern'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//button[text()='Speichern'])")).click();
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa25");
try { if (isElementPresent(By.xpath("(//h1[text()='This is an automated Test'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa26");
try { if (isElementPresent(By.xpath("(//button[text()='Logout'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("(//button[text()='Logout'])")).click();
for (int second = 0;; second++) {
if (second >= secondsToWait) System.out.println("timeoutfa27");
try { if (isElementPresent(By.xpath("(//button[text()='Login'])"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
}
【问题讨论】:
标签: javascript extjs selenium selenium-ide selenium-chromedriver