简体   繁体   English

无法使用Selenium网格在Mac OSX上启动Chrome

[英]Unable to launch Chrome on Mac OSX using Selenium grid

I am trying to perform automation testing using Selenium & Java on MAC Sierra but I keep getting the following error when I run the testng.xml : 我正在尝试在MAC Sierra上使用Selenium和Java执行自动化测试,但是在运行testng.xml时,我testng.xml收到以下错误testng.xml

org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities [{browserName=chrome, chromeOptions={args=[--start-maximized, --disable-web-security], extensions=[], prefs={credentials_enable_service=false, profile.password_manager_enabled=false}}, version=, platform=macOS 10.12}] Command duration or timeout: 61 milliseconds org.openqa.selenium.WebDriverException:转发新会话时出错:找不到功能[{browserName = chrome,chromeOptions = {args = [-start-maximized,--disable-web-security],extensions = [],prefs = {credentials_enable_service = false,profile.password_manager_enabled = false}},版本=,platform = macOS 10.12}]命令持续时间或超时:61毫秒

The hub & node are running on the same Mac computer. 集线器和节点在同一台Mac计算机上运行。 Here is the command line to launch node: 这是启动节点的命令行:

java -jar selenium-server-standalone-3.4.0.jar -role node -hub http://localhost:4444/grid/register 

Here is the sample code which is running absolutely fine on Windows 10: 这是在Windows 10上可以正常运行的示例代码:

capabilities = DesiredCapabilities.chrome();
System.setProperty("webdriver.chrome.driver", "/Users/varun/webautomation/Executables/chromedriver");
capabilities.setBrowserName("chrome");
getPlatformCapabilities(platform);
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-web-security");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new RemoteWebDriver(new URL(remoteAddress), capabilities);

Can anyone please help me out? 有人可以帮我吗? I have searched posts but cannot seem to find the solution. 我搜索了帖子,但似乎找不到解决方法。 The last line in the terminal window running the hub is: 终端窗口中运行集线器的最后一行是:

Got a request to create a new session: Capabilities [{browserName=chrome, chromeOptions={args=[--start-maximized, --disable-web-security], extensions=[], prefs={credentials_enable_service=false, profile.password_manager_enabled=false}}, version=, platform=macOS 10.12}] 收到了创建新会话的请求:功能[{browserName = chrome,chromeOptions = {args = [-start-maximized,--disable-web-security],extensions = [],prefs = {credentials_enable_service = false,profile .password_manager_enabled = false}},版本=,平台= macOS 10.12}]

By default, selenium grid uses port 4444 for hub and port 5555 for node. 默认情况下,Selenium网格将端口4444用于集线器并将端口5555用于节点。 It may be the port forwarding issue. 这可能是端口转发问题。 Is you system allows port 4444 and 5555. If it it is not enabled add it in your firewall for TCP/IP and UDP protocols. 系统是否允许端口4444和5555。如果未启用,则将其添加到防火墙中以用于TCP / IP和UDP协议。 Both ports are enabled by default in Windows. Windows默认情况下启用两个端口。 So that you are not getting any issues there. 这样您就不会遇到任何问题。

So I figured out a non-perfect solutuion which is working for now. 因此,我想出了一个目前尚无法解决的完美解决方案。 I had to remove the code related to passing arguments & chrome options which was the source of the problem as this is not working on Mac OSX. 我必须删除与传递参数和chrome选项相关的代码,这是问题的根源,因为这在Mac OSX上不起作用。 My final code was: 我的最终代码是:

capabilities = DesiredCapabilities.chrome();
System.setProperty("webdriver.chrome.driver","/Users/varun/webautomation/Executables/chromedriver");
capabilities.setBrowserName("chrome");
driver = new RemoteWebDriver(new URL(remoteAddress), capabilities);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM