How to make Jenkins run Selenium WebDriver/TestNG/Java tests automatically on deploy and what has Maven to do with all this?

48,846

Solution 1

Responses, following your list:
Q1. Install Jenkins (we already have that on our server)
A1. None needed.

Q2. Install plugins for Jenkins (which ones?)
A2. As far as I remember no specific plugin is required just for this purpose. Jenkins should be able to run maven or ant job, it's out of the box.

Q3. Install xvfb so tests are run in a headless browser (how do I specify that in the Java written test?)
A3. In your Java tests you will be specifying the host where the browser should be launched (more technically, the host that runs selenium server). It's normally 'localhost', but for this case it will be different (it is generally not a good idea to run jenkins and selenium on the same box). So, in your java code you indicate that host with xvfb AND with selenium grid (that listens to port 4444 by default). It is also considered some good practice to factor this information out of the code (property files and, further, variables in the pom file, or provided by jenkins).

Q4. Install Maven on computer, jenkins and eclipse, use maven projects.
A4. Maven should be installed on jenkins host (and your local machine, the one you use to develop tests).

Q5. Which part of my project folder from the eclipse workplace should I upload on the server and where? I have a testng.xml file and some classes (which are the acutal tests)
A5. Your code is placed under version control (right?), so you point jenkins to fetch your project (then compile code, compile tests, run tests...). The answer is "at least all code that is needed to compile your tests and run them". Jenkins builds your project from source and test execution is just a phase of this process.

Q6. How do I tell Jenkins to automatically run the Selenium Webdriver tests after deploy, and which file do I point to?
A6. use 'integration-test' phase served by surefire plugin.

Q7. How to get reports - through TestNg or through some Jenkins feature?
A7. Jenkins will display (and distribute, if set up this way) the reports generated by testng.

Solution 2

Even I figure out the same problem, When I started configuring my WebDriver project into Maven project and try to Configure that on jenkins I required to go through many tutorial and post on internet. So i though to write down my own. Let me know if this helps
http://qtp-help.blogspot.in/2013/09/webdriver-with-maven.html

Share:
48,846
Kaloyan Roussev
Author by

Kaloyan Roussev

Java, Kotlin, Swift, some Ruby and some Haskell Clean Architecture, Design Patterns, SOLID principles, packaging principles Boyscout rule

Updated on April 29, 2020

Comments

  • Kaloyan Roussev
    Kaloyan Roussev about 4 years

    I've been researching this for a good few hours now, but I've only found pieces of the big picture. Everywhere they are assuming that the reader already has a part of the system set up.

    I think it will be useful to have a big picture description of the parts needed to put the whole thing together.

    They all say "use your maven selenium tests" and so on and so forth.

    EDIT: After some research I found out I need to install Maven in Jenkins and on my computer, install a maven plugin for Eclipse, and create/convert my projects as Maven projects. How do I transfer my Maven projects in Jenkins? Do I export to .jar, or do I move the whole folder on the server? How do I connect the whole thing together with xvfb?

    So here is what I know so far

    1. Install Jenkins (we already have that on our server)
    2. Install plugins for Jenkins (which ones?)
    3. Install xvfb so tests are run in a headless browser (how do I specify that in the Java written test?)
    4. Install Maven on computer, jenkins and eclipse, use maven projects.
    5. Which part of my project folder from the eclipse workplace should I upload on the server and where? I have a testng.xml file and some classes (which are the acutal tests)
    6. How do I tell Jenkins to automatically run the Selenium Webdriver tests after deploy, and which file do I point to?
    7. How to get reports - through TestNg or through some Jenkins feature?