2016-02-18 19 views
3

我想要一些移動自動化測試運行與app和硒網格。一旦我完成所有配置的東西,並添加網格節點,我如何在兩個設備中並行運行我的測試?運行自動化測試與app和硒網格只運行在一個設備

這裏是我的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 hub 

19:16:58.691 INFO - Launching a selenium grid server 

2016-02-18 19:16:59.937:INFO:osjs.Server:jetty-7.x.y-SNAPSHOT 

2016-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:[email protected]:4444 

19: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:4723 

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

我只能夠運行一個註冊節點的網格。我甚至試圖用two setup()創建一個腳本,每個設備都有一個腳本,但即使如此,測試只能在同一個設備上運行一個設備。

這裏是我的網格控制檯:

enter image description here

+0

deviceName是必需的,但是對於Android是任意的(對於iOS,它決定了iOS設備的啓動類型)。不過,我注意到你沒有設置「avd」功能。您是否啓用了啓用USB調試的真實設備? – econoMichael

+0

@econoMichael是的,我有兩個啓用了USB調試的物理電話。 – andrepm

回答

2
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 !! 
+0

我已經嘗試過了,但是謝謝 – andrepm

+0

Heheheh,沒有。我的意思是說,在我問這裏之前,我嘗試了幾乎所有的方法:/ – andrepm

1

從我所收集你試圖同時運行測試,對不對?

如果是這樣,我沒有在帖子中看到線程的任何內容,並且沒有線程,您的測試將連續運行。

Selenium Grid不對相同類型的資源進行循環連接。它只是分配第一臺可用的機器。 I.E.如果測試'A'請求特定的瀏覽器/平臺/設備配置並運行到完成,那麼如果測試'B'出現並要求相同的配置,它將得到與測試A相同的機器。合理?

如果你想並行化你的測試,我會建議你檢查一下pytest &的xdist插件。這將爲你處理所有線程/多進程的東西。有趣的是,即使你寫了所有使用unittest的東西,你也不需要重寫所有的東西來使用pytest;只需在您現有的代碼上點pytest即可。

+0

Huuum,好的。但我怎麼說我想運行在兩個瀏覽器/平臺/設備上運行?一旦我的測試在第一臺可用機器上完成,硒應該在下一臺機器上進行我的測試。但是這沒有發生。 – andrepm

+0

你的兩臺機器是否相同?從你的文章中的圖片我不能告訴。如果它們相同,則必須將測試分爲兩個不同的套件。如果你的兩臺機器不相同,你需要兩個不同的測試套件,你需要不同的'desired_capabilities'。 *假設你正在使用pytest和xdist插件。 – willnx

+0

你的意思是像一個跑步者?在幾部手機上只能運行一個測試腳本是可能的? – andrepm