我正在使用appium 1.1.16
和java-client-3.3.0.jar
在android设备上运行测试。尝试执行javascript
时出现错误,将不胜感激。
// 1。代码:初始化驱动程序:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android");
logger.info("Added capability: deviceName = Android");
capabilities.setCapability("platformName", "Android");
logger.info("Added capability: platformName = Android");
capabilities.setCapability("app", appFile.getAbsolutePath());
logger.info("Added capability: app = "+appFile.getAbsolutePath());
capabilities.setCapability("serial", deviceID);
logger.info("Added capability: serial = "+deviceID);
capabilities.setCapability("newCommandTimeout", "60");
/** initializing appium driver */
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
//driver = new SwipableWebDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
//driver = new RemoteWebDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
logger.info("Added Driver Timeout = "+timeout +" Sec. ");
// 2。代码:执行Java脚本:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(byLocator));
WebElement webelement = driver.findElement(byLocator);
((JavascriptExecutor)driver).executeScript("arguments[0].click()", webelement);
抛出异常:
org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'VDO60.local', ip: '172.16.0.53', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.7.0_79'
Session ID: b00c752f-fe5f-4774-8041-593a1b64fa1e
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{platform=LINUX, app=/Users/navneetsharma/Desktop/qaAutomation/qascripting/Vdopia_Automation/tc_data/sdk/android/VdopiaSDKSample_StandAlone/app/build/outputs/apk/app-debug.apk, javascriptEnabled=true, browserName=Android, networkConnectionEnabled=true, desired={newCommandTimeout=60, app=/Users/navneetsharma/Desktop/qaAutomation/qascripting/Vdopia_Automation/tc_data/sdk/android/VdopiaSDKSample_StandAlone/app/build/outputs/apk/app-debug.apk, platformName=Android, deviceName=Android, serial=4d0025b440ca90d5}, locationContextEnabled=false, newCommandTimeout=60, platformVersion=5.0, databaseEnabled=false, platformName=Android, deviceName=4d0025b440ca90d5, webStorageEnabled=false, serial=4d0025b440ca90d5, warnings={}, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:556)
at projects.sdk.lib.ObjectsHandler.clickElement(ObjectsHandler.java:47)
at projects.sdk.lib.ObjectsHandler.menuNavigation(ObjectsHandler.java:195)
at projects.sdk.lib.SDKPerformActions.performAction(SDKPerformActions.java:74)
at projects.sdk.lib.GetResults.getDeviceJsonResult(GetResults.java:167)
at projects.sdk.lib.GetResults.getResults(GetResults.java:76)
at projects.sdk.SDKAdServingTest.sdkTest(SDKAdServingTest.java:240)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
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.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:207)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:178)
最佳答案
根据链接-Appium & Webdriver (webdriverjs) - cannot execute javascript code
您可以尝试使用命令:“ safeExecute”方法,而不是“ execute”方法。