与Maven、Protractor和Selenium WebDriver的集成测试



我们开发了一个web应用程序,该应用程序在后端使用Java,在UI中使用Angular,并使用Maven作为构建系统。

我一直在尝试使用Protractor进行自动化集成测试,但在大量的谷歌搜索/StackOverflow之后,我仍然不知道如何实现端到端的配置。

Node.js/NPM安装(失败)

我试过使用前端maven插件来处理Node.js和NPM的安装,但由于我们在公司防火墙后面,似乎不可能直接下载任何东西。它可以从我们的Artifactory下载Node,但后来在NPM下载时失败了(我不明白为什么它会下载它,因为它是Node包的一部分)。无论如何,我放弃了这个想法,决定使用本地安装的Node。

启动Tomcat

启动/停止用于e2e测试的Tomcat实例由很好地处理

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <url>${tomcat.manager.url}</url>
                <path>/</path>
                <server>Tomcat</server>
            </configuration>
            <executions>
                <!-- Starting Tomcat -->
                <execution>
                    <id>start-tomcat</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <!-- Fork the process, otherwise the build will be blocked by the running Tomcat -->
                        <fork>true</fork>
                        <port>${tomcat.port}</port>
                        <systemProperties>
                            <!-- We want to use the 'e2e' profile for integration testing -->
                            <spring.profiles.active>e2e</spring.profiles.active>
                        </systemProperties>
                    </configuration>
                </execution>
                <!-- Stopping Tomcat -->
                <execution>
                    <id>stop-tomcat</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>shutdown</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

使用WebDriver(失败)

我设法启动了WebDriver,但问题是它阻止了任何进一步的执行:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <!-- Start webdriver -->
                <execution>
                    <id>start-webdriver</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>webdriver-manager</executable>
                        <arguments>
                            <argument>start</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>

正在运行的量角器

考虑到Node.js已经安装并且WebDriver正在运行,这应该不是问题。但由于我未能启动WebDriver以使其继续执行,这被阻止了。

如何管理(启动/停止)WebDriver有什么建议吗?

directConnect: true添加到Protractor配置文件可以解决启动/停止WebDriver的问题(如Nick所建议的)。在这种情况下,必须从POM中删除对WebDriver的任何显式控制。

参考配置文件中详细说明了可用参数。

最新更新