How to run chrome browser in grid using MAC as hub and Windows as Nod?

最后都变了- 提交于 2019-12-08 12:25:11

问题


Hub: MAC 64-bit Nod: Windows 32-bit

Unable to run chrome browser using Selinum grid MAC as hub and Windows as nod?

using below code i am getting an error (The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list Command duration or timeout: 668 milliseconds)

public void chromeWindows() throws MalformedURLException{

System.setProperty("webdriver.chrome.driver", "/Users/vinayakkhatate/Desktop/jar/chromedriver2");
ChromeOptions opt = new ChromeOptions();
opt.setBinary("C:/Users/user/AppData/Local/Google/Chrome/Application/chrome.exe");


DesiredCapabilities capabilies = DesiredCapabilities.chrome();
capabilies.setBrowserName("chrome");
capabilies.setPlatform(Platform.VISTA);


driver = new RemoteWebDriver(new URL("http://10.0.11.118:5566/wd/hub"), capabilies);
driver.get(baseUrl);
System.out.println(driver.getTitle());

driver.close();
driver.quit();

}

回答1:


I have solution to run Chrome browser from Mac machine to Windows Vista (download and save chromedriver in windows vista machine)

Start the hub in Mac with below command

java -jar selenium-server-standalone-2.33.0.jar -role hub

Start the node in windows with below command

java -jar selenium-server-standalone-2.33.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=5 -Dwebdriver.chrome.driver=pathtochromedriver\chromedriver.exe

Now write code in eclipse in Mac machine

DesiredCapabilities capabilies = DesiredCapabilities.chrome();
capabilies.setBrowserName("chrome");
capabilies.setPlatform(Platform.ANY);

driver = new RemoteWebDriver(new URL("http://<ip address of windows machine>:5555/wd/hub"), capabilies); 



回答2:


Actually, the chromedriver.exe has to be stored on the Windows node. I do it by creating subfolder /lib in my test folder where I store the chromedriver and all other selenium grid related stuff. Later on, when running the node, do it like this:

java -jar lib/selenium-server-standalone-2.28.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.chrome.driver=lib\chromedriver.exe 

especially note the -D switch:

-Dwebdriver.chrome.driver=lib\chromedriver.exe 

Thats how I set up the chromedriver.exe path. Notice the relative path, so I do not have to care really about where in absolute path the tool is running. Hope it helps

EDIT Obviously, the hub and node computers should be acessible by IP. For instance, my work PC has IP 10.131.7.11 in our internal network so if this would be the hub computer, then the node setup would be like this:

java -jar lib/selenium-server-standalone-2.28.0.jar -role node -hub http://10.131.7.11:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.chrome.driver=lib\chromedriver.exe

Please note that the localhost changed to IP of the hub. So next steps for you are:

  • Set up hub and node to be on same network and being accessible by IP adress
  • Run hub on the mac machine
  • Run node on the vista, pointing out to the IP adress of the hub
  • Cross your fingers :)
  • And try running the chrome again

EDIT2 This is how I run chrome:

  if (System.getProperty("os.name").contains("Windows")) {
        System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver.exe");
    } else {
        System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver");
    }

  capabilities = DesiredCapabilities.chrome();
  capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));

  driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilities);



回答3:


Start the hub in Mac with below command

java -jar selenium-server-standalone-2.33.0.jar -role hub

Start the node in windows with below command

java -jar selenium-server-standalone-2.33.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.chrome.driver=pathtochromedriver\chromedriver.exe 

Download chromedriver from below location

https://code.google.com/p/chromedriver/downloads/list

Now intialize driver instance with below logic

System.setProperty("webdriver.chrome.driver", "/Users/test/chromedriver");
DesiredCapabilities dc=new DesiredCapabilities();
dc.setBrowserName("chrome");
dc.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc);
driver.get(Constants.SERVER_URL_NAME);


来源:https://stackoverflow.com/questions/17550687/how-to-run-chrome-browser-in-grid-using-mac-as-hub-and-windows-as-nod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!