maven - 将 Selen 测试与构建过程分开

标签 maven selenium build continuous-integration

我有一个问题对于你们所有人来说可能都很微不足道,我只是想确保我掌握了这个概念。 我做了很多研究和阅读 ( SO post ),但我仍然有点困惑,所以我向你们专家求助!

在下面的文章中,作者提到了一种常见的做法,即在构建时将 Selenium 测试与单元测试分开。他们说selenium测试不应该在每个构建上运行,它们应该在CI服务器上运行,而不是作为maven构建的一部分,因此他们配置maven跳过selenium测试,然后在集成阶段运行它们。

我有点明白原因,但我不太熟悉构建生命周期以及为什么必须按照作者的方式进行设置。

是否有人能提供一个简单的解释(或提供阅读 Material )来解释为什么您想要执行这些文章中提到的操作?我开始大量使用 Selenium ,并希望更好地理解这些概念。如果这是微不足道的,再次抱歉,我不是在征求辩论、争论或投票。

非常感谢!

http://www.weblogism.com/item/334/integration-tests-with-cucumber-jvm-selenium-and-maven http://www.lagerweij.com/2011/08/24/setting-up-selenium-with-maven http://blog.tfnico.com/2007/09/continous-web-testing-with-selenium_16.html http://developershood.blogspot.com/2009/10/using-selenium-and-maven-for-junit.html

最佳答案

分离并仅运行单元测试的原因是:

  1. 需要在 Selenium 测试之前运行单元测试 - 以简化故障推理。
  2. 这些类型的测试需要在 Maven 插件配置中进行不同的设置 - 并行测试运行、排序、系统属性、JVM 选项等。
  3. Selenium 测试是端到端的,需要大量的配置和部署工作、重置应用程序状态(清除数据库、启动和停止应用程序服务器) - 这些工作在所有开发和登台环境中都无法轻松完成

Maven 有一组用于分离集成测试步骤的阶段,也有一些配置文件允许在单个位置收集 selenium 测试配置。

这是我们使用 selenium 进行端到端测试的示例(解压并运行脚本以从头开始设置数据库、启动应用程序服务器、运行测试、停止应用程序服务器、验证并报告测试结果):

<profile>
    <id>selenium</id>
    <dependencies>
        <dependency>
            <groupId>com.thenewmotion</groupId>
            <artifactId>msp-solveconnector</artifactId>
            <version>${project.version}</version>
            <classifier>sql-install</classifier>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>unpack-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>unpack-dependencies</goal>
                            </goals>
                            <configuration>
                                <includeGroupIds>com.thenewmotion</includeGroupIds>
                                <includeArtifactIds>msp-solveconnector</includeArtifactIds>
                                <includeClassifiers>sql-install</includeClassifiers>
                                <includeTypes>zip</includeTypes>
                                <includes>**/*.*</includes>
                                <outputDirectory>${project.build.directory}</outputDirectory>
                                <overWriteReleases>false</overWriteReleases>
                                <overWriteSnapshots>true</overWriteSnapshots>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>sql-maven-plugin</artifactId>
                    <dependencies>
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>5.1.16</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <id>create-db</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>execute</goal>
                            </goals>
                            <configuration>
                                <driver>com.mysql.jdbc.Driver</driver>
                                <url>jdbc:mysql://localhost</url>
                                <username>${msp.db.user}</username>
                                <password>${msp.db.password}</password>
                                <orderFile>ascending</orderFile>
                                <fileset>
                                    <basedir>${project.build.directory}/db</basedir>
                                    <includes>
                                        <include>1_drop_database.sql</include>
                                        <include>2_create_database.sql</include>
                                        <include>3_create_tables.sql</include>
                                        <include>4_create_views.sql</include>
                                        <include>5_create_foreign_keys.sql</include>
                                        <include>6_data.sql</include>
                                    </includes>
                                </fileset>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <configuration>
                        <stopKey>foo</stopKey>
                        <stopPort>8088</stopPort>
                        <connectors>
                            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                                <port>${msp.port}</port>
                                <maxIdleTime>60000</maxIdleTime>
                            </connector>
                        </connectors>
                    </configuration>
                    <executions>
                        <execution>
                            <id>start-jetty</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <daemon>true</daemon>
                            </configuration>
                        </execution>
                        <execution>
                            <id>stop-jetty</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>stop</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.12</version>
                    <configuration>
                        <systemPropertyVariables>
                            <msp.user>${msp.user}</msp.user>
                            <msp.password>${msp.password}</msp.password>
                            <msp.baseUrl>${msp.baseUrl}</msp.baseUrl>
                            <webdriver.type>${webdriver.type}</webdriver.type>
                            <webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
                        </systemPropertyVariables>
                        <includes>
                            <include>**/*FT.class</include>
                        </includes>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sql-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</profile>

关于maven - 将 Selen 测试与构建过程分开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11706855/

相关文章:

python - 使用 selenium (python) 选择满足条件的所有元素

python - Selenium、Python 的问题

build - 计算makefile构建时间

tomcat - 由于 http/https 冲突,CAS 登录/重定向无法正常工作

java - 在哪里可以查看 Maven 插件的默认执行计划?

eclipse - Maven 目标,编译并部署到服务器

python - 带有 selenium 的 Browsermob 代理生成空输出

eclipse - 用ant构建eclipse项目

android - 如何在构建过程中正确生成 XML 资源文件?

java - 使用 <scope>test</scope> 发布 Artifact