Multi-devices support in Android

前端 未结 5 814
既然无缘
既然无缘 2020-12-15 14:28

I am trying to run a script on Multiple devices in Andriod platform, but I am unable to run. I went through Github page for a solution and found the following link about Sup

相关标签:
5条回答
  • 2020-12-15 14:36

    The following code will help you.

    //Running multiple emulators from single appium server

    public class Test{
    
        WebDriver driver = null;
        int timeOut=180;
        int port=-1;
    
        Test(int port){
            this.port=port;
        }
    
        public void testEmulator(int p) throws Exception {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
            capabilities.setCapability(CapabilityType.VERSION, "4.3");
            capabilities.setCapability(CapabilityType.PLATFORM, "Windows");
    
            capabilities.setCapability("udid","emulator-"+p);
    
            capabilities.setCapability("app-package", "your.app.pkg");
            capabilities.setCapability("app-activity",
                "your.app.pkg.Activity");
            driver = new RemoteWebDriver(new URL("http://127.0.0.1:"+this.port+"/wd/hub"),
            capabilities);
            driver.manage().timeouts().implicitlyWait(timeOut, TimeUnit.SECONDS);
            Thread.sleep(50000);
        }
    
        public void tearDown() {
            if (driver != null)
                driver.quit();
        }
    
        public void runTest() {
            try {
                testEmulator(5554);     // for emulator on port 5554
                tearDown();
                testEmulator(5556);     // for emulator on port 5556
                tearDown();
            } catch (Exception e) {
                e.printStackTrace();
            }
    
        }
    
        public static void main(String[] args) {
            new Test(4723).runTest();       // appium server port 4723
        }
    }
    
    0 讨论(0)
  • 2020-12-15 14:41

    To run appium script on multiple devices

    1. You have to start appium servers as per number of devices with different ports number.
    2. Create driver instance with each port in your favorite language (java, ruby)
    3. Run those script simultaneously.
    4. You can also create thread based program which will create different driver instances.

    Here I have create simple java thread based program

    https://github.com/sameer49/Appium-Grid-For-Android

    0 讨论(0)
  • 2020-12-15 14:42

    For multiple android devices start your appium server with parameters:

    • node appium.js -p 4476 -U <device1_serial>
    • node appium.js -p 4475 -U <device2_serial>

    You can select any port, but make sure they are different in your code, where you are creating driver, provide server url:

    server1_url = "http://127.0.0.1:4475/wd/hub"
    server2_url = "http://127.0.0.1:4476/wd/hub"
    

    Done.

    0 讨论(0)
  • 2020-12-15 14:49

    For sequential or parallel execution on multiple android devices, we need to -

    1. Have separate Appium instance for each device or emulator
    2. For each device/Appium instance, provide different values for Appium port, Bootstrap Port, Device ID (ie UDID, not Device Name)
    3. Provide different Chrome Driver port, if using Chrome browser on the app

    Check the below post, which uses Java Thread and Runnable interface for parallel execution - http://automationtestinghub.com/appium-parallel-execution/

    0 讨论(0)
  • 2020-12-15 14:55

    If you are talking about the GUI, I guess your environment is Windows? Then you can use the following batch:

    @ECHO OFF
    
    cd "C:\Program Files (x86)\Appium\node_modules\appium"
    
    node server.js --app "<path-to-your-project>\bin\<app-name>.apk" -p <port-to-listen-on> -dp <device-port-to-connect-to-device-on>
    

    With this you should be able to start two different Appium servers and using them parallel.

    For a full list of all available commands, type node server.js --help.

    If you installed Appium via npm, the path to server.js would be something like "C:\Users\\AppData\Roaming\npm\node_modules\appium" instead.

    0 讨论(0)
提交回复
热议问题