Selenium Webdriver 學習總結-Selenium Grid & Webdriver(九)

來源:互聯網
上載者:User

標籤:des   style   c   code   java   tar   


QQ群: 136924235

 論壇 : http://bbs.shareku.com

Google教程:https://code.google.com/p/selenium/wiki/Grid2

Hub / Node

系統要求:JDK、firefox、chrome、internetExplorer

所需工具:selenium-server-standalone-xxx.jar

:http://code.google.com/p/selenium/downloads/list

Start Hub

IP: 192.168.0.22

命令列啟動Hub:

     C:\>java -jare:\selenium-server-standalone-2.37.0.jar –role hub –port 4444

     選擇性參數:

l  -port (預設 4444)為預設hub所在伺服器(jetty)連接埠為4444,服務啟動之後,可以通過              http://localhost:4444/grid/console 訪問Grid Console已檢視各節點狀態

l  -timeout (預設 30 s),當某節點在指定時間未收到任何請求時,該節點會被釋放加入到其它隊列中,可以使Client不會一直處於掛起狀態

l  -maxSession (預設 5) ,在節點最大並行啟動並執行瀏覽器個數,這個不同於節點中瀏覽器的maxInstance

前者為最大啟動的瀏覽器個數,後者為同一版本瀏覽器最大執行個體數

使用Json配置Hub:

     C:\>java -jar selenium-server-standalone-2.37.0.jar-role hub -hubConfig hubconfig.json

     hubConfig.json如下:

         {

 "host": null,

 "port": 4444,

 "newSessionWaitTimeout": -1,

 "servlets" : [],

 "prioritizer": null,

 "capabilityMatcher":"org.openqa.grid.internal.utils.DefaultCapabilityMatcher",

 "throwOnCapabilityNotPresent": true,

 "nodePolling": 5000,

 

 "cleanUpCycle": 5000,

 "timeout": 60,

 "browserTimeout": 60,

 "maxSession": 5,

 "jettyMaxThreads":-1

}

配置逾時:

     為了維持測試回合完整性,在grid中提供了另外兩種逾時設定,如下:

              -timeout: 單位(秒),在啟動hub命令列參數中指定,當用戶端崩潰指定時間後,grid會回收所有資源

                  -browserTimeout:單位(秒),在啟動hub命令列參數中指定,當Node瀏覽器處於掛起狀態指定時間後,grid會回收所有資源

註:webdriver API中,webDriver.manage().timeouts()設定不同操作的逾時在grid中同樣生效;

                   在Hub中配置兩個參數值後,會對所有Node生效,當然也可以局部地在Node上配置(官方不推薦);

                   對於browserTimeout應該高於socket鎖逾時(45 s),另外,由於該逾時是最後防線,也應高於webDriver.manage().timeouts()指定的逾時時間

 

Start Node

IP: 192.168.0.143

命令列啟動節點:

     C:\>java -jar e:\selenium-server-standalone-2.30.0.jar-role node –hub http://192.168.0.22:4444/grid/register

註:預設情況下,Node預設連接埠為5555;

-hub參數指定Grid Hub接受節點註冊的地址;

為了相容Selenium1.0,-role的參數值可以使用(wd / rc),當使用node時可以接受webdriver和 RC兩者的串連執行個體

  命令列配置節點:

         預設情況,grid會啟動11個瀏覽器執行個體, 5 Firefox, 5 Chrome, 1 Internet Explorer.,最大並發執行測試數目為5,

         我們可以通過配置-browser參數來更改關於瀏覽器的預設配置,一旦更改將覆寫預設配置

    Example_1: 以下配置將在Linux環境下啟動5個Firefox3.6執行個體
    -browser browserName=firefox,version=3.6,maxInstances=5,platform=LINUX
    Example_2: 如果你的遠程機器有多個版本的Firefox或其他瀏覽器,可以使用如下配置
             -browser browserName=firefox,version=3.6,firefox_binary=/home/myhomedir/firefox36/firefox,maxInstances=3,platform=LINUX 
-browser browserName=firefox,version=4,firefox_binary=/home/myhomedir/firefox4/firefox,maxInstances=4,platform=LINUX
    註:如果參數中的value字串中包含空格,可以使用雙引號包裹字串。

使用JSon配置節點:

         C:\>java -jar e:\selenium-server-standalone-2.30.0.jar -role node -nodeConfige:\selenium\node.json

         Node.json如下:

{

           "capabilities":[

           {

              "browserName":"firefox",

              "maxInstances": 2,                          目前的版本瀏覽器執行個體化最大個數

                    "seleniumProtocol":"WebDriver"

           },

           {

      "browserName": "internet explorer",

      "maxInstances": 1,

      "seleniumProtocol": "WebDriver"

      }

           ],

           "configuration":

           {

         "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",

         "maxSession": 2,                          最大並存執行的測試工作

         "port": 5555,

         "host": 192.168.0.143,

         "register": true,

         "registerCycle": 5000,                                該節點向hub發出註冊請求的頻率,單位毫秒ms

         "hubPort": 4444,

         "hubHost": 192.168.0.22

           }

}


使用Grid運行測試

         對於WebDriver而言,你需要使用RemoteWebDriver和DesiredCapabilities對象來定義你將要在什麼平台下運行測試,例如瀏覽器,瀏覽器版本,作業系統,樣本如下

DesiredCapabilities capability =DesiredCapabilities.firefox();

capability.setBrowserName(“firefox” );  

capability.setPlatform(“LINUX”); 

capability.setVersion(“3.6”);

WebDriver driver = new RemoteWebDriver(newURL("http://localhost:4444/wd/hub"), capability);

 

以上指令碼將會匹配如下配置的節點

         -browser browserName=firefox,version=3.6,platform=LINUX

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.