在jenkins构建下以无头模式运行cucumber-jvm selenium测试用例时出错 [英] Error in running cucumber-jvm selenium test cases in headless mode under jenkins build

查看:203
本文介绍了在jenkins构建下以无头模式运行cucumber-jvm selenium测试用例时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在spring-boot和maven中设计的项目。它包含了yellow-jvm selenium测试用例,我希望在jenkins构建中以无头模式运行。为此,我在jenkins构建机器上安装了 XVfb ,并确保 Xvfb 正在运行。

I have a project desgined in spring-boot and maven. It contains cucumber-jvm selenium test cases which I want to run in headless mode in jenkins build. To do so, I have installed XVfb on jenkins build machine and also have made sure that Xvfb is running.

$ps -ef | grep Xvfb
root      3804     1  0 Sep29 ?        00:52:41 Xvfb -ac :99 -screen 0 1280x1024x16

接下来,我还要导出DISPLAY在构建开始时的变量如下,

Next, I am also exporting DISPLAY variable at the start of the build as follows,

export DISPLAY=:99



错误



测试无法执行,给出以下stackstrace

Error

The test fails to execute giving following stackstrace

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: no display specified
Error: no display specified

at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:99)



pom.xml



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>org.abc</groupId>
<artifactId>ABC</artifactId>
<name>ABC</name>
<packaging>war</packaging>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.1.7.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<repositories>
    <repository>
        <id>openqa</id>
        <name>OpenQA Repository</name>
        <url>http://nexus.openqa.org/content/repositories/releases/</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>codehaus snapshot repository</id>
        <url>http://snapshots.repository.codehaus.org/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>

    <!-- <pluginRepository> <id></id> </pluginRepository> -->
</pluginRepositories>

<dependencies>
    <!-- Spring dependencies -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!--Spring security -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Spring LDAP -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap-core</artifactId>
        <version>2.0.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>LdapSDK</groupId>
        <artifactId>LdapSDK</artifactId>
        <version>1.0</version>
        <scope>provided</scope>
    </dependency>

    <!-- IDM specific jars -->
    <dependency>
        <groupId>opentoken-adapter</groupId>
        <artifactId>opentoken-adapter</artifactId>
        <version>2.5.1</version>
        <scope>provided</scope>
    </dependency>

    <!-- Test tools -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.5</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-spring</artifactId>
        <version>1.1.6</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.1.6</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.44.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>2.44.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.codeborne</groupId>
        <artifactId>phantomjsdriver</artifactId>
        <version>1.2.1</version>
    </dependency>

    <!-- LogBack dependencies -->
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
    </dependency>

    <!-- JAVA mail dependency -->
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>

    <!-- Amazon AWS SDK -->
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.8.11</version>
    </dependency>

    <!--Templating engine -->
    <dependency>
        <groupId>org.apache.velocity</groupId>
        <artifactId>velocity</artifactId>
        <scope>provided</scope>
    </dependency>


    <!--Others -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
        <exclusions>
            <exclusion>
                <groupId>commons-collections</groupId>
                <artifactId>commons-collections</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
        <scope>provided</scope>
    </dependency>


    <dependency>
        <groupId>com.belerweb</groupId>
        <artifactId>qq-connect</artifactId>
        <version>1.0.2</version>
    </dependency>

    <dependency>
        <groupId>org.subethamail</groupId>
        <artifactId>subethasmtp</artifactId>
        <version>3.1.7</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.ant</groupId>
        <artifactId>ant</artifactId>
        <version>1.9.3</version>
    </dependency>

    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.6</version>
    </dependency>
    <dependency>
        <groupId>com.jayway.jsonpath</groupId>
        <artifactId>json-path</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.jayway.jsonpath</groupId>
        <artifactId>json-path-assert</artifactId>
        <version>1.2.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>net.sf.json-lib</groupId>
        <artifactId>json-lib</artifactId>
        <version>2.4</version>
        <classifier>jdk15</classifier>
        <scope>test</scope>
    </dependency>


</dependencies>

<properties>
    <integrationSourceDirectory>src/test/ui</integrationSourceDirectory>
    <integrationOutputDirectory>target/integrationtest-classes</integrationOutputDirectory>

    <jetty.port>8000</jetty.port>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <start-class>org.healthfidelity.hfiam.Application</start-class>
    <java.version>1.6</java.version>
</properties>

<build>
    <plugins>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>add-test-source</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/test/ui</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18</version><!--$NO-MVN-MAN-VER$ -->
            <configuration>
                <excludes>
                    <exclude>**/IT*.java</exclude>
                </excludes>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.18</version><!--$NO-MVN-MAN-VER$ -->
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.1.16.v20140903</version>
            <configuration>
                <war>${basedir}/target/HFIam.war</war>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <stopKey>foo</stopKey>
                <stopPort>1234</stopPort>
                <useProvidedScope>true</useProvidedScope>
                <daemon>true</daemon>
                <webApp>
                    <contextPath>/HFIam</contextPath>
                </webApp>
                <connectors>
                    <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                        <maxIdleTime>3600000</maxIdleTime>
                        <port>${jetty.port}</port>
                    </connector>
                </connectors>

            </configuration>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run-war</goal>
                    </goals>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>selenium-maven-plugin</artifactId>
        </plugin>

    </plugins>
</build>

推荐答案

作为决议,


  1. 我在jenkins上安装了 xvfb 插件。

  2. 并在构建环境部分勾选选项在构建之前启动Xvfb,并在之后将其关闭。

  1. I installed xvfb pluggin on jenkins.
  2. And in Build Environment section ticked options Start Xvfb before the build, and shut it down after.

这篇关于在jenkins构建下以无头模式运行cucumber-jvm selenium测试用例时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