android-使用appium和Selenium网格运行自动化测试仅在一个设备上运行

android-使用appium和Selenium网格运行自动化测试仅在一个设备上运行,第1张

概述我正在尝试使用appium和Selenium网格运行一些移动自动化测试.完成所有配置工作并添加网格节点后,如何在两个设备中并行运行测试?这是我的setUp():desired_caps={}desired_caps['platformName']='Android'desired_caps['platformVersion']='5.1'desired_caps[

我正在尝试使用appium和Selenium网格运行一些移动自动化测试.完成所有配置工作并添加网格节点后,如何在两个设备中并行运行测试?

这是我的setUp():

desired_caps = {}    desired_caps['platformname'] = 'AndroID'    desired_caps['platformVersion'] = '5.1'    desired_caps['devicename'] = ''    desired_caps['app'] = os.path.abspath(os.path.join(os.path.dirname(__file__), 'C:/Users/XXXXX/Desktop/workspace/XXXX/apps/XXXXX.apk'))    desired_caps['appPackage'] = 'XXXXXXXX'    desired_caps['appActivity'] = '.MainActivity'    desired_caps['noreset'] = False    self.driver = webdriver.Remote('http://localhost:4444/wd/hub', desired_caps)    self.driver.implicitly_wait(15) 

在这种情况下,devicename应该包含什么?

如果我将其留空,这就是我得到的:

C:\Users\XXXXX\Desktop\workspace\XXXXX>java -jar selenium-server-standalone-2.44.0.jar -role hub19:16:58.691 INFO - Launching a selenium grID server2016-02-18 19:16:59.937:INFO:osJs.Server:jetty-7.x.y-SNAPSHOT2016-02-18 19:16:59.968:INFO:osJsh.ContextHandler:startedo.s.j.s.ServletContextHandler{/,null}2016-02-18 19:16:59.995:INFO:osJs.AbstractConnector:StartedSocketConnector@0.0.0.0:444419:49:48.183 INFO - Got a request to create a new session: CapabilitIEs[{app=C:\Users\XXXXX\Desktop\workspace\XXXXX\apps\XXXXX.apk, appPackage=XXXXXXX, appActivity=.MainActivity, noreset=true, platformVersion=5.1, platformname=AndroID, devicename=}]19:49:48.183 INFO - Available nodes: [host :http://127.0.0.1:4723, host :http://127.0.0.1:4733] 19:49:48.183 INFO - Trying to create a new session on node host :http://127.0.0.1:472319:49:48.183 INFO - Trying to create a new session on test slot {newCommandTimeout=30, browsername=AndroID, maxInstances=1, version=5.1,devicename=0429058934,deviceReadyTimeout=5, platform=ANDROID}

我只能在网格中运行一个注册的节点.我什至尝试用两个setup()创建一个脚本,每个设备每个设备一个,但是即使这样,测试也只能在同一台设备上运行一个设备.

这是我的网格控制台:

解决方法:

    I dID try to run tests using GrID with Appium server in java, same logic you can adopt for your own language. Here is the explanation:    1. This is the same content of node.Json file on two node machines:    {    "capabilitIEs":         [           {             "version":"4.4.2",             "maxInstances": 3,             "platformname":"ANDROID"           }         ],    "configuration":    {       "cleanUpCycle":2000,       "timeout":30000,       "proxy": "org.openqa.grID.selenium.proxy.DefaultRemoteProxy",       "url":"http://WHERE_APPIUM_RUNNNING:4723/wd/hub",       "host": "WHERE_APPIUM_RUNNNING_IP",       "port": 4723,       "maxSession": 6,       "register": true,       "registerCycle": 5000,       "hubPort": 4444,       "hubHost": "WHERE_HUB_RUNNNING_IP"    }    }     2. Downloaded selenium-server-standalone-2.52.0.jar and started as hub on one machine like:     java -jar ~/Downloads/selenium-server-standalone-2.52.0.jar -role hub maxInstances=2 maxSessions=2     3. Started ONLY appium server on node machines and registered with hub using command as: appium --nodeconfig ~/Desktop/node.Json    4. Now declare all the common capability in GrIDTest.java and only devicename was passed from testNG.xml in order to avoID any hardCoding in code and keePing node.config as generic for all node machines, sample testNG.xml is like:    <?xml version="1.0" enCoding="UTF-8"?>    <!DOCTYPE suite SYstem "http://testng.org/testng-1.0.dtd">    <suite name="automation" parallel="tests">        <test name="Test1">        <parameter name="devicename" value="XYZZZZZ" />            <classes>                <class name="poc.grID.GrIDTest" />            </classes>        </test>        <test name="Test2">        <parameter name="devicename" value="ZYXXXXX" />            <classes>                <class name="poc.grID.GrIDTest" />            </classes>        </test>    </suite>    5. And I wrote a GrIDTest.java class like:    package poc.grID;    import java.net.MalformedURLException;    import java.net.URL;    import java.util.concurrent.TimeUnit;    import org.openqa.selenium.WebDriver;    import org.openqa.selenium.remote.DesiredCapabilitIEs;    import org.openqa.selenium.remote.RemoteWebDriver;    import org.testng.annotations.Parameters;    import org.testng.annotations.Test;    public class GrIDTest {        @Parameters({"devicename"})        @Test        public voID test (String devicename) throws MalformedURLException, InterruptedException        {            appium_driver(devicename);        }        public voID appium_driver(String devicename)        {            try            {                DesiredCapabilitIEs capabilitIEs = new DesiredCapabilitIEs();                capabilitIEs.setCapability("devicename", devicename);                capabilitIEs.setCapability("platformname", "AndroID");                if(devicename.equalsIgnoreCase("4d0025b440ca90d5")){                    capabilitIEs.setCapability("app", "/XXXXXX/chocolate.apk");                }else{                    capabilitIEs.setCapability("app", "/XXXXXX/chocolate.apk");                }                capabilitIEs.setCapability("newCommandTimeout", "120");                WebDriver driver = new RemoteWebDriver(new URL("http://WHERE_HUB_RUNNNING_IP:4444/wd/hub"), capabilitIEs);                driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);            }            catch(Exception e)            {                System.out.println(e.getMessage());                e.printstacktrace();            }        }    }6. If you are using eclipse, then Right Click on testNG.xml and select Run As --> TestNg Suite.7. Now you can see I've kept a condition only for apk file location because the node machines have different directory, if possible you should choose a similar location which exists in all node machines, else you may have to live with if - else.  Hope This Helps !!

总结

以上是内存溢出为你收集整理的android-使用appium和Selenium网格运行自动化测试仅在一个设备上运行全部内容,希望文章能够帮你解决android-使用appium和Selenium网格运行自动化测试仅在一个设备上运行所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1120618.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存