How to execute Selenium 2 tests in Jenkins
Solution 1
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)
<target name="compile" depends="init" description="compile the source " >
<javac srcdir="src/" destdir="bin" classpathref="SeleniumCC.classpath"/>
</target>
This got my java classes compiling.
Then I had to update the selenium standalone server to the latest version (selenium-server-standalone-2.xx.x.jar
) This is located in:
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.)
ALSO NOTE : When running Selenium Server on Red Hat I had to setup and install XVFB with Jenkins Xvfb plugin.
I hope this can be of help to others in the future! Good luck!
Solution 2
Well if your intention is to simply run the selenium script without Selenium Grid. Then you do not need any plugin. You would only need remote 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.
Comments
-
Curt almost 2 years
I would like to be able to use Selenium 2 with Jenkins.
I am new to both so please excuse any of my ignorance.
I noticed the following plugin for jenkins HERE, and installed it.
-
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 :
..
Once I try to build the project and run a Junit selenium test in Jenkins, it builds successfully, but the test it self fails. (works fine when running with ant from the command line - and changing the
WebDriver
to :driver = new FirefoxDriver();
) - Using selenium RCThis is the console output in Jenkins:
EDIT: I just noticed you can Archive the Junit .xml output file after the build in Jenkins. 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.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!
-
Curt about 11 yearsI would like to use Selenium Grid, and no it is not a Maven project.
-
Amey about 11 yearsChange this line
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.internetExplorer());
todriver = new RemoteWebDriver(new URL("http://localhost:5555/wd/hub"), DesiredCapabilities.internetExplorer());
and try -
Curt about 11 yearsChanging the port to 5555 does not work, and im sorry that was an old screen shot where i had IE as a configuration, i updated that screen shot in the original question.
-
Amey about 11 yearsSo then change
driver = new RemoteWebDriver(new URL("http://localhost:5555/wd/hub"), DesiredCapabilities.internetExplorer());
todriver = new RemoteWebDriver(new URL("http://localhost:5555/wd/hub"), DesiredCapabilities.firefox());
Also if it does not work please share the error message. -
Manigandan almost 11 yearsI too had a problem while integrating Selenium 2 + Jenkins. I am able to run my selenium test in jenkins. But i am not able to launch the browser through jenkins. It runs like headless browser. May i know weather it is possible to do it? If yes please share how to do it. Please share if you have nice tutorials.
-
Curt almost 11 yearsYes I was able to do it with firefox on both a MAC OSX 10.8.3 and Windows 7. You must use a custom web driver node configuration as I stated above and it should launch the broswer if you have set up a selenium grid with firefox configured. I could not find any good tutorials on this. Good luck!