【问题标题】:Integration testing with Maven, Protractor and Selenium WebDriver使用 Maven、Protractor 和 Selenium WebDriver 进行集成测试
【发布时间】:2016-07-26 09:42:41
【问题描述】:

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

我一直在尝试使用 Protractor 设置自动化集成测试,但在谷歌搜索/StackOverflowing 加载后仍然无法弄清楚如何实现端到端配置。

Node.js/NPM 安装(失败)

我尝试使用frontend-maven-plugin 来处理 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 有什么建议吗?

【问题讨论】:

  • 对于 NPM,设置代理服务器并以管理员身份运行 CMD 并安装您想要的任何节点包,我认为公司防火墙可以防止这种情况。 WEB-DRIVER 启动:在您的配置文件中尝试使用“directConnect: true”量角器自动启动 webdriver 并停止

标签: angularjs node.js maven selenium protractor


【解决方案1】:

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

可用参数在reference configuration file中有详细说明。

【讨论】:

    猜你喜欢
    • 2017-08-08
    • 1970-01-01
    • 2014-08-20
    • 1970-01-01
    • 2012-08-03
    • 2012-03-15
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多