并行运行的宁静-宁静第4/4部分

I'm back with the last part of Serenity, you can definitely check the previous parts in here:
Serenity part 1
Serenity part 2
Serenity part 3

在此博客文章中,我们将完成设置步骤,以了解如何使用带有Cucumber-jvm-parallel-plugin的Maven故障安全插件对黄瓜运行宁静并行测试。

You can definitely check the serenity book for details.

您将需要做的就是:

1.POM文件:

定义了用于为每个测试类运行并行测试的maven故障安全插件。

<plugin>
         <artifactId>maven-failsafe-plugin</artifactId>
         <version>2.18</version>
                <configuration>
                    <parallel>classes</parallel>
                    <threadCount>2</threadCount>
                </configuration>
</plugin>

<plugin>
                <groupId>com.github.temyers</groupId>
                <artifactId>cucumber-jvm-parallel-plugin</artifactId>
                <version>4.2.0</version>
                <executions>
                    <execution>
                        <id>generateRunners</id>
                        <phase>generate-test-sources</phase>
                        <goals>
                            <goal>generateRunners</goal>
                        </goals>
                        <configuration>
                            <!-- Mandatory -->
                            <!-- List of package names to scan for glue code. -->
                            <glue>
                                <package>ui.cucumber</package>
                            </glue>
                            <parallelScheme>FEATURE</parallelScheme>
                        </configuration>
                    </execution>
                </executions>
</plugin>

执行测试时,cucumber jvm并行插件将生成运行程序。 没有它,并行测试将无法工作。

2.为测试定义的功能文件: 在此测试中,我们将对Facebook登录页面和qcCoccoc登录页面进行测试。

  • feature file for facebook login
  @Login
  Scenario Outline: User login successfully with correct
    Given Navigate to facebook login page
    When Login facebook with '<phone>' and '<password>'
    Then Should navigate to facebook homepage
    Examples:
      |phone|password|
      |xxxxx|xxxxxx|
  • feature file for qcCoccoc login

  @Login
  Scenario Outline: Login successfully with email and password
    Given Navigate to quang cao coc coc login site
    When Login with '<email>' and '<password>'
    Then Should navigate to home page site
    Examples:
      |email|password|
      |xxxxx|xxxxx|

3.以黄瓜格式定义的测试:

  • For facebook login page:
@Steps
    private pages.facebook.LoginPage loginPage_facebook;

    @Given("^Navigate to facebook login page$")
    public void navigateToFacebookLoginPage() {

        loginPage_facebook.navigate();

    }


    @When("^Login facebook with '(.*)' and '(.*)'$")
    public void loginFacebookWithPhoneAndPassword(String phone, String password) {

        loginPage_facebook.login(phone,password);

    }

    @Then("^Should navigate to facebook homepage$")
    public void shouldNavigateToFacebookHomepage() {

        WebDriverWait wait = new WebDriverWait(getDriver(),2);
        wait.until(ExpectedConditions.not(ExpectedConditions.urlContains("login")));
        softAssertImpl.assertAll();

    }

第一个用户导航到Facebook登录页面,然后填写凭据详细信息后,我们将断言该网址是否仍然包含“登录名” 是否发短信。

-对于qcCoccoc登录页面,步骤大致相同:

public class LoginPage extends BaseTest {

    @Steps
    private pages.qcCocCoc.LoginPage loginPage_pageobject;


    @cucumber.api.java.en.Given("^Navigate to quang cao coc coc login site$")
    public void navigateToQuangCaoCocCocLoginSite() {

        loginPage_pageobject.open();

    }

    @When("^Login with '(.*)' and '(.*)'$")
    public void loginWithEmailAndPassword(String email, String password) {

        loginPage_pageobject.login(email,password);

    }

    @Then("^Should navigate to home page site$")
    public void shouldNavigateToHomePageSite() {
        WebDriverWait wait = new WebDriverWait(getDriver(),2);
        wait.until(ExpectedConditions.urlContains("welcome"));
        softAssertImpl.assertAll();

    }

    @Then("^Should prompt with '(.*)'$")
    public void shouldPromptWithErrormessage(String errorMessage) {

        softAssertImpl.assertThat("Verify message error",loginPage_pageobject.getMessageError().contains(errorMessage),true);
        softAssertImpl.assertAll();

    }
}

4.运行测试:

  • 只需使用mvn命令行即可运行测试

mvn clean verify -Dcucumber.options =“-tags @Login”

这将运行黄瓜测试具有标签@Login

  • 要仅运行带有宁静报告的facebook测试,请运行命令行:

mvn clean verify -Dtest = ui.cucumber.facebook.AcceptanceTest serenity:aggregate

Alt Text

You can check out the source code in github

如有任何疑问,请发表意见或发表意见!!

和平!!!

注意:如果您觉得此博客对您有所帮助,并且想表达谢意,请随时关注:

cno42wb8aik6o9ek1f89.png

这将有助于我贡献更多有价值的内容。

from: https://dev.to//cuongld2/serenity-running-in-parallel-serenity-part-4-4-4k68

发布了0 篇原创文章 · 获赞 0 · 访问量 664

猜你喜欢

转载自blog.csdn.net/cunxiedian8614/article/details/105690922
今日推荐