0

I just switched from HtmlUnit to Selendroid, because HtmlUnit doesn't work under Android. But I really don't understand selenium/selendroid.

So I got this code:

WebDriver driver = new EdgeDriver();
driver.get("www.google.com");

And this Exception, which points on the first line:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.muco.villagedefender, PID: 10430
java.lang.NoClassDefFoundError: org.openqa.selenium.edge.EdgeDriverService
  at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:98)
  at com.example.muco.villagedefender.MainActivity$2.onClick(MainActivity.java:85)
  at android.view.View.performClick(View.java:4633)
  at android.widget.CompoundButton.performClick(CompoundButton.java:104)
  at android.view.View$PerformClick.run(View.java:19330)
  at android.os.Handler.handleCallback(Handler.java:733)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:157)
  at android.app.ActivityThread.main(ActivityThread.java:5356)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
  at dalvik.system.NativeStart.main(Native Method)

On HtmlUnit I just did this and everthing was fine:

final WebClient webClient = new WebClient(BrowserVersion.EDGE);
final HtmlPage page= webClient.getPage("www.google.com");

So what is wrong?

The other question: Is there no Selenium/Selendroid doc? I can't find anything, only this.

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
Muco
  • 53
  • 11

1 Answers1

0

Check your transitive dependencies and make sure you are including:

org.seleniumhq.selenium / selenium-edge-driver

which - for 2.48.0 and later - should be pulled in automatically by:

org.seleniumhq.selenium / selenium-java

Also check that the versions match.

Finally, the docs suggest you should consider:

EdgeDriverService service = new EdgeDriverService.Builder()
     .usingDriverExecutable(new File("path/to/my/MicrosoftWebDriver.exe"))
     .usingAnyFreePort()
     .build();
service.start();

WebDriver driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.edge());
driver.get("www.google.com");

At the moment you're not configuring the EdgeDriver service at all.

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
  • Added : `compile 'org.seleniumhq.selenium:selenium-java:2.48.0' compile 'org.seleniumhq.selenium:selenium-edge-driver:2.48.0'` but now i get this : `Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/commons/io/ByteOrderMark.class` – Muco Feb 29 '16 at 02:33
  • Sounds like this is all about a conflict in your Gradle dependencies. Can you post full list of deps? Also use latest Selenium (2.52) just in case. – Andrew Regan Feb 29 '16 at 07:30
  • my [build.gradle](http://i.stack.imgur.com/CR7D7.png) and the [External Libs](http://i.stack.imgur.com/w4e5g.png). I wanted to see if selenium works on android, but i don't know how to delete these afterwards. – Muco Feb 29 '16 at 11:47
  • Are you using Gradle 2.1? https://github.com/stephanenicolas/robospice/issues/365 suggests there's an underlying issue with Gradle and commons-io, so it seems you may have to exclude it. This is annoying, though it's Gradle vs Android, nothing to do with Selenium, or that invalidates Selenium/Selendroid running on Android. – Andrew Regan Feb 29 '16 at 12:07
  • I'm using 2.8 . Are these dependencies the right ones? Because it loads for example the **htmlunit** lib, which is not supported by android. And the String contains **seleniumhq**, i need something like **org.openqa.selenium** because the import of selendroid looks like this, am i wrong? – Muco Feb 29 '16 at 13:03
  • Yes, the `groupId` is correct, it doesn't have to match package. HtmlUnit driver is included in main release, and that'll pull in htmlunit, though you don't care if you don't use it. BTW You might as well try 2.52.0 rather than old 2.48.0. – Andrew Regan Feb 29 '16 at 13:20
  • I changed it now to 2.52.0 . I'm getting this error: `Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/thoughtworks/selenium/**BrowserConfigurationOptions.class**` . Everytime i run my project, the class changes and **gradlew clean** doesnt help. My build.gradle looks like [this](http://i.stack.imgur.com/gpaPE.png) at the moment. – Muco Feb 29 '16 at 13:30
  • Sorry, I don't know Gradle well enough to help you dig deeper into your build problem. It probably wouldn't take long to create a simple Maven project and see if that's better? – Andrew Regan Feb 29 '16 at 22:19
  • Nevermind, really thanks for your help, i give selendroid up at this point. – Muco Mar 01 '16 at 13:07
  • @Muco Question. Is there a specific reason you have to use the edge driver? Just wondering. Wouldn't it be better just to use the selendroid driver? What did you want to test? An hybrid app or Mobile browsers? – Madis Kangro Mar 14 '16 at 09:57
  • @MadisKangro Yes. Before selendroid, i used the HtmlUnit. All the other drivers cried about the sourcecode of the website, which i wanted to inspect. I dont want to test anything. I need some live-information from the page(uses tons of javascript). With HtmlUnit everything was already done, but i dont understand selenium/selendroid. – Muco Mar 14 '16 at 11:43
  • @Muco I'm still confused. I mean you can use selendroid to gather live data from a website, but I'm having troubles trying to figure out your workflow. Let me ask a couple of questions. 1. Why do you want to use selendroid? Selendroid is ment for android UI automation. HtmlUnit would be much faster if you want to get some information, hence the question. Why would you want to run it on selendroid. (You can do it, it just isn't the best in terms of performance) 2. Do you want to use the live data right away somewhere else? – Madis Kangro Mar 15 '16 at 12:42
  • @MadisKangro 1. I dont actually want to, but HtmlUnit doesnt work under android as i wrote. My code in HtmlUnit is pretty done. 2. I will use the data in my app. – Muco Mar 15 '16 at 18:49
  • @Muco What do you plan to do with the app? I think that selendroid won't work like how you want it to work. The implementation of selendroid is quite different. – Madis Kangro Mar 17 '16 at 07:28
  • @MadisKangro i want to run the function, which gets the live-data from the website, after a specific time and use the data afterwards – Muco Mar 17 '16 at 08:03
  • @Muco I would look into something else than selendroid. Selendroids idea is completely different what you want to achieve.Selendroid is a test automation framework which drives off the UI of Android native and hybrid applications. I think what you want is completely different. I'm assuming the live-data you are trying to gather isn't from your website? – Madis Kangro Mar 17 '16 at 08:53
  • @MadisKangro no its from another website. – Muco Mar 17 '16 at 13:42