Implement Continuous Test Automation pattern
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.
- Continuous Test Automation concept
- Understand what a CI server [Jenkins is one brand] is
- Know how to set environment variables
- Completed and understood how to run page-object framework codebase
- Download Jenkins
- Set environment variable JENKINS_HOME
- Start Jenkins
- Login and Configure Jenkins
- Create a CT job
- Add build step(s)
- Run the Job
- See the results
- Video explaining all the above.
1) Download jenkins
Download jenkins from jenkins-ci.org.
Save it to file system [I saved to c:\jenkinswar]
2) Set JENKINS_HOME
Set JENKINS_HOME environment variable. I am using Windows 7 os.
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”
4) Login and Configure Jenkins
Hit “http://localhost:8080” in browser. The following page should show up
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
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
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”
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”
6) Add a build step(s)
- Type a project name
- Type description
- Now go ahead and add a build step for “Execute shell“
Add the below content to the build step
cd C:/GitProjects/"some folder"/page-object_framework
bundle exec cucumber features/ConfirmOrder.feature
- 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]
“Save” at the bottom of the page.
7) Run the job
Click “Run Build” in the left menu bar.
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]
The build should succeed and you should see all the cucumber scenario steps pass as below.
- 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
- 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.
- 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]
- 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.
- 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
- 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.
- 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.