我正在尝试在 eclipse/java 中创建一个项目以进行硒测试。
我在 Windows 机器上执行此操作,这也是我的硒网格中心。
我想在远程机器上运行我的测试,它是 mac。
在我的项目中,当我像这样设置 webdriver 时:
System.setProperty("webdriver.chromeDriver.driver",
"C:\\SeleniumGrid\\chromeDriver\\chromedriver.exe"
该路径应该指向我的遥控器/mac上的chromedriver,对吧?
mac已经安装了chrome。我在这里找到了那台机器上的 chromedriver:/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
但是当我这样设置时:
System.setProperty("webdriver.chromeDriver.driver",
"/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome");
ChromeOptions options = new ChromeOptions();
cap.setCapability(ChromeOptions.CAPABILITY, options);
cap = DesiredCapabilities.chrome();
cap.setBrowserName("chrome");
cap.setPlatform(Platform.MAC);
cap.setJavascriptEnabled(true);
newDriver = new RemoteWebDriver(new URL(
"http://999.999.9.99:9999/wd/hub"), cap);
我在这一行得到一个空指针异常:
cap.setCapability(ChromeOptions.CAPABILITY, options);
不知道我在这里做错了什么。对不起,我是硒的新手。任何想法将不胜感激。
编辑:这是堆栈跟踪
[TestNG] Running:
[ThreadUtil] Starting executor timeOut:2147483647ms workers:1 threadPoolSize:3
FAILED CONFIGURATION: @BeforeClass setUp("chrome")
java.lang.NullPointerException
at selenium.helper.WebUtils.setUpRemoteDriver(WebUtils.java:74)
at selenium.testNG.TestNikeCareerSearch.setUp(TestNikeCareerSearch.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.access$0(SuiteRunner.java:333)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368)
at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
SKIPPED CONFIGURATION: @AfterClass tearDown