Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

appium - Multi-devices support in Android

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 Support multiple (Android) devices from a single Appium server

But, still I can't figure out setup environment for multiple devices.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...