本页面是关于在一个持续集成的系统中使用 Selenium-RC - 通过命令行、Ant 或者 TestNG 来运行 Selenium 测试。
首先,我们收集信息。然后我们把它们合理的整理好。关键问题是有很多种方式启动测试并且收集结果, 所以你不得不配合好你所使用的工具 (ANT, TestNG, CC, ...)
如此使用 Selenium-RC 就需要了解很多事情:
- Selenium 服务器 (selenium-server.jar) 是实际上启动 Web 浏览器的程序。这非常重要,因为如果你想通过命令行参数传递参数给浏览器,你就要通过改变服务器的环境来做。
- 使用 Xvfb (X Windows Virtual Frame Buffer):如果你想让 Selenium 运行在 Unix 服器上 - 而不需要使用 X Windows 显示 - 或者你不想看到 Web 浏览器弹出,使用 xvfb。这是一个仅运行在内存里面的 X Server。
ANT
启动服务器用的 target :
<java jar="${selenium-server.jar}" fork="true" spawn="true" />
停止服务器用的 target (引自 Forum thread) :
<target name="stop-server">
<get taskname="selenium-shutdown" src="http:
dest="result.txt" ignoreerrors="true" />
<echo taskname="selenium-shutdown" message="DGF Errors during shutdown are expected" />
</target>
用于启动 Selenese 测试的 target (引自 Forum thread) :
<target name="runSeleniumTests">
<java jar="${acceptanceTestLibDir}/selenium-server.jar" fork="true">
<arg line="-htmlSuite "${firefox}""/>
<arg line=""${baseURL}""/>
<arg line=""${acceptanceTestListDir}/testSuite.html""/>
<arg line=""${acceptanceTestReportDir}/results.html""/>
<arg line="-timeout 30"/>
</java>
</target>
一个完整的例子 :
<?xml version="1.0" encoding="UTF-8"?>
<project name="Run Test" default="run_test" basedir=".">
<property name="test.dir" value="src\test" />
<property name="testLibDir" value="lib" />
<path id="run.cp">
<pathelement path="build"/>
<fileset dir="build/">
<include name="*.jar"/>
</fileset>
<pathelement path="lib"/>
<fileset dir="lib/">
<include name="*.jar"/>
</fileset>
</path>
<target name="run_test" description="Start Proxy ; Run TestNG ; stop Proxy">
<parallel>
<antcall target="start-server"></antcall>
<sequential>
<echo taskname="waitfor" message="Wait for proxy server launch" />
<waitfor maxwait="2" maxwaitunit="minute" checkevery="100">
<http url="http:/>
</waitfor>
<antcall target="run_testNG"></antcall>
<antcall target="stop-server"></antcall>
</sequential>
</parallel>
</target>
<target name="run_testNG" description="Run TestNG">
<testng classpathref="run.cp" haltOnfailure="false">
<xmlfileset dir="." includes="testng.xml" />
</testng>
</target>
<target name="start-server">
<java jar="lib/selenium-server.jar" fork="true">
<arg line="-timeout 30"/>
<jvmarg value="-Dhttp.proxyHost=proxy.corporate.com"/>
<jvmarg value="-Dhttp.proxyPort=3128"/>
</java>
</target>
<target name="stop-server">
<get taskname="selenium-shutdown"
src="http:
dest="result.txt" ignoreerrors="true" />
<echo taskname="selenium-shutdown" message="DGF Errors during shutdown are expected" />
</target>
<taskdef resource="testngtasks" classpath="lib/testng-5.0-jdk15.jar" />
</project>
MAVEN 2
想要在集成测试 前/后 启动/停止 Selenium RC,编辑 pom.xml 包含下面的内容: (引自 Maven 用户列表 此帖 )。
<?xml version="1.0"?>
<project>
<dependencies>
<dependency>
<groupId>org.openqa.selenium.client-drivers</groupId>
<artifactId>selenium-java-client-driver</artifactId>
<version>${selenium-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openqa.selenium.server</groupId>
<artifactId>selenium-server</artifactId>
<version>${selenium-version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>dependency-maven-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>pre-integration-test</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.openqa.selenium.server</groupId>
<artifactId>selenium-server</artifactId>
<version>${selenium-version}</version>
<type>jar</type>
<outputDirectory>${project.build.directory}</outputDirectory>
<destFileName>selenium-server.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>start-selenium</id>
<phase>pre-integration-test</phase>
<configuration>
<tasks>
<echo taskname="selenium" message="---------------------------------------------------------"/>
<echo taskname="selenium" message=" Starting Selenium Remote Control "/>
<echo taskname="selenium" message=" Please make sure that FireFox executable is on the PATH "/>
<java jar="${project.build.directory}/selenium-server.jar" fork="yes" spawn="true"/>
<echo taskname="selenium" message="---------------------------------------------------------"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>stop-selenium</id>
<phase>post-integration-test</phase>
<configuration>
<tasks>
<echo taskname="selenium" message="---------------------------------------------------------"/>
<echo taskname="selenium" message=" Shutting down Selenium Remote Control "/>
<echo taskname="selenium" message=" DGF Errors during shutdown are expected "/>
<get taskname="selenium"
src="http:
dest="result.txt" ignoreerrors="true"/>
<echo taskname="selenium" message="---------------------------------------------------------"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>openqa</id>
<url>http: </repository>
</repositories>
<properties>
<selenium-version>0.8.1</selenium-version>
</properties>
</project>
Maven2 用户: Binil Thomas
JAVA
启动服务器的另一种方法 (引自 Forum thread) :
当然,把 selenium-server.jar 加到 classpath 中去,创建一个 SeleniumServer 对象并 .start() 它。
这典型应用在 TestNG 的 SetUp() 中。
LINUX
这里有一系列的有用的 Unix 命令做这件事:
启动 Xvfb 作为 display 1:
% startx -- `which Xvfb` :1 -screen 0 1024x768x24 2>&1 >/dev/null &
启动一个 Selenium Server 并且并在此 display (display 1) 上启动 Web 浏览器:
% DISPLAY=:1 java -jar selenium-server.jar
截取 xvfb display 下的一个屏幕快照看看发生了什么 (调试模式下很有用):
% DISPLAY=:1 import -window root /tmp/xvfb_snapshot.png
注意: '%' 是 Unix shell 提示符。'DISPLAY=:1" 是一个命令行设置的环境变量。你可以很简单的设置 DISPLAY 到例如 foo.bar.com:2,代表 Selenium Web 浏览器会出现在 foo.bar.com 的第二个 X Windows display 上。
Linux 用户 : obinho.
This information is adapted from the following pages:
分享到:
相关推荐
selenium-RC.rar,包含selenium-java-client-driver.jar,selenium-server.jar等
快速启动selenium-RC-server
selenium1.0的自动化测试,selenium-remote-control-1.0.3,包含selenium-java-client-driver-1.0.1、selenium-php-client-driver-1.0.1等等
4. command prompt go to –> C:\selenium-remote-control-1.0.3\selenium-server-1.0.3>java -jar selenium-server.jar 5. Download the RubyInstaller– The Ruby Installer is currently available only for the ...
java+selenium实现web自动化测试需要用到的jar包。不过某些情况下Selenium-server-standalone包即可,Selenium-java没有使用也可以运行
selenium-server-standalone-2.40.0.jar 、selenium-java-2.40.0-srcs.jar 、selenium-java-2.40.0.jar
selenium-java-2.44.0.jar selenium-java-2.44.0-srcs.jar selenium-server-standalone-2.44.0.jar
Selenium 服务器(selenium-server-4.1.1.jar)
selenium-RC
最新版selenium-java,selenium-server-standalone-3.141.0.jar
selenium-java-2.45.0.jar
selenium web是一种自动化测试工具,有三部分组成selenium-ide;selenium-rc;selenium-grid。这里只是selenium-rc。
selenium-server-standalone-2.44.0, selenium最新服务器,
selenium-java-2.41.0,selenium-java-2.33 完整包下载
selenium-java-2.47.1.zip,2015年8月更新
selenium-server-standalone-3.141.59.jar
包含两个文件 selenium-java-2.25.0.zip和selenium-server-standalone-2.25.0.jar 调试用,好用的
selenium-java-3.141.59.zip
selenium-server-standalone-4.0.0-alpha-2.zip