【问题标题】:Parallel execution in multiple devices using thread concept java使用线程概念java在多个设备中并行执行
【发布时间】:2016-08-25 19:42:51
【问题描述】:

我是 Java 新手。请帮忙。 我有一个要求,我需要在 java 中的多个设备中执行相同的测试场景。 此外,要求说我的代码不应该单独在一个设备中执行,它应该一次在多个设备中启动相同的场景。

是否可以一次执行。

注意: 我一次连接了 3 个设备。 但它一个接一个地执行相同的场景。

我正在使用 appium 服务器并进行测试

请帮忙.. 提前致谢。

【问题讨论】:

    标签: java multithreading testng appium concept


    【解决方案1】:
    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
        }
    }
    

    【讨论】:

    • 如果对你有帮助请告诉我
    • 它只有助于在一台设备上执行.. 但我需要在多个设备上执行
    • 我知道你的答案.. 但是服务器只启动了一次.. 没关系.. 我很困惑,因为直到现在我认为我们需要为每个设备运行多个服务器。
    • 请根据您要运行的设备数量创建尽可能多的 WebDriver 驱动程序,代码就可以了。
    • 我的意思是一台服务器用于一台设备。
    【解决方案2】:

    你可以试试这样的:

    public void startAppium() {
        //start appium instance
        try {
            Thread.sleep((long)(Math.random() * 10000)); //wait from 0 to 10 sec for parallel process run
            ProcessBuilder builder = new ProcessBuilder(getCmd());
            builder.redirectOutput("path to log file"); //here you can find logs of appium
            builder.redirectErrorStream(true);
            appium = builder.start();
            Thread.sleep(3000); //wait 3 sec until server started
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    【讨论】:

    • 是的,我可以理解这段代码是用于服务器启动的,但现在我需要一个示例代码,说明如何在多个设备中同时执行相同的测试场景。请帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 1970-01-01
    • 2013-09-07
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多