{"id":314,"date":"2024-06-03T09:59:56","date_gmt":"2024-06-03T09:59:56","guid":{"rendered":"https:\/\/robotqa.com\/blog\/?p=314"},"modified":"2024-06-03T09:59:56","modified_gmt":"2024-06-03T09:59:56","slug":"running-appium-paralelly-by-using-xml","status":"publish","type":"post","link":"https:\/\/robotqa.com\/blog\/running-appium-paralelly-by-using-xml\/","title":{"rendered":"Running Appium Paralelly by Using XML"},"content":{"rendered":"<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.robotqa.com\/wp-content\/uploads\/2024\/06\/2024060313011927.png\" alt=\"xml-parallel-testing\" width=\"710\" height=\"501\" class=\"aligncenter size-full wp-image-339\" srcset=\"https:\/\/blog.robotqa.com\/wp-content\/uploads\/2024\/06\/2024060313011927.png 710w, https:\/\/blog.robotqa.com\/wp-content\/uploads\/2024\/06\/2024060313011927-300x212.png 300w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/>\n\nRunning Appium tests in parallel can significantly speed up the testing process, especially when you have a large suite of tests. To achieve this, you can use a test framework like TestNG in combination with an XML configuration file to define and manage parallel execution.\n\nHere&#8217;s a step-by-step guide to running Appium tests in parallel using TestNG and an XML configuration file:\n<p><\/p>\n<h3><strong>1. Setting Up Your Project<\/strong><\/h3>\nEnsure you have the necessary dependencies in your <code>pom.xml<\/code> (if you&#8217;re using Maven):\n<pre class=\"lang:xhtml decode:true \">&lt;dependencies&gt;\n&lt;!-- Appium dependencies --&gt;\n&lt;dependency&gt;\n&lt;groupId&gt;io.appium&lt;\/groupId&gt;\n&lt;artifactId&gt;java-client&lt;\/artifactId&gt;\n&lt;version&gt;8.2.0&lt;\/version&gt;\n&lt;\/dependency&gt;\n\n&lt;!-- TestNG dependencies --&gt;\n&lt;dependency&gt;\n&lt;groupId&gt;org.testng&lt;\/groupId&gt;\n&lt;artifactId&gt;testng&lt;\/artifactId&gt;\n&lt;version&gt;7.7.0&lt;\/version&gt;\n&lt;scope&gt;test&lt;\/scope&gt;\n&lt;\/dependency&gt;\n&lt;\/dependencies&gt;<\/pre>\n<p><\/p>\n<h3><strong>2. Writing Your Test Class<\/strong><\/h3>\nCreate a test class that defines your Appium tests. Each test method can represent a different test case. Here\u2019s a simple example:\n<pre class=\"lang:java decode:true \">import io.appium.java_client.AppiumDriver;\nimport io.appium.java_client.MobileElement;\nimport io.appium.java_client.android.AndroidDriver;\nimport org.openqa.selenium.remote.DesiredCapabilities;\nimport org.testng.annotations.AfterClass;\nimport org.testng.annotations.BeforeClass;\nimport org.testng.annotations.Test;\n\nimport java.net.MalformedURLException;\nimport java.net.URL;\n\npublic class AppiumParallelTest {\nprivate AppiumDriver&lt;MobileElement&gt; driver;\n\n@BeforeClass\npublic void setUp() throws MalformedURLException {\nDesiredCapabilities capabilities = new DesiredCapabilities();\ncapabilities.setCapability(\"platformName\", \"Android\");\ncapabilities.setCapability(\"deviceName\", \"Android Emulator\");\ncapabilities.setCapability(\"app\", \"\/path\/to\/your\/app.apk\");\n\ndriver = new AndroidDriver&lt;&gt;(new URL(\"http:\/\/127.0.0.1:4723\/wd\/hub\"), capabilities);\n}\n\n@Test\npublic void testOne() {\n\/\/ Your test logic here\n}\n\n@Test\npublic void testTwo() {\n\/\/ Your test logic here\n}\n\n@AfterClass\npublic void tearDown() {\nif (driver != null) {\ndriver.quit();\n}\n}\n}<\/pre>\n<h3><\/h3>\n<p><\/p>\n<h3><strong>3. Configuring TestNG XML for Parallel Execution<\/strong><\/h3>\nCreate a <code>testng.xml<\/code> file to configure TestNG to run tests in parallel. This file allows you to define how many threads to use and specify the test classes.\n<pre class=\"lang:xhtml decode:true \">&lt;!DOCTYPE suite SYSTEM \"https:\/\/testng.org\/testng-1.0.dtd\"&gt;\n&lt;suite name=\"Suite\" parallel=\"tests\" thread-count=\"2\"&gt;\n&lt;test name=\"Test1\"&gt;\n&lt;classes&gt;\n&lt;class name=\"your.package.AppiumParallelTest\"\/&gt;\n&lt;\/classes&gt;\n&lt;\/test&gt;\n&lt;test name=\"Test2\"&gt;\n&lt;classes&gt;\n&lt;class name=\"your.package.AppiumParallelTest\"\/&gt;\n&lt;\/classes&gt;\n&lt;\/test&gt;\n&lt;\/suite&gt;<\/pre>\n&nbsp;\n\nIn this example:\n<ul>\n \t<li><code>parallel=\"tests\"<\/code> specifies that tests should run in parallel.<\/li>\n \t<li><code>thread-count=\"2\"<\/code> specifies the number of threads to use for parallel execution.<\/li>\n<\/ul>\n\n<p>&nbsp;<\/p>\n<!-- CTA Section -->\n<div class=\"bg-primary text-white text-center\">\n<div class=\"container space-1\"><span class=\"h6 d-block d-lg-inline-block font-weight-light mb-lg-0\"> <span class=\"font-weight-semi-bold\">Need testing?<\/span> \u2013 Try RobotQA and Start Testing on Real Devices. <\/span> <a class=\"btn btn-sm btn-white transition-3d-hover font-weight-normal ml-3\" href=\"\/register\">Start Free Trial<\/a><\/div>\n<\/div>\n<!-- End CTA Section -->\n<p>&nbsp;<\/p>\n\n<h3><strong>4. Running Your Tests<\/strong><\/h3>\nYou can run your tests using the TestNG command-line interface or through an IDE that supports TestNG.\n\nTo run from the command line, use:\n<pre class=\"lang:sh decode:true \">mvn test -Dsurefire.suiteXmlFiles=testng.xml<\/pre>\nThis command tells Maven to use the <code>testng.xml<\/code> configuration file for running the tests.\n<h3>Tips for Parallel Execution<\/h3>\n<ul>\n \t<li><strong>Ensure Appium server is ready<\/strong>: Make sure you have Appium servers running on different ports for each parallel execution instance.<\/li>\n \t<li><strong>Unique Device Configurations<\/strong>: If you are running tests on multiple devices\/emulators, ensure each test configuration points to a unique device.<\/li>\n \t<li><strong>Thread Safety<\/strong>: Ensure your test code is thread-safe, especially if you have shared resources.<\/li>\n<\/ul>\nBy following these steps, you can efficiently run your Appium tests in parallel, significantly reducing the overall test execution time.","protected":false},"excerpt":{"rendered":"<p>Running Appium tests in parallel can significantly speed up the testing process, especially when you have a large suite of tests. To achieve this, you can use a test framework like TestNG in combination with an XML configuration file to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":339,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5],"tags":[2,35,36],"class_list":["post-314","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-automation-testing","category-testing-tools","tag-appium","tag-parallel-test","tag-xml"],"_links":{"self":[{"href":"https:\/\/robotqa.com\/blog\/wp-json\/wp\/v2\/posts\/314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/robotqa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robotqa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robotqa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robotqa.com\/blog\/wp-json\/wp\/v2\/comments?post=314"}],"version-history":[{"count":0,"href":"https:\/\/robotqa.com\/blog\/wp-json\/wp\/v2\/posts\/314\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/robotqa.com\/blog\/wp-json\/wp\/v2\/media\/339"}],"wp:attachment":[{"href":"https:\/\/robotqa.com\/blog\/wp-json\/wp\/v2\/media?parent=314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robotqa.com\/blog\/wp-json\/wp\/v2\/categories?post=314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robotqa.com\/blog\/wp-json\/wp\/v2\/tags?post=314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}