使用Maven运行Selenium测试

时间:2016-12-16 18:49:14

标签: java maven selenium

我有一个Maven Web项目,我必须在其中运行一些Selenium UI测试(使用JUnit)。但是,当我构建项目(目标:“clean install”)时,Selenium测试不起作用,因为Tomcat服务器尚未启动。

我添加了一个我在网上找到的插件片段(tomcat7-maven-plugin),但它似乎没有做任何事情。

重要的是要知道我的Selenium测试使用的Firefox驱动程序与我的默认Firefox安装使用不同的二进制文件(旧的Firefox版本可以与旧版本的Selenium一起使用)。

这是我的POM.XML文件:

<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>org.web3</groupId>
    <artifactId>WebShopWeb3</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <id>tomcat-run</id>
                        <goals>
                            <goal>run-war-only</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <port>8080</port>
                            <fork>true</fork>
                        </configuration>
                    </execution>
                    <execution>
                        <id>tomcat-shutdown</id>
                        <goals>
                            <goal>shutdown</goal>
                        </goals>
                        <phase>post-integration-test</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <finalName>WebShopWeb3</finalName>
    </build>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4.1211.jre7</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>2.53.0</version>
        </dependency>
    </dependencies>
</project>

我的项目(测试突出显示):

enter image description here

有人知道我需要添加到POM.XML中的行还是我需要做的其他事情?

由于

1 个答案:

答案 0 :(得分:0)

我有一个简单的应用程序与硒。这是pom.xml。

{{1}}

相关问题