Using Appium With Selenium Grid
During the development of your test suite, it & # x27; s helpful to run test one at a clip, and on one target platform at a time. But when it comes to a product CI surroundings, you & # x27; re decidedly going to want to run your exam in parallel, with as high a concurrency as you can manage. We & # x27; ve already looked at, and it involves setting up specific capability in your test to make certain that, for each test, Appium can instantiate an appropriate driver without step on the toes of the drivers runningother tests. This approach only scales so far, however. There & # x27; s a limit to how many real or practical devices you can run on one machine. What if you want to run 100 Appium? You & # x27; re likely not going to be capable to do that all with one Appium waiter. Or what if you & # x27; re running a web exam, and would like to make sure your testing plant on desktop browser as well as mobile device? For that you & # x27; ll need to mix in Selenium. Either way, you & # x27; re eventually going to run into a situation where you need multiple automation servers running, which adds a lot of complexness to your exam playscript. Now your test script needs to know the host and port of each server, which servers host which devices or browsers, and how to make sure it doesn & # x27; t start too many tests on one host and overload its capacity. Essentially, you & # x27; re dealing with an execution model that looks like this: (In this example, we & # x27; re prove to run a web test in parallel across Safari on iOS, Chrome on Android, and Chrome on Desktop). Thankfully, there & # x27; s a way to mitigate all this complexity, by using a special-purposeload balancer called Selenium Grid. Selenium Grid is basically a proxy server that speaks the WebDriver protocol, and manages connections to a pool of WebDriver servers. It wasn & # x27; t design specifically to work with Appium, but because Appium also speaks the WebDriver protocol (and because we taught Appium how to file with Selenium Grid), it & # x27; s the best tool for DIY Appium clump. Here & # x27; s how Selenium Grid works: In early words, I & # x27; ve been describing a model that appear more like this: Beyond the simplicity of require to know simply about one test waiter, the Selenium Grid model is especially nice for Appium, because Appium driver also ask a routine of scheme resources (unique embrasure, etc ...). On the Grid model, you can start each Appium server independently, with a predefined set of embrasure or the like, using the -- default-capabilities flag. So, for example, I could commence a set of Appium server like this, also using the -- nodeconfig flag to tell Appium it should relate with Selenium Grid: Now each of these Appium servers will be register with the Selenium Grid, and each waiter has declared which wdaLocalPort it needs; now my test handwriting doesn & # x27; t have to know or care about this! It becomes an ops step, which get much more sentiency. The magic middling much all hap in the & quot; node config & quot; file, which is defined as JSON. There are a lot ofnodeconfig optionsto take from, but here & # x27; s an example of the config I & # x27; ll be using for the Safari-on-iOS node in this guide: Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. Let & # x27; s occupy a look at some of the important configuration keys: That & # x27; s basically all you need to know about how Selenium Grid act with Appium. So let & # x27; s dive into a working example. What we want to end up with is parallel executing of one web test, across Safari on iOS, Chrome on Android, and Chrome on Desktop (just like in the diagrams above). Here are the content of the nodeconfig JSON files (in addition to nodeconfig-ios.json, which is above). (You can also download themfrom the Appium Pro repo on GitHub). nodeconfig-android.json: nodeconfig-chrome.json: This is all the frame-up we involve! In a real production CI environment, you & # x27; d probably have this all automate and potentially registering lots more nodes across many different physical or practical servers. Anyway, once you & # x27; ve got everything up and running, you should see message in the Selenium Grid console to the effect that several thickening have checked in: Because our test project is Gradle-based, our good option for scat in parallel is to use maxParallelForks (as described in, along with instructions for Maven-based projects). Here & # x27; s how I & # x27; ve updated my build.gradle to that end: This will cause Gradle to create a new thread for each test form. Unfortunately, a consequence is that for real parallelism, we need to have separate tryout classes, not just separate methods within one exam. For that reason, this example include 4 Java files: one as a basal trial form for shared codification, and 3 platform-specific classes, so that they can be run in latitude. Here & # x27; s the base course: As you can see, it contains the actual trial logic we want to action, which attempts a login onThe Internetand checks that the login fails. The sole real point of interest here is that we get saved a reference to the Grid hub server, running on the default port 4444. This is what each test class will use to connect to the Grid hub. And here are the three platform-specific classes: The only responsibility for these category is to get the correct capabilities set up, instantiate a driver with them, and kick off the actual test. With each of these family set up in their own files appropriately, I can now use a gradle command to run my test suite in parallel: (The * helps me select all the test classes I care about for this example, and not other unity). At this point, all three tests are started simultaneously, and Selenium Grid forward each session to the appropriate node. The result is that all the tests accomplish at the same time (though on my machine, the Chrome Desktop test ends much faster than the early two)! Selenium Grid, and deal in general, is a deep topic, and this guide could only extend the canonic cases. But what we & # x27; ve shown is enough to use to get a examination grid of basically any size up and running, potentially still mixing and fit peregrine and desktop testing as well. What you & # x27; ll no doubt find as you get into put up your own Grid is that, fabulous as Selenium Grid itself may be, there & # x27; s an awful lot of maintenance associated with running the various node! That & # x27; s one reason that there are, nowadays, a number of selection for running your Appium exam in parallel in the cloud, and it & # x27; s important to try answer like these out before going all-in on an in-house Grid setup, so you can do allow cost-benefit analysis for your squad. Lead, Content Marketing, HeadSpin Inc. Piali is a dynamic and results-driven Content Marketing Specialist with 8+ eld of experience in crafting absorb narratives and marketing collateral across diverse manufacture. She excel in cooperate with cross-functional team to develop innovative content strategy and deliver compelling, authentic, and impactful content that resonates with target audiences and enhances brand authenticity. 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)



