简体   繁体   English

如何在Jenkins中执行Selenium 2测试

[英]How to execute Selenium 2 tests in Jenkins

  • I would like to be able to use Selenium 2 with Jenkins. 我希望能够将Selenium 2与Jenkins一起使用。

  • I am new to both so please excuse any of my ignorance. 我是两个人的新手所以请原谅我的无知。

  • I noticed the following plugin for jenkins HERE , and installed it. 我注意到jenkins HERE的以下插件,并安装了它。

  • I have a base class as follows: 我有一个基类如下:

     public class BaseTestClass { protected Properties myprops; protected String baseurl; protected WebDriver driver; protected boolean acceptNextAlert = true; protected StringBuffer verificationErrors = new StringBuffer(); public BaseTestClass() { try { myprops = TestUtil.readProps("src/MyProps.properties"); baseurl = myprops.getProperty("baseurl"); driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.fireFox()); } catch(Exception e) { e.printStackTrace(); } } @Before public void setUp() throws Exception { driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); } @After public void tearDown() throws Exception { driver.quit(); String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } } protected boolean isElementPresent(By by) { try { driver.findElement(by); return true; } catch (NoSuchElementException e) { return false; } } protected String closeAlertAndGetItsText() { try { Alert alert = driver.switchTo().alert(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alert.getText(); } finally { acceptNextAlert = true; } } 

I have the following configuration on the Selenium Plugin for Jenkins : 我在JenkinsSelenium插件上有以下配置:

在此输入图像描述

.. ..

在此输入图像描述

Once I try to build the project and run a Junit selenium test in Jenkins, it builds successfully, but the test it self fails. 一旦我尝试构建项目并在Jenkins中运行Junit selenium测试,它就会成功构建,但测试会自行失败。 (works fine when running with ant from the command line - and changing the WebDriver to : driver = new FirefoxDriver(); ) - Using selenium RC (从命令行使用ant运行时工作正常 - 并将WebDriver更改为: driver = new FirefoxDriver(); ) - 使用selenium RC

This is the console output in Jenkins: 这是Jenkins的控制台输出: 在此输入图像描述

EDIT : I just noticed you can Archive the Junit .xml output file after the build in Jenkins. 编辑 :我刚刚注意到你可以在Jenkins构建之后存档Junit .xml输出文件。 I am getting a class not found exception? 我得到一个没有找到的类异常? This is weird because like i said, it builds just fine when using ant from the command line. 这很奇怪,因为就像我说的那样,它在命令行中使用ant时构建得很好。

The error is as follows: 错误如下:

<error message="com.loggedin.CCBreadCrumb" type="java.lang.ClassNotFoundException">
java.lang.ClassNotFoundException: com.loggedin.CCBreadCrumb at
java.net.URLClassLoader$1.run(URLClassLoader.java:366) at 
java.net.URLClassLoader$1.run(URLClassLoader.java:355) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:354) at
java.lang.ClassLoader.loadClass(ClassLoader.java:423) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at
java.lang.ClassLoader.loadClass(ClassLoader.java:356) at java.lang.Class.forName0(Native
Method) at java.lang.Class.forName(Class.java:186)
</error>

Thanks in advance for any direction or help you may have! 提前感谢您的任何指导或帮助!

I think i was making several mistakes. 我想我犯了几个错误。 To resolve the Class Not Found Exception I added the following to ant's build.xml - (remember I am new Ant) 要解决Class Not Found Exception我在ant的build.xml添加了以下内容 - (记住我是新的Ant)

<target name="compile" depends="init" description="compile the source " >       
    <javac srcdir="src/" destdir="bin" classpathref="SeleniumCC.classpath"/>
</target>       

This got my java classes compiling. 这让我的java类编译。

Then I had to update the selenium standalone server to the latest version ( selenium-server-standalone-2.xx.x.jar ) This is located in: 然后我不得不将selenium独立服务器更新到最新版本( selenium-server-standalone-2.xx.x.jar )它位于:

jenkins_home_directory\\plugins\\selenium\\WEB-INF\\lib

Last I was trying to use the wrong configuration in the selenium plug-in (I was trying to use a Custom RC node configuration, what I needed was a Custom web driver node configuration.) 最后我试图在selenium插件中使用错误的配置(我试图使用自定义RC节点配置,我需要的是自定义Web驱动程序节点配置。)

在此输入图像描述

ALSO NOTE : When running Selenium Server on Red Hat I had to setup and install XVFB with Jenkins Xvfb plugin. 另请注意:在Red Hat上运行Selenium Server时,我必须使用Jenkins Xvfb插件设置和安装XVFB。

I hope this can be of help to others in the future! 我希望这对未来的其他人有所帮助! Good luck! 祝好运!

Well if your intention is to simply run the selenium script without Selenium Grid. 好吧,如果你的目的是简单地运行没有Selenium Grid的selenium脚本。 Then you do not need any plugin. 那你就不需要任何插件了。 You would only need remote webdriver. 你只需要远程webdriver。

To launch Selenium 2 from Jenkins the best way would be is to wrap the test process in the pom.xml (if you are using Maven) and then simply create a new job in Maven using "Build a maven2/3 project" in Jenkins. 要从Jenkins启动Selenium 2,最好的方法是将测试过程包装在pom.xml中(如果您使用的是Maven),然后使用Jenkins中的“Build a maven2 / 3 project”在Maven中创建一个新作业。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM