【问题标题】:How to get the status of each line of a Datatable rows that is executed如何获取执行的 Datatable 行的每一行的状态
【发布时间】:2019-08-31 17:25:22
【问题描述】:

我正在测试一个大约有 100 个用户名和密码的场景。我应该一个一个地使用每个用户名-密码对,然后尝试登录到应用程序。然后注销。在同一个浏览器中再次登录,不要关闭它。在这里,如果任何凭据无效,则只有该特定行应标记为失败,其余应继续执行

我试图搜索解决方案,但无法获得任何合适的解决方案

Scenario: To test if the given list of users credentials are valid

    Given user is already at Login page
    And user enters credentails

|   Username    |   Password    |
|   user1       |   password1   |
|   user2       |   invalid         |
|   user3       |   password3   |
|   user4       |   password4   |
|   user5       |   password5   |
|   user6       |   password6   |
|   user7       |   password7   |

此处数据表第二行的状态应在报告中标记为失败,其余数据应执行,但失败的数据除外。通过的数据应在报告中标记为PASS。如何做到这一点。

【问题讨论】:

    标签: eclipse cucumber pom.xml reporting junit-runner


    【解决方案1】:

    首先您需要按照以下大纲修改场景。

     Scenario Outline: To test if the given list of users credentials are valid
        Given user is already at Login page
        And In credentails, user enters name as <Username> and Pwd as <Password>
    
        Examples: Checking Login Scenarios
          | Username | Password  |
          | user1    | password1 |
          | user2    | invalid   |
    

    接下来让我们考虑一下你的步骤实现

    package my.package.name
    
    import cucumber.api.PendingException;
    import cucumber.api.java.en.Given;
    import cucumber.api.java.en.And;
    import cucumber.api.junit.Cucumber;
    import org.junit.runner.RunWith;
    
    @RunWith(Cucumber.class)
    public class MyStepDefinitions {
    
        @Given("^user is already at Login page$")
        public void user_is_already_at_login_page() throws Throwable {
            throw new PendingException();
        }
    
        @And("^In credentails, user enters name as (.+) and Pwd as (.+)$")
        public void in_credentails_user_enters_name_as_and_pwd_as(String username, String password) throws Throwable {
            throw new PendingException();
        }
    
    }
    

    第三步,在上述步骤实施中,您编写操作以登录网站,但操作因密码无效而失败。 现在取决于您使用的报告,您需要根据报告的 API 编写一种方法,就像我分享的范围一样。

    public static synchronized void logFail(String message) {
        try {
            testReport.get().fail("<details>" + "<summary>" + "<b>" + "<font color=" + "red>" + "</font>" + "</b >" + "</summary>" + "<br>" + "<h6>" + "<b>" + BasePage.returnLocator(message) +  "</b>"+ "</h6>" + "</br>" + message +"</details>"+" \n");
        }
        catch(Exception e) {            
        }   
    }
    

    最后,按照上述层次结构,您将能够在报告中打印通过/失败。

    【讨论】:

    • 感谢您的解决方案。你能帮我理解 BasePage.returnLocator(message)。此外,如果我使用场景大纲,对于每一行数据,都会启动一个新的 chrome 窗口。我想在同一个浏览器窗口中测试所有内容。这就是我没有使用场景大纲的原因
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多