appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.22k stars 758 forks source link

Unable to run the test parallelly on 2 devices through testng (appium java) > code runs individually << failed due to unable to locate the element #1761

Open lakshmividyadharan opened 2 years ago

lakshmividyadharan commented 2 years ago

testng XML : <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">

Test : package tests; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Method; import java.util.Properties; import java.util.concurrent.TimeUnit; import org.testng.Assert; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; //import Practice.BluesecureTC.Base1; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.AndroidElement; import pages.GetVerificationCodePage; import pages.InviteUserPage; import pages.OTPVerificationPage; import pages.SplashPage; import utils.Base; import utils.Base2; public class Muti_LoginTC2 extends Base2{ @BeforeTest() public void killAllnodes() throws IOException, InterruptedException { Runtime.getRuntime().exec("taskkill /F /IM node.exe"); Thread.sleep(3000); } // @AfterTest // public void stop() // { // stop_service(); // } // @Test public void login1() throws IOException, InterruptedException { AndroidDriver driver1 = startServer("8244","Bluesecure","RZ8R915W2KW"); driver1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); System.out.println("Thread one is" +Thread.currentThread().getId()); SplashPage s1=new SplashPage(driver1); GetVerificationCodePage verify = new GetVerificationCodePage(driver1); OTPVerificationPage otp = new OTPVerificationPage(driver1); s1.naviagte(); // String expected="android.widget.ScrollView"; // String actual = verify.allow_permissions(); verify.login("8755875532"); otp.verifyOtp(); } @Test public void login2() throws IOException, InterruptedException { AndroidDriver driver2 = startServer("8241","Bluesecure","HA4L6TGQGET4CMDI"); //AndroidDriver driver = capabilities("Bluesecure"); driver2.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); System.out.println("Thread two is" +Thread.currentThread().getId()); SplashPage s2=new SplashPage(driver2); GetVerificationCodePage verify2 = new GetVerificationCodePage(driver2); OTPVerificationPage otp2 = new OTPVerificationPage(driver2); s2.naviagte(); // String expected="android.widget.ScrollView"; // String actual = verify2.allow_permissions(); verify2.login("9544696100"); otp2.verifyOtp(); // } // @Test // public void login3() throws IOException, InterruptedException // { // AndroidDriver driver = startServer("8997","Bluesecure","RZ8R915W2KW"); // //AndroidDriver driver = capabilities("Bluesecure"); // driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // // // SplashPage s1=new SplashPage(driver); // // GetVerificationCodePage verify = new GetVerificationCodePage(driver); // OTPVerificationPage otp = new OTPVerificationPage(driver); // // s1.naviagte(); //// String expected="android.widget.ScrollView"; //// String actual = // // verify.allow_permissions(); // verify.login("9544696100"); // otp.verifyOtp(); //// // } }
lakshmividyadharan commented 2 years ago

one device test pass, other device test will stop without locating any element

amuthansakthivel commented 1 year ago

@lakshmividyadharan - I think it may be because you doing something wrong in your code or setup. There are multiple ways to perform parallel execution.

  1. You can have same appium server with different port
  2. You can have two different appium server pointing your tests to them

Plesae refer to this video - https://www.youtube.com/watch?v=Z7vIuEWmi3A&list=PL9ok7C7Yn9A9qy5rqMiFtGHPbwM9yOxCW&index=7