Implement Continuous Test Automation pattern

Context:

In our previous discussion on Continuous Test Automation concepts, we learnt some jargon around Continuous Delivery and how Continuous Test Automation fits in the big picture. Obviously there is technology piece, process piece and Agile (collaboration between people) piece. All of them have to work hand in hand. We (as you know) are talking more about technology piece on this website.

In this section, we will implement “one” of the Continuous Test Automation patterns. If we follow this pattern as a practice every time we have a source code change and/or Test Automation code change, then we will be reaping huge benefits that can be derived out of Continuous Delivery model.

Pre-Requisites

Agenda:

  1. Download Jenkins
  2. Set environment variable JENKINS_HOME
  3. Start Jenkins
  4. Login and Configure Jenkins
  5. Create a CT job
  6. Add build step(s)
  7. Run the Job
  8. See the results
  9. Video explaining all the above.

1) Download jenkins

Download jenkins from jenkins-ci.org.

DownloadJenkinsWar

 

Save it to file system [I saved to c:\jenkinswar]

save_tocdrive

 

2) Set JENKINS_HOME

Set JENKINS_HOME environment variable. I am using Windows 7 os.

add_jenkins_env

3) Start jenkins

Navigate to your command line and start jenkins by issuing “java -jar jenkins.war”

  • The server reads JENKINS_HOME environment variable at bootup
  • It found c:\jenkinswar in my case because I wanted it to be in that folder
  • By default it starts on port 8080
  • Patience until it starts and says “fully up and running”

start_jenkins

 

4) Login and Configure Jenkins

Hit “http://localhost:8080” in browser. The following page should show up

first_jenkins_page

Go ahead and click “Manage Jenkins” on the left side bar. Then follow the steps as in the below screenshot. Save at the bottom of the page

configure_global_security

Once you save, you are back to main page. On the main page, click “sign up” at the top right corner and fill in your details and click “Sign up button”. I filled mine as below

sign_up_pradeep

You should be automatically logged into Jenkins after this step with Success, you can check because at the top right corner, you would now find “sign out”

pradeep_success_sign_in

5) Create a CT job

Now lets go ahead and create our first Continuous Test Automation job. Click “New Item” in the left bar as follows and fill the details and click “Save

new_jenkins_job

6) Add a build step(s)

  • Type a project name
  • Type description
  • Now go ahead and add a build step for “Execute shell

\

acceptance_tests_configure

Add the below content to the build step

  • pwd – present working directory [To check where I am first]
  • cd – change directory [change to the directory where your acceptance tests are. In my case I had them in the directory shown above]
  • pwd again – To check that jenkins indeed changed the directory
  • Finally execute the acceptance tests [The project I am executing is the same project code base which we used for page-object framework. You can download it from here]

acceptance_tests_buildstep

Save” at the bottom of the page.

acceptance_tests_buildstep_save

7)  Run the job

Click “Run Build” in the left menu bar.

acceptance_tests_buildstep_saved

7)See the Results

You should see the page-object_framework code executing for the CT job. Click the progress bar and it will open the console window. Of course you should see browser popping up on your machine [Assuming the fact that you have done all the setup necessary as described in page-object framework section]

acceptance_tests_executing

The build should succeed and you should see all the cucumber scenario steps pass as below.

acceptance_tests_success

8) FAQ

  1. I am not able to start my jenkins server – Well, we assume that you have jdk installed and it is in the PATH and that no other server is running on port 8080
  2. On a windows machine, I get the error “sh not found” in the  “Execute shell” build step — This is most likely because Jenkins shell looks for a *nix environment, hence it is not able to find windows cmd.exe.
    1. Install git client on windows and in <git installation directory>\bin\sh.exe should be present. Now when jenkins executes “Execute shell”, it will invoke sh.exe [You can check this by typing sh.exe in cmd, add it to PATH if not present]
    2. If solution one above worked, you DO NOT need to do this step. Otherwise, you can go to Manage Jenkins – Configure system – Shell and in the text box type “C:\Windows\System32\cmd.exe”. This will ensure that Jenkins can kick off cmd.exe when Shell build step executes.
  3. I can’t see the browser pop up – Were we able to run the page-object_framework codebase without CT job ? If no, please first run that and ensure that your environment is set up correctly. Then follow the steps again
  4. I want more hand-holding here. Well if you jumped across all tutorials [basic, intermediate, advanced and frameworks], then it is difficult to provide any help.
  5. On the other hand, if you have read all the content and you want to learn it “right” by having one of us help you, then write to us – We provide conduct coaching classes online.

9) Video of steps