目前正在开发Selenium and驱动程序,并使用Java。在Firefox26.0中运行的测试。在Eclipse am中使用TestNG帧工作。

基于过滤器部分,我编写了如下代码:
Log.info("Clicking on Visualization dropdown");
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById('visualizationId').style.display='block';");
Select select = new Select(driver.findElement(By.id("visualizationId")));
select.selectByVisibleText("Week");
Thread.sleep(6000);
Log.info("Clicking on Period dropdown");
JavascriptExecutor executor1 = (JavascriptExecutor)driver;
executor1.executeScript("document.getElementById('periodId').style.display='block';");
Select select1 = new Select(driver.findElement(By.id("periodId")));
select1.selectByVisibleText("Last 4 Weeks");
Thread.sleep(6000);
Log.info("Clicking on Apply Filter button");
driver.findElement(By.id("kpiFilterSubmit")).click();// This is the one combination of filter section
//Filter selection-2
Log.info("Clicking on Visualization dropdown");
JavascriptExecutor executor3 = (JavascriptExecutor)driver;
executor3.executeScript("document.getElementById('visualizationId').style.display='block';");
Select select3 = new Select(driver.findElement(By.id("visualizationId")));
select3.selectByVisibleText("ICC");
Thread.sleep(6000);
Log.info("Clicking on Type dropdown");
JavascriptExecutor executor02 = (JavascriptExecutor)driver;
executor02.executeScript("document.getElementById('classificationId').style.display='block';");
Select select02 = new Select(driver.findElement(By.id("classificationId")));
select02.selectByVisibleText("Internal PRs");
Thread.sleep(6000);
Log.info("Clicking on Priority dropdown");
JavascriptExecutor executor5 = (JavascriptExecutor)driver;
executor5.executeScript("document.getElementById('priorityId').style.display='block';");
Select select5 = new Select(driver.findElement(By.id("priorityId")));
select5.deselectAll();
select5.selectByVisibleText("Not Urgent");
Thread.sleep(6000);
Log.info("Clicking on Apply Filter button");
driver.findElement(By.id("kpiFilterSubmit")).click();
Thread.sleep(6000);// Second combination of filter section.例如,如果有一段时间我无法识别元素或其他问题,这意味着代码通常会停止并显示错误。但是在我的例子中,我想跳过特定的过滤器部分,我需要移动到过滤器部分的其他组合。请帮助我使代码以更好的标准。我在学习java和selenium web驱动程序。
发布于 2014-02-06 13:52:27
在我的例子中,我想跳过特定的筛选部分,我需要移到筛选部分的其他组合块引号。
您可以使用“验证”助手方法。
Wiki:ide.jsp#assertion-or-verification
例如,
JavascriptExecutor executor = (JavascriptExecutor)driver;
if(verifyElementPresent(By.id("visualizationId")){
executor.executeScript("document.getElementById('visualizationId').style.display='block';")
Select select = new Select(driver.findElement(By.id("visualizationId")));
select.selectByVisibleText("Week");
Thread.sleep(6000);
}
...
public boolean verifyElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}顺便说一下,使用Thread.sleep(6000);不是一个好的决定。
你可能会面临不同的问题。
所以试着使用等待。Wiki:advanced.jsp
发布于 2015-03-14 17:38:34
您的目标还不清楚--应该只使用一个成功的组合,还是要运行所有成功组合的测试?我可能建议使用数据提供程序。它为您的测试提供输入数据。在您的例子中,它可以是要使用的筛选器列表。此列表将在依赖的@Test或@BeforeTest中进行管理。所有失败的组合都将被标记为失败,并像往常一样跳过测试。
https://stackoverflow.com/questions/21596106
复制相似问题