繁体   English   中英

Cucumber / JUnit - 在循环内测试失败时如何继续?

[英]Cucumber / JUnit - How to proceed when test failed inside a loop?

晚上好,

I investigated hours to find a solution for the following problem: I'm using Eclipse, Cucumber, JUnit & Maven. 如何获得单个测试步骤将被标记为失败。 我有可能使用 try-catch 和 Assert.fail() 使整个场景失败,但循环内没有一个案例。

附上我的部分代码:

场景:然后在页面|455xxxxxx10|4xx0|上执行登录 |455xxxxxx10|4xx0| |455xxxxxx10|4xx0| |455xxxxxx10|4xx0| |455xxxxxx10|4xx0|

很可能一个数字是错误的,然后整个场景就会失败? 将这种情况标记为错误并再次执行循环会很棒。

        List<String> credentials = dataTable.asList(String.class);
        driver.get("URL");
        sessionID = driver.manage().getCookieNamed("CookieName").toString();

        for (int a=0, b=1; a<credentials.size() & b<=credentials.size(); a+=2, b+=2)
        {
            driver.findElement(By.linkText("LOGIN")).click();
            wait = new WebDriverWait(driver, 60);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[1]/header/nav/div/div/div/ul/li[2]/a/span")));```

在我看来,您应该使用场景大纲。

Scenario Outline: Then Execute Login on Page
Given: "<User>" logs into the page
|User        |
|455xxxxxxxxx|
|4xx0        |
|4xx0        |

这将为任何用户(或任何您用来登录的用户)运行每个测试场景作为单独的测试。 因此,如果其中一种情况失败。 您将能够看到是哪一个。

您应该使用场景大纲。 尝试以下操作:

Feature: Login Feature - Verify if user is able to Login into the site.

Scenario Outline: Login as a authenticated user
 Given user is on homepage
 When user navigates to Login Page
 Then I enter Username as "<username>" and Password as "<password>"

Examples:
|username  |password|
|455xxxxx10|4xx0    |
|455xxxxx10|4xx0    | 

PS:注意关键词。 你不能写

 Feature: Login Feature
Verify if user is able to Login into the site

因为“验证是否用户....”之前没有关键字

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM