Running Multiple Appium Tests in Parallel
UI-driven functional tests take clip, and even when we & # x27; ve used all the trick up our Appium sleeves, the tests will ne'er be as tight as, say, unit tests. The ultimate solution to this is to run more than one trial at a time. Think about it this way: if you have a build in which you are constantly adding tests (as you are likely to do while), then each additional test will add directly to your build time, if you & # x27; re running them one-by-one: Let & # x27; s say, on the other hand, that for each additional examination you add to your anatomy, you unlock an additional trial execution thread. In this case, you & # x27; re bunk every individual test simultaneously, and the build is only as long as the longest trial! It & # x27; s credibly not realistic to take that you could give thousands of test execution threads, but it illustrates the point that ofttimes the most effective optimisation you can make to reduce overall build clip is to parallelize test execution. Also, with the availability of, adding additional exam threads becomes a problem of toll rather than technological feasibleness. In another article, we & # x27; ll discourse all the ins and outs of parallelization from a testsuite perspective. For now, let & # x27; s just learn the mechanics of bunk multiple Appium session at a time, and leave the big-picture stuff for later. There are basically four designs for lam multiple Appium sessions at a clip: (In this article we & # x27; ll explore Options 1 and 2 above, leaving Selenium Grid and cloud-based Appium testing as topics for former articles.) Regardless of which option you choose for the Appium server side of the equation, there is also the client side to vex about. Just because you have multiple Appium servers or a cloud-based solution doesn & # x27; t entail you have parallel examination -- -you too need a way for your test contrabandist or test fabric to kick off the tests in analog! This ability to run tests in multiple threads (or using an event loop) is not part of Appium itself and must be configure in your test runner itself. Each words and test runner has its own way of accomplishing this task. In the world of Java, the near aboveboard way to do this is probably with Maven and theSurefire plugin, which lets you update yourpom.xmlwith the following kind of configuration: Here you can see that we can either parallelize based on methods or some other grouping (classes, for example). We can also specify how many test threads we want -- -this should of course match the number of Appium sessions we can handle. For most of Appium & # x27; s history, Option 1 (running multiple host) was the lone way to achieve multiple co-occurrent sessions. The Appium server was not set up for handling multiple simultaneous sessions, so the recommended coming was to start different Appium servers listening on different ports, for example: Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. Then, each test thread would need to aline the URL of the Appium server to include the appropriate port, for exemplar: Obviously, this isn & # x27; t ideal from a testsuite design perspective, since we have to feature some way of specifying port differently based on different yarn, signify creating different trial classes or similar. Nowadays, Option 1 is thankfully not the only alternative: we can also simply start multiple sessions on a single run Appium waiter! This imply we can bury starting multiple waiter on different ports and rely on the one waiter running on the default port, or any embrasure we want. Unfortunately, this isn & # x27; t everything we have to worry about. Appium orchestrates a host of services under the hoodlum to ease communicating between different subsystem and drivers. In some cases, an Appium driver might want to use a port or a socket, and it would not be good for another session using the like driver to compete for communication on the same porthole or socket. There are thus a fistful of capability that take to be included to make certain no system resource conflicts live between your different test sessions. One vantage of Option 1 (running multiple Appium servers) that I didn & # x27; t reference ahead is that you can use it to nobble away all this embrasure conformation from your testsuite, by leveraging the-- default-capabilitiesserver flag. Essentially, you can define unique porthole value on server start (rather than in desired capabilities), for example: (This gets us back to the problem of now having to stipulate different Appium server ports in our driver creation, but this problem could be avoided with the use of something like Selenium Grid) Once we & # x27; ve got our node set up to fire off multiple tests at the same time, an Appium server running which can handle multiple sessions (or we & # x27; re run multiple servers), and appropriately unique desired capability for each test thread, we & # x27; re good to go. With the Gradle setup I & # x27; m use for Appium Pro, the Maven method I discussed above is not available to me. The most aboveboard approach is to parallelize based on test grade. First, I ask to update mybuild.gradleto include the next directive: This tells Gradle that I need to run in at most 2 processes, forking a new process for every test class I encounter. What I require to do next is organize my testsuite so that different course contain different sets of desired capabilities. Because I am multiplying test classes based on the number and type of capability sets, that signify each trial class should inherit a base class which moderate the actual logic (we don & # x27; t want to double that!), so some organization like the following: In a existent, well-architected physique, you probably need to postdate a completely different approach, one that doesn & # x27; t affect hand-coding multiple classes just for the sake of getting parallel testing proceed, but for the interest of this article it & # x27; s what we & # x27; ll do. Here & # x27; s an example of login exam ready to be run in parallel on different: Edition028_Parallel_Testing_Base.java Edition028_Parallel_Testing_iOS.java Edition028_Parallel_Testing_iOS_2.java Notice that both of classes with existent@Testnote differ merely by a few capabilities. This could obviously be tightened up to reduce boilerplate, apply an anon. internal form design, or alike. But it illustrates the point. Now, we can run these tests in parallel by isolating them using gradle: If you run this, you & # x27; ll see the Appium server handling multiple sessions at the same time, their log yield interleave. This is another ground to potentially choose multiple servers over a single server -- -the ability to direct log yield to different file, or otherwise hold it sensibly direct for debug purposes! And that & # x27; s basically it. Parallel testing is a deep topic and there & # x27; s scads more to say about it, so stay tuned for other clause in this genre. Don & # x27; t forget to see outthe total code samplefor this edition, which also includes an Android test family. You can update thebuild.gradlefile to have amaxParallelForks of 3, fire up an, and run a cross-platform suite in parallel too! Lead, Content Marketing, HeadSpin Inc. Piali is a dynamic and results-driven Content Marketing Specialist with 8+ days of experience in crafting engage narratives and marketing collateral across diverse manufacture. She excel in collaborating with cross-functional teams to germinate innovative content strategies and deliver compelling, authentic, and impactful content that vibrate with mark audiences and enhances brand genuineness. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts..png)



