In the fast-paced world of software development, delivering reliable quality while keeping up with tight release schedules is a challenge that many development teams face. Continuous Integration (CI) and Continuous Delivery (CD) are practices that assist teams in deploying code changes quickly and reliably. This blog focuses on integrating Appium, an open-source test automation framework for mobile applications, with Jenkins, a popular CI/CD tool. By doing this, we can automate the testing of mobile apps and streamline our release processes.
Continuous Integration is the practice of automatically testing and merging code changes to a shared repository. This ensures that new code is integrated frequently, allowing teams to identify issues early in the development process. Meanwhile, Continuous Delivery takes this a step further by ensuring that all code changes are automatically prepared for production release, enabling a seamless deployment process.
Appium is widely recognized in the mobile testing landscape. It supports native, hybrid, and mobile web applications on both Android and iOS platforms. By using Appium, you can write tests in various programming languages such as Java, Python, Ruby, etc., enabling greater flexibility in test development.
Jenkins, being an open-source automation server, allows for the continuous integration and delivery of projects through easy set-up and extensibility. Integrating Appium with Jenkins allows for the continuous testing of our mobile applications, which is fundamental in delivering a bug-free application to users.
Before jumping into the coding part, let's set up our environment for CI/CD with Jenkins and Appium.
Install Jenkins:
http://localhost:8080
).Install Required Plugins:
Manage Jenkins
> Manage Plugins
.Install Node.js and Appium:
node -v
in your command line.npm install -g appium
Prepare your Test Script:
import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.MalformedURLException; import java.net.URL; public class SampleTest { private AppiumDriver<MobileElement> driver; @Before public void setUp() throws MalformedURLException { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("deviceName", "YourDeviceName"); caps.setCapability("platformName", "Android"); caps.setCapability("app", "path/to/your/app.apk"); // change to your app driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), caps); } @Test public void testExample() { // Your test logic here } @After public void tearDown() { driver.quit(); } }
Now that we have everything set up, let’s create a Jenkins pipeline to automatically run our Appium tests whenever there's a new code push.
Create a New Pipeline Job:
Set Up the Pipeline Script:
pipeline { agent any stages { stage('Clone Repository') { steps { git 'https://github.com/your-repo-url.git' // replace with your repo } } stage('Run Tests') { steps { sh 'mvn clean test' // Assuming you are using Maven for Java projects } } } post { always { junit 'target/surefire-reports/*.xml' // path to your test result files } } }
Once you've set up your pipeline configuration in Jenkins, every time you push changes to the specified Git repository, Jenkins will clone the latest version, and run your Appium tests automatically. You can monitor the status of your builds in Jenkins, collect results, and even set up notifications for test failures.
By following these steps, your mobile app can achieve reliable testing and seamless integration into your CI/CD pipeline, harnessing the full power of automation with Appium and Jenkins. As you refine your pipeline, you can incorporate more advanced features like parallel testing, environment-specific variables, and integration with other monitoring tools, enhancing your development workflow even further.
By automating your testing process, you not only save time but also significantly reduce the chances of human error, ensuring that your applications are consistently of high quality.
30/09/2024 | Mobile Testing
18/09/2024 | Mobile Testing
30/09/2024 | Mobile Testing
21/09/2024 | Mobile Testing
21/09/2024 | Mobile Testing
30/09/2024 | Mobile Testing
21/09/2024 | Mobile Testing
30/09/2024 | Mobile Testing
21/09/2024 | Mobile Testing