Running Tests using Jenkins
Jenkins is an open-source continuous integration/continuous delivery and deployment (CI/CD) automation software DevOps tool. It is used to implement CI/CD workflows, called pipelines. Users can use Jenkins to execute automation on the pCloudy platform to enable CI/CD.
- The user should be registered on the pCloudy platform
- Jenkins installed on the local machine
- Maven and JDK path should be configured in Jenkins
- Maven should be installed on the local machine
- Set the required capabilities in the Appium script
- Copy the project path and keep it handy
Let's see the Approaches
Steps to run jenkins using the Freestyle approach
Steps 1. Go to Dashboard and Click on New Item
Steps 2. Enter “project name”, select “Freestyle project” and click “OK”
Steps 3. Under General scroll down and Go to Build and click on the Add build step
Steps 4. Select "Execute Windows batch command" for windows or Execute Shell from the drop-down
Note: This needs to be selected depending on OS
Steps 5. Enter the maven command to run the project and save it
Note: Here user needs to give the path of the project where it is located
e.g. cd C:\Users\Admin\eclipse-workspace\Chapter4-TestNgwithpCloudyonSingleDeviceIOS2
Note: Make sure pCloudy capabilities should be set in Runner.java
Steps 6. Set app capability
- Login to your registered account.
- Go to the "Device page" and navigate to the "Capabilities" section as shown in the below screenshot. You will see "Capability Configurator"
- Select Operating System->Android or iOS
- Select Automation Type->Browser Testing or App Testing
- Note: As per Automation Type selection other fields get updated.
E.g.: If user selects OS as "Android" and Automation Type as "App Testing"
- Application Name :-This is an optional field.
- Note: We kept it option as for preinstalled app,app name not required
- App Package :-
- In very basic terms, appPackage is the technical name of the app which is provided by its developers
- App Activity :-
- AppActivity refers to the different functionalities that are provided by the app.
- For example, WhatsApp provides multiple functionalities such as conversations, profile information, setting profile photos, setting status, notifications and a lot of other things. All these functionalities are represented by different appActivity
Note: You can find AppPackage and App Activity by :-
- Using 'mCurrentFocus' or 'mFocusedApp' in Command Prompt. For this adb needs to be installed in your system.
- Using APK Info app:- APK Info is an app that you can download from Play Store, and it will provide the app package and app activity name of any app which is installed on your mobile device.
Refer: capability-configurator for more detailed information about all use cases
Steps 7. Click on "Build Now" and go to console output to check the status
Steps 8. Click on “Console Output”
Steps to run jenkins using the Pipeline approach
- Install jq package (This package helps to get the output response)
- jq is like sed for JSON data – you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text. It is written in portable C.
- Maven should be configured in Jenkins
- User should have a Github account: this is needed incase if the repository is private
Note: This sample project is for reference with respect to the ubuntu machine
Steps 1: Create a GitHub account and upload your project
- For the public repository, users don't need to configure Github in Jenkins
- For a private repository, users need to configure Github in Jenkins
Steps 2: Login into your Jenkins and click on “New Item”
Steps 3: Enter the Project name and Select pipeline style.
Steps 4: If the Project in Github is private, then the user needs to configure Github credentials in Jenkins
Steps to access Github from Jenkins:-
- once the build is created, go to the Jenkins dashboard and click on pipeline syntax to configure GitHub credentials
- In the “sample step” select the “Git” option from the dropdown.
- Enter the repository URL from GitHub.
- Enter the branch name
- Configure GitHub credentials in Jenkins
- Click on Generate pipeline script.
Note: If Git is not working from the password, generate a git token from GitHub and place it in the password field.
Note: Above process is used to clone the Git repository to the Jenkins workspace.
Steps 5: Go to the Dashboard and click on the created build and select configure
Steps 6: Write the code to run the pipeline script and click on SAVE
Code definition:- There are four stages as mentioned below:-
Jenkins stage 1:- Git clone-> For example, we have considered pCloudy-sample-project chapter-1: Which is for a single device(Android)
Here is a reference link for the same.
Note:- We have updated the capabilities in GitHub as well.
Jenkins stage 2:- In this stage, we are using the authentication API which is present in content.pcloudy.com
Here the user needs to enter the email and API key to generate the token.
Note:- The user can also use the Jq package to help extract the token value from the output
- Jenkins stage:- 3 Upload stage-> The user needs to enter the local file path in the API
- Jenkins stage:- 4 Run mvn test.
Steps 7: Run the build.