Appium-Parallel Testing-1: Using ‘Separate Appium Instances’ for ‘Separate Devices’
i.e.(Running multiple Appium servers & sending one session to each server)

Please go through the below video for complete details:
Parallel Testing — Client Side Settings:
Add/Update “Surefire plugin” pom.xml with the following kind of configuration
Step1:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-suresafe-plugin</artifactId>
<version>3.5.2</version>
<executions>
<execution>
<configuration>
<parallel>classes</parallel>
<threadCount>5</threadCount>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Parallel Testing — Client Side Settings:
Step2:
<suite name = "Parallel Testing Suite">
<test name = "Parallel Tests" parallel = "classes" thread-count = "2">
<classes>
<class name = "demo1.Test1" />
<class name = "demo1.Test1" />
</classes>
</test>
</suite>
2. Parallel Testing — Server Side Settings:
appium -p 10000 # server 1
appium -p 10001 # server 2
Then, each test thread would need to adjust the URL of the Appium server to include the appropriate port,
Android & iOS Parallel Testing Capabilities:
udid: if you don’t include this capability, the driver will attempt to use the first device in the list returned by ADB. This could result in multiple sessions targeting the same device, which is not a desirable situation. Thus it’s essential to use the udid capability, even if you’re using emulators for testing (in which case the emulator looks like emulator-55xx).
Java Code: Test1.class
package demo1;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
public class Test1 {
private AndroidDriver driver;
String app_package="com.fastaguser";
@BeforeTest
public void stepup1() throws MalformedURLException {
UiAutomator2Options cap =new UiAutomator2Options();
cap.setPlatformName("android");
cap.setAutomationName("uiautomator2");
cap.setUdid("emulator-5554");
driver=new AndroidDriver(new URL("http://127.0.0.1:10000"), cap);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@Test
public void sessionidsample() throws InterruptedException {
Thread.sleep(5000);
driver.activateApp(app_package);
Thread.sleep(5000);
driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().className(\"android.widget.ImageView\").instance(3)")).click();
driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().className(\"android.widget.LinearLayout\").instance(6)")).click();
driver.findElement(AppiumBy.id("com.fastaguser:id/vehicle_id_txt")).sendKeys("1234");
driver.findElement(AppiumBy.id("com.fastaguser:id/btn_submit")).click();
}
@AfterTest
public void teardown1() {
if(driver!=null) {
driver.quit();
System.out.println("Test Completed");
}
}
}
Java Code: Test2.class
package demo1;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
import io.appium.java_client.android.options.UiAutomator2Options;
import java.net.*;
import java.time.Duration;
public class Test2 {
private AndroidDriver driver;
@BeforeTest
public void setup2() throws MalformedURLException {
UiAutomator2Options cap=new UiAutomator2Options();
cap.setPlatformName("android");
cap.setAutomationName("uiautomator2");
cap.setUdid("emulator-5556");
driver = new AndroidDriver(new URL("http://127.0.0.1:10001"), cap);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@Test
public void test1() throws InterruptedException {
driver.activateApp("io.appium.android.apis");
driver.findElement(AppiumBy.accessibilityId("Views")).click();
driver.findElement(AppiumBy.androidUIAutomator("new UiScrollable(new UiSelector().scrollable(true))"+
".scrollIntoView(new UiSelector().text(\"Tabs\"))"));
driver.findElement(AppiumBy.accessibilityId("Tabs")).click();
driver.findElement(AppiumBy.accessibilityId("5. Scrollable")).click();
driver.findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().setMaxSearchSwipes(10)" +
".scrollIntoView(new UiSelector().text(\"TAB 30\"))"));
Thread.sleep(5000);
driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().text(\"TAB 30\")")).click();
driver.findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().setMaxSearchSwipes(10)" +
".scrollIntoView(new UiSelector().text(\"TAB 1\"))"));
Thread.sleep(5000);
driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().text(\"TAB 1\")")).click();
}
@AfterTest
public void teardown2() {
if(driver!=null) {
driver.quit();
}
}
}
GitHub Link:
https://github.com/AppiumGuide/AppiumGuide
🎬 Explore More! Watch My Latest Videos on YouTube!
No comments:
Post a Comment