Running Multiple Appium Tests in Parallel
AI-Powered Key Takeaways


Parallel Testing - Client Side
& lt; plugin & gt; & lt; groupId & gt; org.apache.maven.plugins & lt; /groupId & gt; & lt; artifactId & gt; maven-surefire-plugin & lt; /artifactId & gt; & lt; configuration & gt; & lt; parallel & gt; methods & lt; /parallel & gt; & lt; threadCount & gt; 4 & lt; /threadCount & gt; & lt; /configuration & gt; & lt; /plugin & gt;Parallel Testing - Server Side
appium -p 10000 # server 1 appium -p 10001 # server 2Check:
@ Test public vacancy testOnServer1 () throws MalformedURLException {DesiredCapabilities capabilities = new DesiredCapabilities (); capabilities.setCapability (`` platformName '', `` iOS ''); capabilities.setCapability (`` platformVersion '', `` 11.4 ''); capabilities.setCapability (`` deviceName '', `` iPhone 8 ''); capabilities.setCapability (`` app '', APP); IOSDriver driver = new IOSDriver < > (new URL (`` http: //localhost:10000/wd/hub ''), capabilities); actualTest (driver);} public void testOnServer2 () throws MalformedURLException {DesiredCapabilities capabilities = new DesiredCapabilities (); capabilities.setCapability (`` platformName '', `` iOS ''); capabilities.setCapability (`` platformVersion '', `` 11.4 ''); capabilities.setCapability (`` deviceName '', `` iPhone 8 ''); capabilities.setCapability (`` app '', APP); IOSDriver driver = new IOSDriver < > (new URL (`` http: //localhost:10001/wd/hub ''), capabilities); actualTest (driver);}Android Parallel Testing Capabilities
iOS Parallel Testing Capabilities
Check out:
Option 1 Redux
appium -p 10000 -- default-capabilities ' {`` systemPort '': 8200, `` udid '': `` emulator-5554 ''} ' appium -p 10001 -- default-capabilities ' {`` systemPort '': 8201, `` udid '': `` emulator-5556 ''} 'Read:
Putting It All Together
test {maxParallelForks = 2 forkEvery = 1}BaseTests | -- BaseIOSTests | | -- IOSTests_Group1 | | -- ISOTests_Group2 | -- BaseAndroidTests | -- AndroidTests_Group1 | -- AndroidTests_Group2package Edition028_Parallel_Testing; import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileBy; importee org.openqa.selenium.By; signification org.openqa.selenium.support.ui.ExpectedConditions; importee org.openqa.selenium.support.ui.WebDriverWait; public form Edition028_Parallel_Testing_Base {protect String AUTH_USER = `` alice ''; protected String AUTH_PASS = `` mypassword ''; protected By loginScreen = MobileBy.AccessibilityId (`` Login Screen ''); protect By loginBtn = MobileBy.AccessibilityId (`` loginBtn ''); protect By username = MobileBy.AccessibilityId (`` username ''); protected By password = MobileBy.AccessibilityId (`` password ''); public void actualTest (AppiumDriver driver) {WebDriverWait expect = new WebDriverWait (driver, 10); try {wait.until (ExpectedConditions.presenceOfElementLocated (loginScreen)) .click (); wait.until (ExpectedConditions.presenceOfElementLocated (username)) .sendKeys (AUTH_USER); wait.until (ExpectedConditions.presenceOfElementLocated (word)) .sendKeys (AUTH_PASS); wait.until (ExpectedConditions.presenceOfElementLocated (loginBtn)) .click ();} finally {driver.quit ();}}}package Edition028_Parallel_Testing; significance io.appium.java_client.ios.IOSDriver; import java.net.MalformedURLException; significance java.net.URL; import org.junit.Test; signification org.openqa.selenium.remote.DesiredCapabilities; public class Edition028_Parallel_Testing_iOS extends Edition028_Parallel_Testing_Base {protected String APP = `` https: //github.com/cloudgrey-io/the-app/releases/download/v1.5.0/TheApp-v1.5.0.app.zip ''; @ Test public void testLogin_iOS () throws MalformedURLException {DesiredCapabilities capabilities = new DesiredCapabilities (); capabilities.setCapability (`` platformName '', `` iOS ''); capabilities.setCapability (`` platformVersion '', `` 11.4 ''); capabilities.setCapability (`` deviceName '', `` iPhone 8 ''); capabilities.setCapability (`` wdaLocalPort '', 8100); capabilities.setCapability (`` app '', APP); IOSDriver driver = new IOSDriver < > (new URL (`` http: //localhost:4723/wd/hub ''), capacity); actualTest (driver);}}package Edition028_Parallel_Testing; significance io.appium.java_client.ios.IOSDriver; import java.net.MalformedURLException; import java.net.URL; import org.junit.Test; importation org.openqa.selenium.remote.DesiredCapabilities; public course Edition028_Parallel_Testing_iOS_2 extends Edition028_Parallel_Testing_Base {protected String APP = `` https: //github.com/cloudgrey-io/the-app/releases/download/v1.5.0/TheApp-v1.5.0.app.zip ''; @ Test public void testLogin_iOS () drop MalformedURLException {DesiredCapabilities capabilities = new DesiredCapabilities (); capabilities.setCapability (`` platformName '', `` iOS ''); capabilities.setCapability (`` platformVersion '', `` 11.4 ''); capabilities.setCapability (`` deviceName '', `` iPhone X ''); capabilities.setCapability (`` wdaLocalPort '', 8101); capabilities.setCapability (`` app '', APP); IOSDriver driver = new IOSDriver < > (new URL (`` http: //localhost:4723/wd/hub ''), capabilities); actualTest (driver);}}gradle cleanTest test -- tests `` Edition028_Parallel_Testing_iO * ''Piali Mazumdar
Running Multiple Appium Tests in Parallel
4 Parts
-1280X720-Final-2.jpg)
Regression Intelligence practical guide for innovative exploiter (Part 3)
-1280X720-Final-2.jpg)
Regression Intelligence practical guidebook for advanced users (Part 4)
Discover how HeadSpin can empower your business with superior testing capabilities







Discover how HeadSpin can empower your business with superior testing capabilities
Discover how HeadSpin can empower your business with superior quiz potentiality
Connet Now


Automate This With SUSA
Test Your App Autonomously







.png)












