简体   繁体   中英

Appium - Android Hybrid app

I see console 'driver null' error after executing test script

Script:

capabilities.setCapability("appium-version", "1.4.0");
System.out.println("<<< Detects android device / emulator >>>");
capabilities.setCapability("deviceName","New1");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("autoWebview","true");
capabilities.setCapability("automationName","Appium");
//capabilities.setCapability("newCommandTimeout", "180");
capabilities.setCapability("app", "com.android.launcher");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appActivity", "com.sciit.mat");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);

Console Error:

<<< Detects android device / emulator >>>
<<< Utlizes remote webdriver >>>
Driver in App screen : null
FAILED: sampletestmethod
java.lang.NoSuchMethodError: org.openqa.selenium.remote.ErrorHandler.<init>(Lorg/openqa/selenium/remote/ErrorCodes;Z)V
at io.appium.java_client.AppiumDriver.<clinit>(AppiumDriver.java:46)
at com.sci.matapp.sampleScript1.TestScript1.sampletestmethod(TestScript1.java:39)
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:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:773)
at org.testng.TestRunner.run(TestRunner.java:623)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
at org.testng.TestNG.run(TestNG.java:1018)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:112)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:176)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================

===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.XMLReporter@1064425: 521 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@6ea0c6: 508 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 131 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@899482: 746 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@d17bee: 551 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@16432db: 81 ms

NOTE: I have utilized below jar files:

  • android,
  • selenium-java-2.47.1

  • java client2.2.0

  • selenium-java-client-driver-1.0.1

  • selenium-server-standalone-2.47.1

  • selendroid-standalone-0.10.0-with-dependencies

Can some one help if i miss anything. Thanks,

You get classNotFoundException/NoSuchMethodError when there is version clash between jar files. Also looking at exception, it is giving error on AppiumDriver.

  • selendroid-client-0.16.0.jar
  • selendroid-standalone-0.16.0.-with-dependancies.jar
  • selenium-server-standalone-2.45.0.jar or greater
  • selenium-java-2.44.0
  • Java-client-3.1.0 (1.0.1 is too old)

Edit

  • httpclient-*.jar
  • httocore-*.jar

Make sure you use latest and same versions for httpclient & httpcore. Try to use latest versions of all jars to avoid mainly NoSuchMethodError

Edit2 for element not found in given context You need to explicitly switch to webview so that appium can lookout element. try getting all webviews as below:

String nr = driver.getWindowHandles().toString();
System.out.print(nr); 

IT will return you an array similar to :

[NATIVE_APP, WEBVIEW_1, WEBVIEW_0]

Now switch to WEBVIEW_1 as:

driver.switchTo().window("WEBVIEW_1");

Please note: Appium is not good in switching between multiple webviews. (Atleast I faced that issue.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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