grid原理圖java
安裝java jdk 並配置好環境的條件下node
1.本機啓動hub ( win 7 64bit FF 28.0)web
java -jar selenium-server-standalone-2.41.0.jar -role hub -maxSession 40 -port 4444瀏覽器
2.另一臺啓動node (win 7 32bit ff 24.5.0),防火牆須要關閉測試
java -jar selenium-server-standalone-2.41.0.jar -role node \
-hub http://{grid_server}:4444/grid/register -port 5555 \
-firefoxProfileTemplate llinotes.profile -maxSession 20 \
-browser "browserName=firefox,version=28.0,platform=WINDOWS,maxInstances"ui
在遠程機器顯示 couldn't register this node,this
將node輸入命令改爲以下:google
java -jar selenium-server-standalone-2.41.0.jar -role webdriver \spa
-hub http://192.168.1.9:4444/grid/register -port 5555 \firefox
-firefoxProfileTemplate llinotes.profile -maxSession 20 \
-browser "browserName=firefox,version=28.0,platform=WINDOWS,maxInstances"
register成功
run hub機器上的腳本
[Test] public void Test() { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities = DesiredCapabilities.Firefox(); capabilities.SetCapability(CapabilityType.BrowserName, "firefox"); capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows)); capabilities.SetCapability(CapabilityType.Version, "24.5.0"); driver = new RemoteWebDriver(new Uri("nodeUrl/wd/hub"), capabilities); baseURL = "https://www.google.com/"; verificationErrors = new StringBuilder(); driver.Navigate().GoToUrl(baseURL); driver.FindElement(By.Id("lst-ib")).SendKeys("selenium"); driver.FindElement(By.Name("btnK")).Click(); }
能夠打開Node FF瀏覽器並進行操做。Done
hub機器顯示信息:
node機器顯示:
接着又遇到一個問題:若是我要在不一樣的機器上運行hub上的測試,應該怎麼作呢
我試着在另一臺node機器register node(記得關閉防火牆)
在hub機器添加以下代碼,將nodeUrl改爲其餘機器上的ip,運行全部測試,按照測試順序啓動不一樣機器的瀏覽器
[Test] public void Test() { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities = DesiredCapabilities.Firefox(); capabilities.SetCapability(CapabilityType.BrowserName, "firefox"); capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows)); capabilities.SetCapability(CapabilityType.Version, "28.0"); driver = new RemoteWebDriver(new Uri("nodeUrl2/wd/hub"), capabilities); baseURL = "https://www.google.com/"; verificationErrors = new StringBuilder(); driver.Navigate().GoToUrl(baseURL); driver.FindElement(By.Id("lst-ib")).SendKeys("selenium"); driver.FindElement(By.Name("btnK")).Click(); }
爲了省事,我想把那些命令直接用cmd批處理來執行
新建.txt文件,輸入以下內容:
cd selenium-server-standalone-2.41.0.jar路徑
java -jar selenium-server-standalone-2.41.0.jar -role hub -maxSession 40 -port 4444
另存爲hubstart.bat,雙擊就能直接運行這個命令啓動hub