尝试在云设备上单击androidDriver元素。低于堆栈跟踪。
java.lang.NullPointerException在 org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:276) 在 org.openqa.selenium.remote.RemoteWebElement.isDisplayed(RemoteWebElement.java:317) 在browserStack.TestAppLaunch.launchApp(TestAppLaunch.java:23)处 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)位于 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498)在 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) 在org.testng.internal.Invoker.invokeMethod(Invoker.java:661)处 org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)在 org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)在 org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126) 在 org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) 在org.testng.TestRunner.privateRun(TestRunner.java:744)处 org.testng.TestRunner.run(TestRunner.java:602)在 org.testng.SuiteRunner.runTest(SuiteRunner.java:380)在 org.testng.SuiteRunner.access $ 000(SuiteRunner.java:39)在 org.testng.SuiteRunner $ SuiteWorker.run(SuiteRunner.java:414)在 org.testng.internal.thread.ThreadUtil $ 1.call(ThreadUtil.java:52)在 java.util.concurrent.FutureTask.run(FutureTask.java:266)在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 在 java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在java.lang.Thread.run(Thread.java:745)
public AndroidDriver<?> bsAndroidDriver;
@SuppressWarnings({ "unchecked", "rawtypes" })
@BeforeTest
@org.testng.annotations.Parameters(value = { "deviceName" })
public void startAndroidDriver(String deviceName) throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
JSONParser parser = new JSONParser();
JSONObject config = (JSONObject) parser.parse(new FileReader(Constants.TEST_BROWSER_STACK_MOBILE_PROPERTIES_FILE_PATH));
JSONObject devices = (JSONObject) config.get("devices");
String userName = (String) config.get("user");
String accessKey = (String) config.get("key");
Map<String, String> deviceCapabilities = (Map<String, String>) devices.get(deviceName);
Iterator<?> it = deviceCapabilities.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
capabilities.setCapability(pair.getKey().toString(), pair.getValue().toString());
}
Map<String, String> commonCapabilities = (Map<String, String>) config.get("androidCapabilities");
it = commonCapabilities.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
if (capabilities.getCapability(pair.getKey().toString()) == null) {
capabilities.setCapability(pair.getKey().toString(), pair.getValue().toString());
}
}
bsAndroidDriver = new AndroidDriver<>(new URL("http://" + userName + ":" + accessKey + "@" + config.get("server") + "/wd/hub"), capabilities);
bsAndroidDriver.findElement(By.xpath("xpath_of_obj_given")).click();
>-此步骤出错!
注意:应用程序已成功启动。而且xpath看起来还不错。在本地测试。此特殊测试在云android设备上运行。
使用过的Maven存储库-
selenium-java,3.14.0
testng,6.11
java-client 4.1.2