如何在Selenium WebDriver,JBehave和Serenity BDD框架中并行运行Web测试?



几天来,我一直在尝试在基于Selenium WebDriver,JBehave和Serenity BDD构建的框架中并行运行Web测试。在阅读了许多文章并实现它们之后,我仍然无法并行运行 Web 测试。

如果有人能在概念上或实际上让我了解我需要进行的更改以允许在框架中并行执行,我将不胜感激。

我已经阅读并尝试实现以下文章中提到的解决方案,但无济于事:http://mdolinin.github.io/blog/2014/01/17/thucydides-plus-jbehave-plus-maven-run-tests-in-parallel/上面的文章使用ThucydidesJUnitStory类,但由于它已被弃用,我改用SerenityStory类。它仍然没有用。

结构:

Project
|-- src/test/java
|---- com.auto.test.app
|-------- AcceptanceTestSuite.java
|---- com.auto.test.app.definitions
|-------- SearchDefinitions.java
|---- com.auto.test.app.definitions.steps
|-------- SearchSteps.java
|---- src/test/resources
|-------- stories
|------------ AcceptanceTestSuite
|---------------- BasicSearch.story
|---------------- AdvancedSearch.story
|---- src/main/java
|-------- com.auto.test.app.pages
|------------ HomePage.java
|-------- com.auto.test.app.pages.objects
|------------ HomePageOR.java
|---- drivers
|-------- ChromeDriver.exe
|---- pom.xml
|---- serenity.properties

绒球.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.auto.test</groupId>
    <artifactId>Serenity_TAF</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <name>Serenity Test Automation Framework</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <serenity.version>1.1.17</serenity.version>
        <serenity.jbehave.version>1.1.0</serenity.jbehave.version>
        <webdriver.driver>chrome</webdriver.driver>
        <webdriver.chrome.driver>./drivers/chromedriver.exe</webdriver.chrome.driver>
    </properties>
    <repositories>
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>bintray</name>
            <url>http://jcenter.bintray.com</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>bintray-plugins</name>
            <url>http://jcenter.bintray.com</url>
        </pluginRepository>
    </pluginRepositories>
    <dependencies>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-core</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-junit</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-jbehave</artifactId>
            <version>${serenity.jbehave.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>1.7.0</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.lambdaj</groupId>
            <artifactId>lambdaj</artifactId>
            <version>2.3.3</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <systemPropertyVariables>
                        <webdriver.driver>${webdriver.driver}</webdriver.driver>
                    </systemPropertyVariables>
                    <includes>
                        <include>**/*Test.java</include>
                        <include>**/*TestSuite.java</include>
                        <include>**/Test*.java</include>
                        <include>**/When*.java</include>
                    </includes>
                    <!--  <forkMode>perthread</forkMode> -->
                    <parallel>classes</parallel>
                    <threadCount>2</threadCount>                    
                    <argLine>-Xmx512m</argLine>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.serenity-bdd.maven.plugins</groupId>
                <artifactId>serenity-maven-plugin</artifactId>
                <version>${serenity.version}</version>
                <executions>
                    <execution>
                        <id>serenity-reports</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

宁静属性

# Define the default driver
webdriver.driver=chrome
webdriver.chrome.driver=drivers/chromedriver.exe
webdriver.base.url=https://www.google.com/
# Appears at the top of the reports
serenity.project.name=Serenity & Java based Test Automation Framework
# Run the tests without calling WebDriver - useful to check your JBehave wiring
#serenity.dry.run=true
story.timeout.in.secs=3600
thucycides.step.delay=1000
webdriver.timeouts.implicitlywait=10000
webdriver.wait.for.timeout=60000
#serenity.timeout=10000
# Customize browser size
#serenity.browser.height = 1004
#serenity.browser.width = 1920
security.enable_java=true
serenity.take.screenshots=AFTER_EACH_STEP
serenity.reports.show.step.details=false
serenity.report.show.manual.tests=false
serenity.resized.image.width=1920
serenity.keep.unscaled.screenshots=true
serenity.maintain.session=true

Serenity 现在有这个功能

  1. 并行批处理运行宁静测试

http://thucydides.info/docs/serenity-staging/#_running_serenity_tests_in_parallel_batches

如果测试是数据驱动的,只需在类级别添加以下行:

@Concurrent    
public class sampleTest {    
  //Do stuff here    
}    

http://www.thucydides.info/docs/serenity/#_data_driven_tests

如果您希望运行批处理或并行,请查看此处:http://www.thucydides.info/docs/serenity/#_running_serenity_tests_in_parallel_batches

相关内容

  • 没有找到相关文章

最新更新