selenium-webdriver - 如何在 Allure 报告中对测试步骤进行分组

标签 selenium-webdriver allure

我正在寻找可以在诱惑报告中对测试步骤进行分组的解决方案。

目前正在发生的事情:

例如,我有一个测试用例登录,其中有 5 个步骤 i.e go to login page, enter login detail, click on submit etc.但是在诱惑报告中,我只想显示所有 5 个登录操作的 1 个步骤。是否可以?

所以基本上我想将测试用例显示为步骤而不是场景作为报告中的步骤。

我搜索了很多,但没有找到一种有诱惑力的方法。

最佳答案

你可以调用allure.step里面的函数堵塞

@pytest.mark.sanity
class TestExample:

    def test_example(self):
        with allure.step('Do Login'):
            self.go_to_login_page()
            self.insert_user_name()
            self.insert_password()

    def go_to_login_page(self):
        Report.report_step('go to login page')

    def insert_user_name(self):
        Report.report_step('insert username')

    def insert_password(self):
        Report.report_step('insert password')

或者使用页面对象
@pytest.mark.sanity
class TestExampleTest:

    def test_example(self):
        with allure.step('Do Login'):
            (LoginPage()
             .go_to_login_page()
             .insert_user_name()
             .insert_password())


class LoginPage:

    def go_to_login_page(self):
        Report.report_step('go to login page')
        return self

    def insert_user_name(self):
        Report.report_step('insert username')
        return self

    def insert_password(self):
        Report.report_step('insert password')
        return self
report_stepReport.py 中的静态函数文件
def report_step(step_title):
    with allure.step(step_title):
        pass

这些步骤将分组在 'Do Login' 内步

enter image description here

enter image description here

编辑 与 Java 相同的想法
public class Test {
    public void testMethod() {
        doLogin();
    }

    @Step("Do Login")
    public void doLogin() {
        new LoginPage()
                .goToLoginPage()
                .insertUserName("NAME")
                .insertPassword("PASSWORD");
    }
}

public class LoginPage {

    @Step("Go to login page")
    public LoginPage goToLoginPage() {
       step("goToLoginPage");
       return this;
    }

    @Step("Insert user name {userName}")
    public LoginPage insertUserName(String userName) {
       return this;
    }

    @Step("Insert password {password}")
    public LoginPage insertPassword(String password) {
        return this;
    }
}

关于selenium-webdriver - 如何在 Allure 报告中对测试步骤进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54685694/

相关文章:

java - Allure:如果子步骤失败,如何使父步骤失败?

java - 如何创建 isSecure 标志为 false 的 org.openqa.selenium.Cookie

ruby - 尝试使用 Selenium Webdriver v3.70 最大化浏览器窗口时出现 Ruby "KeyError: key not found: 102"错误

java - 使用 selenium webDriver 从 webapp 上传文件

selenium-webdriver - Protractor :在不知道文件名的情况下测试下载文件

java - 如何从 junit 扩展返回值给@Test?

Python、Selenium、下载所有 MIME 类型

python - 如何使用Python py.test在Allure 2中实现缺陷分类?

node.js - 引诱报告以查看历史趋势

python - 来自 python 的 allure 命令行