selenium - xvfb 和 thucydides/Selenium 运行 Firefox 的默认路径

标签 selenium jenkins centos xvfb thucydides

CI Jenkins 在非 root 用户下运行在 CentOS headless 机器上。

Xvfb packege 已安装,当我尝试来自 How can I specify a display? 的提示时,即在控制台手动设置

export DISPLAY=127.0.0.1:0
Xvfb :0
firefox &

它有效 - Xvfb 输出显示一些 firefox 请求,Firefox 输出到控制台。

当我从 maven 运行同样的东西时,没有任何反应。请查看我的 pom.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>somegrouppegas</groupId>
    <artifactId>pegas</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>pegas</name>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <thucydides.version>0.9.273</thucydides.version>
        <thucydides.jbehave.version>0.9.273</thucydides.jbehave.version>
        <webdriver.driver>firefox</webdriver.driver>
        <actualVersion>0.9.7.1-BETA</actualVersion>
    </properties>

    <dependencies>
        <dependency>
            <groupId>net.thucydides</groupId>
            <artifactId>thucydides-core</artifactId>
            <version>${thucydides.version}</version>
        </dependency>
        <dependency>
            <groupId>net.thucydides</groupId>
            <artifactId>thucydides-junit</artifactId>
            <version>${thucydides.version}</version>
        </dependency>
        <dependency>
            <groupId>net.thucydides</groupId>
            <artifactId>thucydides-jbehave-plugin</artifactId>
            <version>${thucydides.jbehave.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.easytesting</groupId>
            <artifactId>fest-assert</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.googlecode.lambdaj</groupId>
            <artifactId>lambdaj</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ftpserver</groupId>
            <artifactId>ftpserver-core</artifactId>
            <version>1.0.6</version>
        </dependency>
        <dependency>
            <groupId>com.javadocmd</groupId>
            <artifactId>simplelatlng</artifactId>
            <version>RELEASE</version>
        </dependency>
        <!--<dependency>
            <groupId>com.github.arachnidium</groupId>
            <artifactId>arachnidium-app-model</artifactId>
            <version>${actualVersion}</version>
        </dependency>  -->
    </dependencies>
    <build>
        <plugins>
            <!--
            XMInd plugin is not needed right now; it will be added after it will be improved
            <plugin>
                <groupId>mavenplugintest</groupId>
                <artifactId>mavenplugintest</artifactId>
                <version>1.0-SNAPSHOT</version>
                <configuration>
                    <xmindpath>parse.xmind</xmindpath>
                </configuration>
                <executions>
                    <execution>
                        <id>generateStoriesFromXMind</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>generateStoriesFromXMind</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>generateXMindFromTestResults</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>generateXMindFromTestResults</goal>
                        </goals>
                    </execution>

                </executions>
            </plugin> -->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <forkCount>0</forkCount>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <forkCount>0</forkCount>

                    <includes>
                        <include>**/*Test.java</include>
                        <include>**/Test*.java</include>
                        <include>**/When*.java</include>
                        <include>**/*TestSuite.java</include>
                    </includes>
                </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>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <!--<compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments> -->
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9</version>
            </plugin>
            <plugin>
                <groupId>net.thucydides.maven.plugins</groupId>
                <artifactId>maven-thucydides-plugin</artifactId>
                <version>${thucydides.version}</version>
                <executions>
                    <execution>
                        <id>thucydides-reports</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>maven2</id>
            <activation>
                <file>
                    <missing>${basedir}</missing>
                </file>
            </activation>
            <reporting>
                <plugins>
                    <plugin>
                        <groupId>net.thucydides.maven.plugins</groupId>
                        <artifactId>maven-thucydides-plugin</artifactId>
                        <version>${thucydides.version}</version>
                    </plugin>
                </plugins>
            </reporting>
        </profile>
        <profile>
            <id>jenkins</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>selenium-maven-plugin</artifactId>
                        <version>2.3</version>
                        <executions>
                            <execution>
                                <id>xvfb</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>xvfb</goal>
                                </goals>
                                <configuration>
                                    <display>:0</display>
                                </configuration>
                            </execution>
                            <execution>
                                <id>start</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start-server</goal>
                                </goals>
                                <configuration>
                                    <background>true</background>
                                    <logOutput>true</logOutput>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop-server</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>maven3</id>
            <activation>
                <file>
                    <exists>${basedir}</exists>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-site-plugin</artifactId>
                        <version>3.2</version>
                        <configuration>
                            <reportPlugins>
                                <plugin>
                                    <groupId>net.thucydides.maven.plugins</groupId>
                                    <artifactId>maven-thucydides-plugin</artifactId>
                                    <version>${thucydides.version}</version>
                                </plugin>
                            </reportPlugins>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

firefox 和 Xvfb 实用程序为 jenkins linux 用户和 chmoded 777 chowned,所以权限不是问题的根源。

export DISPLAY=127.0.0.1:0

设置为预构建操作。 xvfb应该由maven selenium插件启动,根据mavn输出和自己的Xvfb日志启动。

我想知道 Thucydides/Selenium 如何定义如何找到要运行的 Firefox 二进制文件?可能他们应该以某种方式在 jenkins 配置文件中明确配置?

最佳答案

实际上,我无法以我喜欢的方式解决问题,因为尽管有 DISPLAY 变量的任何组合,将文件和二进制文件归于 jenkins 用户并返回到 root,但无法从 maven 插件运行 Xvfb配置。但是,Xvfb Jenkins 插件运行良好!如果对我来说更完美,因为我不再需要不同的 mvn 配置文件在本地机器和 CI 上运行(插件的 Xvfb 运行存储为 jenkins 配置文件),

关于selenium - xvfb 和 thucydides/Selenium 运行 Firefox 的默认路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26679921/

相关文章:

java - 如何在 Jenkins 中使用二进制文件执行 HTTP POST?

linux - 在 CentOS 7 Linux 中编辑 tomcat-users.xml

java - 单击具有数组或列表中的值的按钮

java - Selenium 中的 dispose() 错误

java - maven 编译错误 - 无法执行目标 org.apache.maven.plugins :maven-compiler-plugin:3. 5.1:compile

java - 从 Web 表中获取行数 - Selenium WebDriver Java

svn - Subversion 单选按钮在 Hudson 中不可用

jenkins - Gradle插件无法在Jenkins上正确执行命令

python - 你如何用>1024个文件描述符编译python?

linux - NGINX dns 不适用于 VPS