尝试使用Jenkins运行一组用java编写的selenium测试

时间:2012-01-12 11:48:15

标签: selenium selenium-grid

阅读了几乎所有与#34;具有相似标题的问题" (发送这篇文章后我会继续阅读)并阅读

  
      
  • centripetal.ca/blog/2011/02/07/getting-started-with-selenium-and-jenkins /
  •   
  • oliverpolden.com/content/setting-automated-selenium-testing-jenkinshudson
  •   

和其他一些帖子(我注意到这两个因为我认为它们可能对某些人有用)我还没有找到我需要的答案。现在我明白了:

我在一家使用Jenkins for CI和maven的公司工作。他们为sotware运行了三种类型的测试:junit,cactus和selenium。詹金斯有一份工作来进行junit测试。现在他们决定使用Jenkins运行其他两种类型的测试(Cactus和Selenium)。这就是我的任务。仙人掌将成为我后来会问的另一个问题(现在我已经用那个问题敲了很长时间)。 Selenium测试是用java编写的,那里有一个java文件,其中包含以下所有测试:

package com.mycompany.test.dailySanity;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({
        Test1.class,
        Test2.class,
        Test3.class,
})

public class AllTests {
        /**
         * This is just a place holder.
         * Add All your TestClass one to the list above.
         * NOTE, the TestClasses should be "," separated
         */
}

我发现的所有信息都是关于htmlsuite的,但没有关于测试是否在java中的信息(不,将它们导出为HTML不是一种选择)。我试过了

  

export DISPLAY =":99" &安培;&安培; java -jar /path/to/selenium-server.jar   -browserSessionReuse -htmlSuite * firefox http://localhost   /path/to/my/testsfile/AllTests.java   /path/to/my/logfile/SeleniumLog.html

作为" 执行命令行程" in" Build "詹金斯的工作,但它只是继续尝试的东西。  控制台输出

09:29:48.508 INFO - Java: Sun Microsystems Inc. 14.2-b01
09:29:48.518 INFO - OS: Linux 2.6.18.8-xenU amd64
09:29:48.654 INFO - v2.4.0, with Core v2.4.0. Built from revision 13337
09:29:49.263 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
09:29:49.264 INFO - Version Jetty/5.1.x
09:29:49.269 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
09:29:49.271 INFO - Started HttpContext[/selenium-server,/selenium-server]
09:29:49.271 INFO - Started HttpContext[/,/]
09:29:49.337 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@7a187814
09:29:49.337 INFO - Started HttpContext[/wd,/wd]
09:29:49.343 INFO - Started SocketListener on 0.0.0.0:4444
09:29:49.343 INFO - Started org.openqa.jetty.jetty.Server@67ad77a7
10:51:00.038 INFO - Shutting down...
10:51:00.040 INFO - Stopping Acceptor ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=4444]

我认为它没有做任何其他事情(等了2个小时才通过它)因为它是一个java文件,它需要一个html文件( -htmlsuite 是一个线索)。

总结一下:我需要一种方法来运行用Java编写的Selenium测试并打包在Jenkins的java套件中。


编辑 好的,我没有到达任何地方,也没有时间。我添加了更多信息,万一有人可以帮助我(不是我不感谢Ross)。这是我的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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>my.company</groupId>
    <artifactId>selenium-test</artifactId>
    <version>0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium.client-drivers</groupId>
            <artifactId>selenium-java-client-driver</artifactId>
            <version>1.0.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>selenium-maven-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start-server</goal>
                        </goals>
                        <configuration>
                            <background>true</background>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <!-- Skip the normal tests, we'll run them in the integration-test phase -->
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                            <includes>
                                <include>/path/to/my/tests/AllTests.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

当我跑步时

mvn -f selenium_pom.xml integration-test

我得到以下输出

[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.kana.sem:selenium-test:jar:0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. @ line 44, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building selenium-test 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ selenium-test ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /path/to/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ selenium-test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ selenium-test ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /path/to/resources/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ selenium-test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ selenium-test ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ selenium-test ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO]
[INFO] --- selenium-maven-plugin:2.1:start-server (default) @ selenium-test ---
Launching Selenium Server
Waiting for Selenium Server...
[WARNING] OS appears to be Unix and no DISPLAY environment variable has been detected. Browser maybe unable to function correctly. Consider using the selenium:xvfb goal to enable headless operation.
[INFO] User extensions: /localhome/kana/p4/dev/BOT/target/selenium/user-extensions.js
08:05:07,166 INFO  [org.openqa.selenium.server.SeleniumServer] Java: IBM Corporation 2.3
08:05:07,173 INFO  [org.openqa.selenium.server.SeleniumServer] OS: Linux 2.6.18.8-xenU x86
08:05:07,184 INFO  [org.openqa.selenium.server.SeleniumServer] v2.9.0, with Core v2.9.0. Built from revision 14289
08:05:07,273 INFO  [org.openqa.selenium.server.SeleniumServer] RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
08:05:07,277 INFO  [org.openqa.jetty.http.HttpServer] Version Jetty/5.1.x
08:05:07,686 INFO  [org.openqa.jetty.util.Container] Started org.openqa.jetty.jetty.servlet.ServletHandler@51fe51fe
08:05:07,687 INFO  [org.openqa.jetty.util.Container] Started HttpContext[/wd,/wd]
08:05:07,687 INFO  [org.openqa.jetty.util.Container] Started HttpContext[/,/]
08:05:07,688 INFO  [org.openqa.jetty.util.Container] Started HttpContext[/selenium-server,/selenium-server]
08:05:07,689 INFO  [org.openqa.jetty.util.Container] Started HttpContext[/selenium-server/driver,/selenium-server/driver]
08:05:07,705 INFO  [org.openqa.jetty.http.SocketListener] Started SocketListener on 0.0.0.0:4444
08:05:07,705 INFO  [org.openqa.jetty.util.Container] Started org.openqa.jetty.jetty.Server@40e640e6
08:05:07.916 INFO - Checking Resource aliases
Selenium Server started
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default) @ selenium-test ---
[INFO] No tests to run.
[INFO] Surefire report directory: /path/to/surefire-reports/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.387s
[INFO] Finished at: Fri Jan 13 08:05:08 CST 2012
[INFO] Final Memory: 12M/30M
[INFO] ------------------------------------------------------------------------

我使用perforce,Jenkins,maven3和Red Hat Enterprise Linux Server 5.5版(Tikanga)。我确定我的pom是其中一个问题,但是从互联网样本中得到了它......


谢谢(并祝贺所有已经读完这篇文章的人!)

PS:如果你也知道如何从Selenium测试中获得一个很棒的报告。

2 个答案:

答案 0 :(得分:0)

-htmlsuite选项适用于与您尝试的完全不同的选项。不要让它分散你的注意力: - )

您的Java代码似乎已写入,以便通过JUnit执行测试。这是一种非常常见的技术。我希望你需要做的就是在测试开始之前确保Selenium RC服务器正在运行。只需java -jar /path/to/selenium-server.jar并保持运行,直到最后一次测试结束。您的测试将通过创建与它的连接来联系服务器,可能是通过调用new DefaultSelenium(...)

答案 1 :(得分:0)

Jenkins与Maven很好地集成,所以我建议你专注于使用 Maven 而不是Jenkins来运行测试。您可以使用failsafe插件来运行集成测试,例如您的selenium测试。 Jenkins将自动查找故障安全报告并显示漂亮的HTML摘要。此外,您可以在本地计算机上更轻松地测试它。

请您更新您的帖子以澄清您是否使用Selenium 1或2. RemoteWebDriver看起来像v2,但您的POM从1.0显示selenium-java-client-driver