首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在同一类- selenium web驱动程序中跳过测试?

如何在同一类- selenium web驱动程序中跳过测试?
EN

Stack Overflow用户
提问于 2014-02-06 06:57:23
回答 2查看 1.7K关注 0票数 0

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

  • 如果我运行的是测试名Test.java。在这一点上,我有许多过滤器与下拉值的组合,以及日期选择器和多个选择框显示在图像中。

基于过滤器部分,我编写了如下代码:

代码语言:javascript
复制
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驱动程序。

EN

回答 2

Stack Overflow用户

发布于 2014-02-06 13:52:27

在我的例子中,我想跳过特定的筛选部分,我需要移到筛选部分的其他组合块引号。

您可以使用“验证”助手方法。

Wiki:ide.jsp#assertion-or-verification

例如,

代码语言:javascript
复制
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

票数 0
EN

Stack Overflow用户

发布于 2015-03-14 17:38:34

您的目标还不清楚--应该只使用一个成功的组合,还是要运行所有成功组合的测试?我可能建议使用数据提供程序。它为您的测试提供输入数据。在您的例子中,它可以是要使用的筛选器列表。此列表将在依赖的@Test或@BeforeTest中进行管理。所有失败的组合都将被标记为失败,并像往常一样跳过测试。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21596106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档