第一步:准备2台电脑,且2台电脑都安装好jdk,都准备好selenium-server-standalone-2.40.0.jar,IEDriver, ChromeDriver等工具,注意chrome版本与chromedriver需要匹配,详见我的另一篇博客:http://www.cnblogs.com/cherrysu/p/7815245.html
第二步:其中一台电脑作为hub,也就是老大,另一台作为node,也就是小弟,两台电脑一定要能ping通。
第三步:hub机上新建HUB.bat, 内容参考:
java -jar C:\\Software\\selenium\\selenium-server-standalone-2.40.0.jar -role hub
其中selenium-server-standalone-2.40.0.jar 的版本和路径需要改成自己的。
第四步:node机上新建node.bat,内容参考:
java -Dwebdriver.chrome.driver="C:\\software\\chromedriver.exe" -Dwebdriver.ie.driver="C:\\software\\IEDriverServer-x64.exe" -jar C:\\libs\\selenium-server-standalone-2.40.0.jar -role node -nodeConfig node.json -hub http://hub机IP:4444/grid/register
其中 chromedriver.exe,IEDriverServer-x64.exe,standalone都需要改为node机上对应的地址, -nodeConfig node.json可以修改node机上的grid参数,具体内容参考:
{
"capabilities": [
{
"browserName": "chrome",
"maxInstances": 5,
"platform": "WINDOWS",
"version":"51"
},
{
"browserName": "internet explorer",
"maxInstances": 2,
"platform": "WINDOWS",
"webdriver.ie.driver": "IEDriverServer.exe"
}
],
"configuration": {
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "http://192.168.84.209:4444"
}
}
第五步:先运行hub.bat,在运行node.bat,在hub机上打开 http://localhost:4444/grid/console# 查看链接状态
第六步:编写python脚本