[英]How to execute performance tests with selenium, junit and jenkins
[英]How to execute Selenium 2 tests in Jenkins
我希望能够将Selenium 2与Jenkins一起使用。
我是两个人的新手所以请原谅我的无知。
我注意到jenkins HERE的以下插件,并安装了它。
我有一个基类如下:
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; } }
我在Jenkins的Selenium插件上有以下配置:
..
一旦我尝试构建项目并在Jenkins中运行Junit selenium测试,它就会成功构建,但测试会自行失败。 (从命令行使用ant运行时工作正常 - 并将WebDriver
更改为: driver = new FirefoxDriver();
) - 使用selenium RC
这是Jenkins的控制台输出:
编辑 :我刚刚注意到你可以在Jenkins构建之后存档Junit .xml输出文件。 我得到一个没有找到的类异常? 这很奇怪,因为就像我说的那样,它在命令行中使用ant
时构建得很好。
错误如下:
<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>
提前感谢您的任何指导或帮助!
我想我犯了几个错误。 要解决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>
这让我的java类编译。
然后我不得不将selenium独立服务器更新到最新版本( selenium-server-standalone-2.xx.x.jar
)它位于:
jenkins_home_directory\\plugins\\selenium\\WEB-INF\\lib
最后我试图在selenium插件中使用错误的配置(我试图使用自定义RC节点配置,我需要的是自定义Web驱动程序节点配置。)
另请注意:在Red Hat上运行Selenium Server时,我必须使用Jenkins Xvfb插件设置和安装XVFB。
我希望这对未来的其他人有所帮助! 祝好运!
好吧,如果你的目的是简单地运行没有Selenium Grid的selenium脚本。 那你就不需要任何插件了。 你只需要远程webdriver。
要从Jenkins启动Selenium 2,最好的方法是将测试过程包装在pom.xml中(如果您使用的是Maven),然后使用Jenkins中的“Build a maven2 / 3 project”在Maven中创建一个新作业。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.