Using Appium With Selenium Grid
AI-Powered Key Takeaways
Scaling Up Parallel Testing

Check out:
Selenium Grid
Also check:
Read:

appium -- default-capabilities= ' {`` wdaLocalPort '': 8100} ' -- nodeconfig=/path/to/nodeconfig.json appium -- default-capabilities= ' {`` wdaLocalPort '': 8200} ' -- nodeconfig=/path/to/nodeconfig.jsonAccelerate Appium test cycles with the HeadSpin.Learn more.
Node Config
{`` capabilities '': [{`` deviceName '': `` iPhone 8 '', `` platformVersion '': `` 11.4 '', `` maxInstances '': 1, `` platformName '': `` iOS '', `` browserName '': `` Safari ''}], `` shape '': {`` cleanUpCycle '' :2000, `` timeout '' :30000, `` proxy '': `` org.openqa.grid.selenium.proxy.DefaultRemoteProxy '', `` maxSession '': 1, `` register '': true, `` registerCycle '': 5000, `` hubPort '': 4444, `` hubHost '': `` 127.0.0.1 '', `` hubProtocol '': `` http ''}}Read:
Starting Up the Grid
# Window 1: the Grid hub java -jar /path/to/selenium-server-standalone.jar -role hub # Window 2: the iOS node appium -p 4723 -- nodeconfig /path/to/nodeconfig-ios.json # Window 3: the Android node appium -p 4733 -- nodeconfig /path/to/nodeconfig-android.json # Window 4: the Chrome desktop node java -Dwebdriver.chrome.driver= '' /path/to/chromedriver '' -jar /path/to/selenium-server-standalone.jar -role node -nodeConfig /path/to/nodeconfig-chrome.json{`` capabilities '': [{`` browserName '': `` Chrome '', `` platformVersion '': `` 26 '', `` maxInstances '': 1, `` platformName '': `` Android '', `` automationName '': `` UiAutomator2 '', `` deviceName '': `` Android Emulator ''}], `` configuration '': {`` cleanUpCycle '' :2000, `` timeout '' :30000, `` proxy '': `` org.openqa.grid.selenium.proxy.DefaultRemoteProxy '', `` maxSession '': 1, `` registry '': true, `` registerCycle '': 5000, `` hubPort '': 4444, `` hubHost '': `` 127.0.0.1 '', `` hubProtocol '': `` http ''}}{`` capabilities '': [{`` browserName '': `` chrome '', `` browserVersion '': `` 71 '', `` platformName '': `` MAC '', `` maxInstances '': 1}], `` cleanUpCycle '' :2000, `` timeout '' :30000, `` proxy '': `` org.openqa.grid.selenium.proxy.DefaultRemoteProxy '', `` maxSession '': 1, `` registry '': true, `` registerCycle '': 5000, `` hubPort '': 4444, `` hubHost '': `` 127.0.0.1 '', `` hubProtocol '': `` http ''}Also read:
13:48:04.514 INFO [DefaultGridRegistry.add] - Registered a node http: //0.0.0.0:4733Check:
Running Tests on the Grid
exam {maxParallelForks = 3 forkEvery = 1}public class Edition054_Selenium_Grid {protected RemoteWebDriver driver; static String HUB_URL = `` http: //localhost:4444/wd/hub ''; individual static By loginBtn = By.tagName (`` button ''); private static By username = By.id (`` username ''); private still By word = By.id (`` password ''); individual static By message = By.id (`` flashing ''); individual still String LOGIN_URL = `` https: //the-internet.herokuapp.com/login ''; individual static String ERR_MSG = `` Your username is invalid! ``; @ After public void tearDown () {if (driver! = null) {driver.quit ();}} protected void actualTest (RemoteWebDriver driver) {WebDriverWait expect = new WebDriverWait (driver, 10); driver.navigate () .to (LOGIN_URL); wait.until (ExpectedConditions.presenceOfElementLocated (username)) .sendKeys (`` foo ''); driver.findElement (password) .sendKeys (`` bar ''); driver.findElement (loginBtn) .click (); String errText = wait.until (ExpectedConditions.presenceOfElementLocated (substance)) .getText (); Assert.assertThat (errText, Matchers.containsString (ERR_MSG));}}Read:
public class Edition054_Selenium_Grid_IOS extends Edition054_Selenium_Grid {@ Test world vacancy testIOS () throws MalformedURLException {DesiredCapabilities cap = new DesiredCapabilities (); caps.setCapability (`` platformName '', `` iOS ''); caps.setCapability (`` platformVersion '', `` 11.4 ''); caps.setCapability (`` deviceName '', `` iPhone 8 ''); caps.setCapability (`` browserName '', `` Safari ''); driver = new RemoteWebDriver (new URL (HUB_URL), detonator); actualTest (driver);}} public class Edition054_Selenium_Grid_Android extends Edition054_Selenium_Grid {@ Test public void testAndroid () throws MalformedURLException {DesiredCapabilities caps = new DesiredCapabilities (); caps.setCapability (`` platformName '', `` Android ''); caps.setCapability (`` deviceName '', `` Android Emulator ''); caps.setCapability (`` automationName '', `` UiAutomator2 ''); caps.setCapability (`` browserName '', `` Chrome ''); driver = new RemoteWebDriver (new URL (HUB_URL), caps); actualTest (driver);}} public grade Edition054_Selenium_Grid_Desktop extends Edition054_Selenium_Grid {@ Test public vacuum testDesktop () throws MalformedURLException {DesiredCapabilities crest = new DesiredCapabilities (); caps.setCapability (`` browserName '', `` chrome ''); caps.setCapability (`` browserVersion '', `` 71 ''); caps.setCapability (`` platformName '', `` MAC ''); driver = new RemoteWebDriver (new URL (HUB_URL), caps); actualTest (driver);}}./gradlew: cleanTest: test -- tests `` Edition054_Selenium_Grid.Edition054_Selenium_Grid_ * ''Optimize digital experience with the mobile app performance quiz capabilities of the HeadSpin.Learn more.
Wrap-up
Piali Mazumdar
Using Appium With Selenium Grid
4 Parts
-1280X720-Final-2.jpg)
Regression Intelligence practical guide for advanced users (Part 3)
-1280X720-Final-2.jpg)
Regression Intelligence pragmatic usher for advanced users (Part 4)
Discover how HeadSpin can authorize your occupation with superior testing potentiality







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


Automate This With SUSA
Test Your App Autonomously







.png)












