Tuesday, 19 January 2016

Setting up Appium with Android Studio



Appium is widely used automation tool for Mobile Applications and this post will help you to setup the Appium with Android Studio including writing and executing your first test case using Appium.If you are not familiar with android studio then also this post will definitely help you to to setup Appium. I hope this post helps you to setup your Appium Test Environment quickly. If you face any issues do post your questions. Let is get started with how to install Appium and configure in Android Studio.This is very easy step by step tutorial for appium setup in android studio.





  1. Download -
    1. Android Studio
    2. Appium Jar files for Java
    3. Latest Appium Client Library
    4. Appium Server 
    5. Install Java
  2. Install Android Studio please follow the steps given in the link to install android studio step by step on windows machine click here
  3. After installation of android studio ,open android studio and create a new project - How to create android project?
4. Add the downloaded Appium jars into your project - click on project -> click on app->copy all the jars in lib. Select the copied jars except Selenium, Java client and Junit Jar ,then right click on it and click on "Add as Library".

5. Click on build.gradle in app you will see all the libs added like below screenshot add junit:4.12.Sync the project or Re-build the project. It should show "Build Successful Message"

Build.gradle code for appium setup
Appium Gradle Dependency


6. Now you are ready to write your first test case - right click on the package and click on "Create Java Class". Copy given test case sample.

7. Running the Test case-

  • Click on build variant
  • Select Unit Testing
  • Start  the appium server with Specific port "4444"click here
  • Connect device with USB debugging on or start an emulator.
  • Right click on the test class and click on "Run"
 

import java.net.MalformedURLException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;



public class WaitTests {

 WebDriver driver;

 @Before
 public void setUp() throws MalformedURLException {
  // Created object of DesiredCapabilities class.
  DesiredCapabilities capabilities = new DesiredCapabilities();

  // Set android deviceName desired capability. Set your device name.
  capabilities.setCapability("deviceName", "XT1562");

  // Set BROWSER_NAME desired capability. It's Android in our case here.
  capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");

  // Set android VERSION desired capability. Set your mobile device's OS version.
  capabilities.setCapability(CapabilityType.VERSION, "6.0.1");

  // Set android platformName desired capability. It's Android in our case here.
  capabilities.setCapability("platformName", "Android");

  // Set android appPackage desired capability. It is
  // com.android.calculator2 for calculator application.
  // Set your application's appPackage if you are using any other app.
  capabilities.setCapability("appPackage", "com.android.calculator2");

  // Set android appActivity desired capability. It is
  // com.android.calculator2.Calculator for calculator application.
  // Set your application's appPackage if you are using any other app.
  capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");

  // Created object of RemoteWebDriver will all set capabilities.
  // Set appium server address and port number in URL string.
  // It will launch calculator app in android device.
  driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
  driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
  
  
 }

 @Test
 public void testFirstCalculator() {
  
 
  // Click on DELETE/CLR button to clear result text box before running test.
  driver.findElements(By.xpath("//android.widget.Button")).get(0).click();

  // Click on number 2 button.
  driver.findElement(By.name("7")).click();

 driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); 
}

@After
 public void End() {
  driver.quit();
 }
}

 
 
Once your Setup is Complete Learn more About Appium with this simple Step by Step
APPIUM TUTORIAL 
Note - Learn More About Android Studio Basic Features and Functionality HERE .
 
 Please share your feedback in comments section below and join QA-Automated 
for latest post updates.Happy Testing !!!


126 comments:

  1. you have mentioned
    Add the Appium jars into your project - click on project -> click on app->copy all the jars in lib. Select the copied jars except Selenium, Java client and Junit Jar ,then right click on it and click on "Add as Library".

    But I do not see "lib" folder in Android Studio's project explorer, though I see in Windows Folder Structure.

    And also I do not see any option as Add As Library in any context menu, do we just need to copy paste all jar files in lib folder in Windows Explorer ??

    ReplyDelete
    Replies
    1. click on teh project structure then on top left corner there is drop down -> check if android is selected then change and select "project" -> then click on app-> libs and then you can right click on libs and copy the jar files.

      Delete
    2. Hi there,

      When I click Project Structure, I do get these drop down menus when I click Project. I could be using a more updated version of Android studio then you?

      Instead of being able to upload the jar files, I added them via app -> dependencies through Maven. Would this still be sufficient to run the test code above? When i create a test class via src -> main -> java nothing can be resolved.

      Any thoughts on this?

      Delete
    3. In your project structure search lib folder add the file there and as well as in gradle dependencies then only you can see results.

      Delete
  2. When I copy the above code, getting error at the below mentioned lines. Let us know the used interfaces for better understaning. Thanks!

    ReplyDelete
  3. service.start();
    reader.readFile();

    ReplyDelete
  4. Remove these two lines as these I added to start Appium server using java code . This tutorial is also there ar my blog -http://qaautomated.blogspot.in/2016/01/how-to-start-appium-server-using-java.html

    ReplyDelete
  5. Hi Anuja,

    Which are the packages i should import in my class?

    ReplyDelete
  6. import org.junit.After;
    import org.junit.AfterClass;
    import org.junit.Before;
    import org.junit.BeforeClass;
    import org.junit.Test;
    import org.junit.runner.JUnitCore;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import java.io.IOException;
    import java.net.URL;
    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.MobileElement;
    import io.appium.java_client.remote.MobileCapabilityType;

    ReplyDelete
  7. thanks for your tutorial, in your source code Do I need to place the sample.apk at c://apk// ,
    but I don't have the file "sample.apk".
    Looking forward to your answer . Thank you.

    ReplyDelete
  8. Thanks for reading .
    You need to place path of your apk which you want to test

    ReplyDelete
  9. I get an unresolved symbol error at "driver = new AndroidDriver...." I did some digging and it seems that AndroidDriver is part of org.openqa.selenium, but it does not show up in my org.openqa.selenium package.

    ReplyDelete
    Replies
    1. AndroidDriver is the unresolved symbol.

      Delete
    2. Check that you added java-client-3.2.0.jar which you can download from the link I have given in the post.becasue AndroidDriver is part of this package
      import io.appium.java_client.android.AndroidDriver;

      Delete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Hii Anuja i got error while testing
    Test running failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
    Empty test suite.
    PLz help me
    Thank U

    ReplyDelete
  12. There can be different reasons to get this error -
    1. create your test case in scr-> main-> java
    2. select build variant as Unit Test
    3. If u r running in real device check USB debugging is on and connected as file transfer

    ReplyDelete
  13. Hi Anuja,

    Could you please let me know can we configure the TestNG for this?
    If yes please provide the steps to doing that.

    Thank you!
    - Manish B

    ReplyDelete
    Replies
    1. Hi Manish,
      We can configure TestNG for this and I have addes a blog post so that you can do it . please check out this link - http://qaautomated.blogspot.in/2016/03/appium-setup-in-android-studio-with.html
      Regards,
      Anuja

      Delete
  14. Hi Anuja,
    The 2nd link in the download section, Appium jar files in the google drive - From where were these files downloaded?

    ReplyDelete
    Replies
    1. I googled and downloaded the necessary files.

      Delete
  15. Hi Anuja,
    This document is very well.
    I Followed this same steps but
    In test case1 shows compile error with
    findElementByID and
    Asser

    ReplyDelete
  16. Hi Anuja,
    This document is very well.
    I Followed this same steps but
    In test case1 shows compile error with
    findElementByID and
    Asser

    ReplyDelete
    Replies
    1. Hi sravanthi, you can click on the error and import the required class.If you are not getting the imports then check your dependencies and libs

      Delete
    2. I tried ,But imports also not working for
      this below lines
      driver=new AndroidDriver("http://127.0.0.1:4444/wd/hub",cap);(e:connot resolve constructor)
      driver.findElementByID("Example").click();(e.cannot resolve method findElementByID) Asser.assertTrue(driver.findElementByID("Example").isDisplayed));
      (e:cannot resolve symbol Asser)

      Delete
    3. hi there, I have the same problem...any solution for this ? thanks in advance.

      Delete
    4. Yes I am having same problem. If u got the solution for this. Please tell me

      Delete
    5. If your imports are not working check ur jars in lib folder and build.gradle. If anything is missing you will not get imports

      Delete
    6. Hi Anuja, thanks for the tutorial, but I'm getting the same errors.

      I have imported the library and compile gradle but nothing, I always get the same error as Sravanthi M

      Delete
    7. driver=new AndroidDriver(cap);(constructor have only one parameter DesiredCapabilities)
      driver.findElementById("Example").click();(Change method name findElementByID() to findElementById) Assert.assertTrue(driver.findElementById("Example").isDisplayed));
      (There is no sysmbol named Asser, Change it to Assert)

      Delete
    8. Hi, this solved my errors. thanks

      Delete
  17. I'm not able to solve this error since last four hours. please guide to remove it

    I'm getting this in console

    java.lang.NoSuchFieldError: INSTANCE
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.(SSLConnectionSocketFactory.java:144)
    at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:71)
    at org.openqa.selenium.remote.internal.HttpClientFactory.(HttpClientFactory.java:57)
    at org.openqa.selenium.remote.internal.HttpClientFactory.(HttpClientFactory.java:60)
    at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:251)
    at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.(ApacheHttpClient.java:228)
    at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:89)
    at org.openqa.selenium.remote.HttpCommandExecutor.(HttpCommandExecutor.java:63)
    at io.appium.java_client.remote.AppiumCommandExecutor.(AppiumCommandExecutor.java:36)
    at io.appium.java_client.AppiumDriver.(AppiumDriver.java:167)
    at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:69)
    at appiumtest.cogitate.us.appiumtest.ExampleUnitTest.testCaseSetup(ExampleUnitTest.java:37)

    Process finished with exit code 0

    ReplyDelete
    Replies
    1. Did you got the solution for this error? I am getting the same error.

      Delete
  18. do we require seperate android sdk or android studio will fulfill the purpose..
    becaose wile running my first appium test case on ubuntu using android studio there is an error android_home is not set.

    ReplyDelete
    Replies
    1. android studio is enough you can download android sdk with sdk manager inside android studio . You need to set Android_Home to execute anything using android studio

      Delete
  19. Thanks for the article. Do we have some build dependency file for including the Appium Jar files and Appium Client Library - instead of manually downloading them?

    ReplyDelete
    Replies
    1. I dnt think so we have it. I will still explore to know more.Share with us if you find out.

      Delete
  20. This is great initiative. Thanks for the article and answering questions.
    Can you create this project and check in to GitHub, so that other users can import it in to Android Studio. This way, most people can be successful in getting Appuim environment in Android Studio, quickly and easily. Also, some one can even fix/update GitHub in future - to keep it current.

    ReplyDelete
    Replies
    1. Thanks for your comments I will try to do it :-)

      Delete
  21. Hi,

    How to copy all the jar files from drive? I am new to this automation so pls help me.

    ReplyDelete
    Replies
    1. Hi, Just download the jar files from the drive . Then select all and copy it. Then go to android studio project -> app> lib folder and paste all files.
      Regards,
      Anuja

      Delete
  22. Replies
    1. Add below code in app -> build.gradle
      packagingOptions {
      exclude 'META-INF/DEPENDENCIES.txt'
      exclude 'META-INF/LICENSE.txt'
      exclude 'META-INF/NOTICE.txt'
      exclude 'META-INF/NOTICE'
      exclude 'META-INF/LICENSE'
      exclude 'META-INF/DEPENDENCIES'
      exclude 'META-INF/notice.txt'
      exclude 'META-INF/license.txt'
      exclude 'META-INF/dependencies.txt'
      exclude 'META-INF/LGPL2.1'
      }

      Delete
  23. Hi,
    I've coped all jar files and import properly and even if getting below errors..
    driver=new AndroidDriver("http://127.0.0.1:4444/wd/hub",cap); error as Cannot resolve constructor 'AndroidDriver(java.lang.String, org.openqa.selenium.remote.DesiredCapabilities)'

    and Cannot resolve symbol 'Asser' ...

    It would appreciate if you help me on this

    Thanks
    Srihari

    ReplyDelete
    Replies
    1. you can check whether yoy have imported required packages -
      import org.junit.After;
      import org.junit.AfterClass;
      import org.junit.Before;
      import org.junit.BeforeClass;
      import org.junit.Test;
      import org.junit.runner.JUnitCore;
      import org.openqa.selenium.WebElement;
      import org.openqa.selenium.remote.DesiredCapabilities;
      import java.io.IOException;
      import java.net.URL;
      import io.appium.java_client.AppiumDriver;
      import io.appium.java_client.MobileElement;
      import io.appium.java_client.remote.MobileCapabilityType;

      Delete
    2. I also had the same issue and I found that using it like this can solve the issue - driver=new AndroidDriver (new URL("http://127.0.0.1:4444/wd/hub"), cap);

      Delete
    3. Notice that "import java.net.URL;" would be needed.

      Delete
  24. This comment has been removed by a blog administrator.

    ReplyDelete
  25. I am not able to change my build variant and I am getting java.lang.NoClassDefFoundError: com/sun/jna/platform/win32/Kernel32 error.

    I have posted a question on stackoverflow here http://stackoverflow.com/questions/40396108/calling-stop-on-appiumdriverlocalservice-fails.

    This happens when I try to stop the server.

    ReplyDelete
    Replies
    1. You can share build.gradle dependency section with me. so that I can get some more clarity.

      Delete
  26. Getting an exception at

    driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), (Capabilities) capabilities);

    as follows-

    java.lang.ClassCastException: org.openqa.selenium.remote.DesiredCapabilities cannot be cast to org.openqa.selenium.Capabilities

    Any help?

    ReplyDelete
  27. Thanks for beautiful tutorial. I found this tutorial very late but BINGO :). But it's clear my concept with beautiful explanation

    ReplyDelete
    Replies
    1. I am glad that it helped you. Thanks for visiting.Follow me on FB or G+ to get latest post updates. :-)

      Delete
  28. Thanks Anuja. The videos were helpful.

    ReplyDelete
  29. hi getting the below error in appium


    info: [debug] Error: 'java -version' failed. Error: spawn ENOENT
    > at [object Object]. (C:\Program Files\Appium\node_modules\appium\lib\devices\android\android-common.js:1057:17)
    > at exithandler (child_process.js:633:7)
    > at ChildProcess.errorhandler (child_process.js:649:5)
    > at ChildProcess.EventEmitter.emit (events.js:95:17)
    > at Process.ChildProcess._handle.onexit (child_process.js:795:12)
    > info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: 'java -version' failed. Error: spawn ENOENT)","origValue":"'java -version' failed. Error: spawn ENOENT"},"sessionId":null}
    > info: <-- POST /wd/hub/session 500 33.932 ms - 208

    ReplyDelete
  30. Wow, very concise and effective tutorial on Appium with Android Studio. It saved my day.

    Thank you !!

    ReplyDelete
    Replies
    1. Hey, thanks for stopping by at my blog. and I a glad it saved your day. stay connected for more tutorials

      Delete
  31. He thanks for stopping by at my blog. and I a glad it saved your day. stay connected for more tutorials

    ReplyDelete
  32. Hello
    please upload the vedio from another account it was really helpful.

    ReplyDelete
    Replies
    1. Hi,
      I have decided to wait for 1 day for response as I have not violated any terms or else will update from other account.

      Regards,
      Anuja

      Delete
  33. This comment has been removed by the author.

    ReplyDelete
  34. Thanks:)
    I have one more query how to automate the toast message in android? please suggest.

    ReplyDelete
  35. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)

    ReplyDelete
  36. org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Requested a new session but one was in progress) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 0 milliseconds
    Build info: version: 'unknown', revision: '86a5d70', time: '2017-02-16 07:47:51 -0800'
    System info: host: 'LENOVO-PC', ip: '192.168.0.106', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_76-release'
    Driver info: driver.version: RemoteWebDriver

    ReplyDelete
  37. at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:161)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:64)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:128)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:155)
    at com.example.lenovo.android.Cbsk.setUp(Cbsk.java:55)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

    ReplyDelete
  38. can you say how to clear this issue

    ReplyDelete
    Replies
    1. Hi, Can you try with started Appium server on different port number.
      make sure you have latest appium server and appium java client.

      Regards,
      Anuja

      Delete
    2. me too had the same issue! solved it! thanks :))))))

      Delete
  39. Hi, I have some problems when i created a project in android studi, The gradle showed this error:
    Error:(41, 17) Failed to resolve: junit:junit:4.12
    Error:Failed to resolve: com.squareup:javawriter:2.1.1
    Error:Failed to resolve: javax.inject:javax.inject:1
    Error:Failed to resolve: javax.annotation:javax.annotation-api:1.2
    Error:Failed to resolve: com.google.code.findbugs:jsr305:2.0.1
    Error:Failed to resolve: org.hamcrest:hamcrest-library:1.3
    Error:Failed to resolve: com.squareup:javawriter:2.1.1

    please i followed each steps of yours Tutorial.. I need Help...Thank

    ReplyDelete
    Replies
    1. Hi, Please make sure you have latest version of appium client and server along with selenium jars. Plus you have latest version of JAVA and Android studio installed. You can watch video also to follow exact steps.
      THanks,
      Anuja

      Delete
  40. Hi,
    Thanks for this tutorial,
    I followed all the steps you mention and imported all the jars you mentioned in the video and blog,
    However, when pasting the code, the following imports are unrecognized -

    import org.openqa.selenium.By;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;

    (By, remtoe, and support are colored in red).
    as a result DesiredCapabilities can't be resolved and the code doesn't compile...

    Do you have a suggestions to what am I doing wrong ?

    ReplyDelete
    Replies
    1. Hi, There is one jar ouside the folder when you extract selenium jars. you are missing that jar. thats why you are getting that error.

      Delete
    2. Thank you, that did the trick

      Delete
  41. hi, your tutorial is to good but i have a problem, when i run the project the following error is shown
    Error:Execution failed for task '
    :app:transformResourcesWithMergeJavaResForDebug'.
    > com.android.build.api.transform.TransformException:
    com.android.builder.packaging.DuplicateFileException:
    Duplicate files copied in APK META-INF/LICENSE File1:
    C:\Users\Jolta\AndroidStudioProjects\MytestingApp\app\libs\httpmime-4.5.2.jar File2:
    C:\Users\Jolta\AndroidStudioProjects\MytestingApp\app\libs\xercesImpl-2.11.0.jar File3:
    C:\Users\Jolta\AndroidStudioProjects\MytestingApp\app\libs\httpclient-4.5.2.jar File4:
    C:\Users\Jolta\AndroidStudioProjects\MytestingApp\app\libs\cglib-nodep-3.2.4.jar File5:
    C:\Users\Jolta\AndroidStudioProjects\MytestingApp\app\libs\httpcore-4.4.4.jar

    ReplyDelete
  42. Thank you by the tutorial, I helped me a lot. I am new about moviles test theme and i have a doubt: How am i generate the code of the application who i want to test? that is, the bibliographies almost always give me a example code but they dont tell me where are they generate the test code?
    I would like I know this, please help me.

    ReplyDelete
  43. I started the test´s world with visual studio, microsoft test manager and selenium for web and desktop application the last year, and i liked it.
    At present I am interested in automated mobile testing and i am working with appium and android studio. I have accomplished to do test examples but i dont understand How am i generate the code of the application who i want to test? the examples come with yours code.
    I saw examples with Appium on Mac and i have seen how is it generate the code.
    I have not seen test examples on windows where it is explain the generate test code whit appium and android studio.
    Thank you for yours attention

    ReplyDelete
  44. Hi Anuja,

    i m getting this when i run the code

    debug] [MJSONWP] Bad parameters: BadParametersError: Parameters were incorrect. We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities","sessionId","id","sessionId","id"]} and you sent ["desiredCapabilities","requiredCapabilities","capabilities","alwaysMatch","firstMatch"]


    please help me out for this issue

    regards,
    jay

    ReplyDelete
    Replies
    1. Hi, Can you share your code too.
      Regards,
      Anuja

      Delete
  45. Hi Anuja,
    Firstly thanks a lot for this great tutorial, it really helped me get started (otherwise I was really stuck for the last 2 days going through so many blogs but none helped really).

    I have followed your tutorial and set up environment on CentOs -
    I have 2 problems -
    (1) I get NullPointer Exception while initializing the driver at
    "driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);"

    When I start my appium server (locally) - I see ->
    Welcome to Appium v1.6.3
    [Appium] Appium REST http interface listener started on 0.0.0.0:4723.
    HOW CAN ANY SERVER START AT 0.0.0.0:4723 ?

    (2) After Exception, I see following ouput on server ->
    [MJSONWP] Bad parameters: BadParametersError: Parameters were incorrect. We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities","capabilities","sessionId","id"]} and you sent ["desiredCapabilities","requiredCapabilities","capabilities","alwaysMatch","firstMatch"]
    [HTTP] <-- POST /wd/hub/session 400 5 ms - 243
    --> POST /wd/hub/session {"desiredCapabilities":{"appPackage":"com.android.calculator2","appActivity":"com.android.calculator2.Calculator","browserName":"Android","platformName":"Android","deviceName":"SM-T230NU","version":"4.4.2"},"requiredCapabilities":{},"capabilities":{"desiredCapabilities":{"appPackage":"com.android.calculator2","appActivity":"com.android.calculator2.Calculator","browserName":"Android","platformName":"Android","deviceName":"SM-T230NU","version":"4.4.2"},"requiredCapabilities":{}},"alwaysMatch":{"appPackage":"com.android.calculator2","appActivity":"com.android.calculator2.Calculator","browserName":"Android","platformName":"Android","deviceName":"SM-T230NU","version":"4.4.2"},"firstMatch":[]}

    WHY BAD PARAMETERS ??

    I am trying to follow the exact steps you described in your video.
    Please help!

    ReplyDelete
  46. Most of times i face this error.

    how to resolve these error.

    please guide me.

    Error:Error converting bytecode to dex:
    Cause: Dex cannot parse version 52 byte code.
    This is caused by library dependencies that have been compiled using Java 8 or above.
    If you are using the 'java' gradle plugin in a library submodule add
    targetCompatibility = '1.7'
    sourceCompatibility = '1.7'
    to that submodule's build.gradle file.

    ReplyDelete
  47. hi
    when is add the jars to lib in the project i get below error:
    Error:Failed to open zip file.
    Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
    Re-download dependencies and sync project (requires network)

    Please help here

    ReplyDelete
  48. hi I am getting the FirstTest class name grayed out and it says that Class FirstTest is never used .I followed your steps and also see that import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    these are all grayed out please advice

    ReplyDelete
    Replies
    1. Hi,

      This not actual error it is just a extra info about the class.It will not affect execution

      Regards,
      Anuja

      Delete
  49. This comment has been removed by the author.

    ReplyDelete
  50. My class is not getting executed though as it is greyed out.

    ReplyDelete
    Replies
    1. Hi,

      Make sure you have used Junit Annotations correctlty.
      You have created clss in src->java -> this path..
      Another way of exsution select test case name and right click and run.

      Thanks,
      Anuja

      Delete
  51. hi That is correct it is under /test/java/FirstTest

    ReplyDelete
  52. Hi Anuja,
    This is a great tutorial and I was able to follow i t step by step but I run into this error now.
    [HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"appPackage":"com.android.calculator","appActivity":"com.android.calculator.Calculator","browserName":"Android","platformName":"Android","deviceName":"9039262e","version":"6.0.1"},"requiredCapabilities":{},"capabilities":{"desiredCapabilities":{"appPackage":"com.android.calculator","appActivity":"com.android.calculator.Calculator","browserName":"Android","platformName":"Android","deviceName":"9039262e","version":"6.0.1"},"requiredCapabilities":{}},"alwaysMatch":{"appPackage":"com.android.calculator","appActivity":"com.android.calculator.Calculator","browserName":"Android","platformName":"Android","deviceName":"9039262e","version":"6.0.1"},"firstMatch":[]}
    [debug] [MJSONWP] Bad parameters: BadParametersError: Parameters were incorrect. We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities","capabilities","sessionId","id","sessionId","id","sessionId","id"]} and you sent ["desiredCapabilities","requiredCapabilities","capabilities","alwaysMatch","firstMatch"]
    Can you advice?

    ReplyDelete
  53. Thank you so much..Your blog was really helpful. Keep Going...

    ReplyDelete
  54. I am facing problem to configure appium and android studio in mac os. So if is it possible to share any video for mac os. And Please explain in brief how to configure this in mac os.

    ReplyDelete







  55. :app:transformClassesWithDexForDebug
    AGPBI: {"kind":"error","text":"Error converting bytecode to dex:\nCause: Dex cannot parse version 52 byte code.\nThis is caused by library dependencies that have been compiled using Java 8 or above.\nIf you are using the \u0027java\u0027 gradle plugin in a library submodule add \ntargetCompatibility \u003d \u00271.7\u0027\nsourceCompatibility \u003d \u00271.7\u0027\nto that submodule\u0027s build.gradle file.","sources":[{}],"original":"UNEXPECTED TOP-LEVEL EXCEPTION:\njava.lang.RuntimeException: Exception parsing classes\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:781)\n\tat com.android.dx.command.dexer.Main.processFileBytes(Main.java:747)\n\tat com.android.dx.command.dexer.Main.access$1200(Main.java:88)\n\tat com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1689)\n\tat com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)\n\tat com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)\n\tat com.android.dx.command.dexer.Main.processOne(Main.java:695)\n\tat com.android.dx.command.dexer.Main.processAllFiles(Main.java:592)\n\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:321)\n\tat com.android.dx.command.dexer.Main.run(Main.java:292)\n\tat com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:54)\n\tat com.android.builder.core.DexByteCodeConverter.lambda$dexInProcess$0(DexByteCodeConverter.java:174)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat java.lang.Thread.run(Thread.java:745)\nCaused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)\n\tat com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:476)\n\tat com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)\n\tat com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)\n\tat com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)\n\tat com.android.dx.command.dexer.Main.parseClass(Main.java:793)\n\tat com.android.dx.command.dexer.Main.access$1600(Main.java:88)\n\tat com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1728)\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:779)\n\t... 16 more\n","tool":"Dex"}
    AGPBI: {"kind":"error","text":"1 error; aborting","sources":[{}]}

    FAILED

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':app:transformClassesWithDexForDebug'.
    > com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process

    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.




    I am getting this error .plz help me

    ReplyDelete
  56. Error:(8, 27) error: cannot find symbol class By
    Error:(10, 34) error: package org.openqa.selenium.remote does not exist
    Error:(11, 34) error: package org.openqa.selenium.remote does not exist
    Error:(12, 34) error: package org.openqa.selenium.remote does not exist
    Error:(13, 38) error: package org.openqa.selenium.support.ui does not exist
    Error:(14, 38) error: package org.openqa.selenium.support.ui does not exist
    Error:(58, 6) error: cannot find symbol class Test
    Error:(25, 9) error: cannot find symbol class DesiredCapabilities
    Error:(25, 48) error: cannot find symbol class DesiredCapabilities
    Error:(31, 36) error: cannot find symbol variable CapabilityType
    Error:(34, 36) error: cannot find symbol variable CapabilityType
    Error:(52, 22) error: cannot find symbol class RemoteWebDriver
    Error:(63, 29) error: cannot find symbol variable By
    Error:(66, 28) error: cannot find symbol variable By


    please help me out

    ReplyDelete
    Replies
    1. That means you have not imported all the jar files inside selenium folder

      Delete
    2. I have added all jar files
      compile 'com.android.support:appcompat-v7:25.3.1'
      compile 'com.android.support.constraint:constraint-layout:1.0.2'
      compile 'com.android.support:design:25.3.1'
      testCompile 'junit:junit:4.12'
      compile files('libs/cglib-nodep-3.2.4.jar')
      compile files('libs/commons-codec-1.10.jar')
      compile files('libs/commons-exec-1.3.jar')
      compile files('libs/commons-io-2.5.jar')
      compile files('libs/commons-lang3-3.5.jar')
      compile files('libs/commons-logging-1.2.jar')
      compile files('libs/cssparser-0.9.21.jar')
      compile files('libs/gson-2.8.0.jar')
      compile files('libs/guava-21.0.jar')
      compile files('libs/hamcrest-core-1.3.jar')
      compile files('libs/hamcrest-library-1.3.jar')
      compile files('libs/htmlunit-2.24.jar')
      compile files('libs/htmlunit-core-js-2.23.jar')
      compile files('libs/htmlunit-driver-2.24.jar')
      compile files('libs/httpclient-4.5.2.jar')
      compile files('libs/httpcore-4.4.4.jar')
      compile files('libs/httpmime-4.5.2.jar')
      compile files('libs/java-client-5.0.0-BETA7.jar')
      compile files('libs/javax.servlet-api-3.1.0.jar')
      compile files('libs/jetty-io-9.4.1.v20170120.jar')
      compile files('libs/jetty-util-9.4.1.v20170120.jar')
      compile files('libs/jna-4.1.0.jar')
      compile files('libs/jna-platform-4.1.0.jar')
      compile files('libs/junit-4.12.jar')
      compile files('libs/neko-htmlunit-2.24.jar')
      compile files('libs/phantomjsdriver-1.4.0.jar')
      compile files('libs/sac-1.3.jar')
      compile files('libs/serializer-2.7.2.jar')
      compile files('libs/websocket-api-9.2.20.v20161216.jar')
      compile files('libs/websocket-client-9.2.20.v20161216.jar')
      compile files('libs/websocket-common-9.2.20.v20161216.jar')
      compile files('libs/xalan-2.7.2.jar')
      compile files('libs/xercesImpl-2.11.0.jar')
      compile files('libs/xml-apis-1.4.01.jar')

      Delete
  57. add multidexenabled true in build.gradle

    ReplyDelete
  58. Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
    > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/openqa/selenium/internal/FindsByClassName.class



    How do i fixed it? please help me

    ReplyDelete
  59. Hi Anuja,
    I an facing below exception wile run sample code provided in blog.

    java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/HasInputDevices

    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

    on this line
    driver = new RemoteWebDriver(new URL("http://127.0.0.1:4724/wd/hub"), capabilities);

    ReplyDelete
    Replies
    1. Could sure use some help on this. I've been trying to get it running for a couple of days.

      Delete
    2. I am getting this same error when I try to do a rebuild. The problem I think is that the HasInputDevices method is in org.openqa.selenium.interactions, but the the build seems to be looking for it in org.openqa.selenium. I am not sure why or how to fix it. Maybe it is a mismatch of the needed jar files?

      Could sure use some help on this. I've been trying to get it running for a couple of days.

      Delete
  60. Hi

    getting bellow error ,

    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/collect/ImmutableMap;
    at org.openqa.selenium.remote.HttpCommandExecutor.(HttpCommandExecutor.java:57)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153)

    after debugging I got that error is in
    Method threw 'java.lang.NoClassDefFoundError' exception. Cannot evaluate org.openqa.selenium.remote.DesiredCapabilities.toString()


    please replay ,

    thanks in advance

    Thanks
    -Tapas

    ReplyDelete
  61. Hi there!
    I am getting an exception of
    java.lang.NullPointerException at com.example.eventhandling.appiumtestingexample.FirstTest.End.
    Can you please help me with this?

    ReplyDelete
  62. Hi Anuja,

    Tried with your sample code. Build successful and calculator app opened and number 7 pressed , but it displays '1 test failed'

    Process finished with exit code -1

    Could you help me out where I went wrong.

    ReplyDelete
  63. Hello,
    I am getting below error while executing the Appium script.Anyone can please suggest a solution or root cause


    Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
    > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK com/steadystate/css/parser/SACParserMessages_de.properties
    File1: C:\Users\Admin\AndroidStudioProjects\AppiumProject\app\libs\cssparser-0.9.22.jar
    File2: C:\Users\Admin\AndroidStudioProjects\AppiumProject\app\libs\selenium-server-standalone-3.4.0.jar

    There is no duplicate file added in the gradle

    Thank you
    Sreejith

    ReplyDelete
  64. Can I get the libs?

    ReplyDelete
  65. when i'm putting capabilities.setCapability it says can't resolve symbol setcapabilty. Please provide the jar files as i have already used the jar files selenium-remote-client 2.0a2.jar. please help me out from this issue

    ReplyDelete
    Replies
    1. Hi, you need to add all jar files in selenium folder including one outside lib folder

      Delete
  66. Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving..
    Mobile App Development Company

    ReplyDelete
  67. What we can use in place of node.exe and appium.js in mac and also need help to locate these

    ReplyDelete
  68. I wish there was something like this for mac users...i am completely lost when try edit my system environment variable.

    ReplyDelete
  69. Hi Anuja,
    I was trying calculator script and as you did in your video by not stating path for cal application in appium config...... as it was there in your mobile
    i did same but server throws error and ends the server
    following is the appium log
    > Launching Appium server with command: C:\Program Files (x86)\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4733 --app --platform-name Android --platform-version 23 --automation-name Appium --device-name "Moto" --log-no-color
    > usage: main.js [-h] [-v] [--shell]
    > [--localizable-strings-dir LOCALIZABLESTRINGSDIR] [--app APP]
    > [--ipa IPA] [-U UDID] [-a ADDRESS] [-p PORT]
    > [-ca CALLBACKADDRESS] [-cp CALLBACKPORT] [-bp BOOTSTRAPPORT]
    > [-k] [-r BACKENDRETRIES] [--session-override] [--full-reset]
    > [--no-reset] [-l] [-lt LAUNCHTIMEOUT] [-g LOG]
    > [--log-level {info,info:debug,info:info,info:warn,info:error,warn,warn:debug,warn:info,warn:warn,warn:error,error,error:debug,error:info,error:warn,error:error,debug,debug:debug,debug:info,debug:warn,debug:error}]
    > [--log-timestamp] [--local-timezone] [--log-no-colors]
    > [-G WEBHOOK] [--native-instruments-lib]
    > [--app-pkg ANDROIDPACKAGE] [--app-activity ANDROIDACTIVITY]
    > [--app-wait-package ANDROIDWAITPACKAGE]
    > [--app-wait-activity ANDROIDWAITACTIVITY]
    > [--android-coverage ANDROIDCOVERAGE] [--avd AVD]
    > [--avd-args AVDARGS]
    > [--device-ready-timeout ANDROIDDEVICEREADYTIMEOUT] [--safari]
    > [--device-name DEVICENAME] [--platform-name PLATFORMNAME]
    > [--platform-version PLATFORMVERSION]
    > [--automation-name AUTOMATIONNAME] [--browser-name BROWSERNAME]
    > [--default-device] [--force-iphone] [--force-ipad]
    > [--language LANGUAGE] [--locale LOCALE]
    > [--calendar-format CALENDARFORMAT] [--orientation ORIENTATION]
    > [--tracetemplate AUTOMATIONTRACETEMPLATEPATH]
    > [--instruments INSTRUMENTSPATH] [--show-sim-log]
    > [--show-ios-log] [--nodeconfig NODECONFIG] [-ra ROBOTADDRESS]
    > [-rp ROBOTPORT] [--selendroid-port SELENDROIDPORT]
    > [--chromedriver-port CHROMEDRIVERPORT]
    > [--chromedriver-executable CHROMEDRIVEREXECUTABLE]
    > [--use-keystore] [--keystore-path KEYSTOREPATH]
    > [--keystore-password KEYSTOREPASSWORD] [--key-alias KEYALIAS]
    > [--key-password KEYPASSWORD] [--show-config] [--no-perms-check]
    > [--command-timeout DEFAULTCOMMANDTIMEOUT] [--keep-keychains]
    > [--strict-caps] [--isolate-sim-device] [--tmp TMPDIR]
    > [--trace-dir TRACEDIR] [--intent-action INTENTACTION]
    > [--intent-category INTENTCATEGORY] [--intent-flags INTENTFLAGS]
    > [--intent-args OPTIONALINTENTARGUMENTS]
    > [--dont-stop-app-on-reset] [--debug-log-spacing]
    > [--suppress-adb-kill-server] [--async-trace]
    >
    > main.js: error: argument "--app": Expected one argument. null
    >
    > Appium server process ended

    ReplyDelete
  70. Hello, I'm getting below errors.. what to do next?

    Error:(18, 5) error: cannot find symbol class WebDriver
    Error:(21, 32) error: cannot find symbol class MalformedURLException
    Error:(29, 36) error: cannot find symbol variable CapabilityType
    Error:(32, 36) error: cannot find symbol variable CapabilityType
    Error:(50, 22) error: cannot find symbol class RemoteWebDriver
    Error:(51, 55) error: cannot find symbol variable TimeUnit
    Error:(61, 29) error: cannot find symbol variable By
    Error:(64, 28) error: cannot find symbol variable By
    Error:(66, 54) error: cannot find symbol variable TimeUnit

    ReplyDelete
  71. i am unable to build my project after put this jar files.

    ReplyDelete
  72. Hi Anuja,

    I am getting below error while run my app.
    Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
    > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK javax/servlet/LocalStrings_fr.properties
    File1: D:\Paddy\Android\Project\Test2\app\libs\selenium-server-standalone-3.5.2.jar
    File2: D:\Paddy\Android\Project\Test2\app\libs\selenium-server-standalone-3.5.2.jar

    ReplyDelete
  73. goog Post...More interesting articles here : Generation Enggelmundus Internet Marketing Tool here : Zeageat IM

    ReplyDelete
  74. This comment has been removed by the author.

    ReplyDelete
  75. HI,
    I am getting below error could you please help me on this.
    error stating "Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
    > Failed to create MD5 hash for file 'C:\Users\xyz\AndroidStudioProjects\AutomationAndroid\app\libs\commons-io-2.5.jar'.

    build.gradle

    dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    compile 'com.android.support:design:26.+'
    testCompile 'junit:junit:4.12'
    // testCompile 'org.assertj:assertj-core:2.0.0'
    // testCompile 'org.testng:testng:6.9.10'
    compile files('libs/cglib-nodep-3.2.4.jar')
    compile files('libs/client-combined-3.5.3-nodeps.jar')
    compile files('libs/commons-codec-1.10.jar')
    compile files('libs/commons-exec-1.3.jar')
    compile files('libs/commons-io-2.5.jar')
    compile files('libs/commons-lang3-3.5.jar')
    compile files('libs/commons-logging-1.2.jar')
    compile files('libs/cssparser-0.9.23.jar')
    compile files('libs/guava-23.0.jar')
    compile files('libs/hamcrest-core-1.3.jar')
    compile files('libs/htmlunit-2.27.jar')
    compile files('libs/htmlunit-core-js-2.27.jar')
    compile files('libs/htmlunit-driver-2.27.jar')
    compile files('libs/httpclient-4.5.3.jar')
    compile files('libs/httpcore-4.4.6.jar')
    compile files('libs/httpmime-4.5.3.jar')
    compile files('libs/java-client-5.0.0-BETA1.jar')
    compile files('libs/javax.servlet-api-3.1.0.jar')
    compile files('libs/jetty-client-9.4.5.v20170502.jar')
    compile files('libs/jetty-http-9.4.5.v20170502.jar')
    compile files('libs/jetty-io-9.4.5.v20170502.jar')
    compile files('libs/jetty-util-9.4.5.v20170502.jar')
    compile files('libs/jna-4.1.0.jar')
    compile files('libs/jna-platform-4.1.0.jar')
    compile files('libs/junit-4.12.jar')
    compile files('libs/neko-htmlunit-2.27.jar')
    compile files('libs/phantomjsdriver-1.4.0.jar')
    compile files('libs/sac-1.3.jar')
    compile files('libs/serializer-2.7.2.jar')
    compile files('libs/websocket-api-9.4.5.v20170502.jar')
    compile files('libs/websocket-client-9.4.5.v20170502.jar')
    compile files('libs/websocket-common-9.4.5.v20170502.jar')
    compile files('libs/xalan-2.7.2.jar')
    compile files('libs/xercesImpl-2.11.0.jar')
    compile files('libs/xml-apis-1.4.01.jar')
    compile files('libs/apache-mime4j-0.6.jar')
    compile files('libs/commons-collections-3.2.1.jar')
    compile files('libs/commons-io-2.4.jar')
    compile files('libs/commons-lang3-3.4.jar')
    compile files('libs/commons-logging-1.1.3.jar')
    compile files('libs/commons-validator-1.4.1.jar')
    compile files('libs/gson-2.3.1.jar')
    compile files('libs/guava-18.0.jar')
    compile files('libs/httpclient-4.4.1.jar')
    compile files('libs/httpcore-4.4.1.jar')
    compile files('libs/httpmime-4.4.1.jar')
    compile files('libs/java-client-3.2.0.jar')
    compile files('libs/selenium-java-2.47.1.jar')
    compile files('libs/client-combined-3.4.0-nodeps.jar')
    compile files('libs/java-client-5.0.3.jar')
    }

    ReplyDelete
  76. Hi Anuja,

    Really amazing blog.
    Liked the way you have elaborated every steps. Just a quick question about the sample calculator project where I would be able to find to run this particular test case.

    Would you be able to provide calculator project here.

    Cheers,
    Yesha

    ReplyDelete
  77. Can someone help me, i check all info about this error, but it didn't help me
    I have this error:

    Error:Error converting bytecode to dex:
    Cause: Dex cannot parse version 52 byte code.
    This is caused by library dependencies that have been compiled using Java 8 or above.
    If you are using the 'java' gradle plugin in a library submodule add
    targetCompatibility = '1.7'
    sourceCompatibility = '1.7'
    to that submodule's build.gradle file.

    ReplyDelete
  78. Hi I added the jars to lib folder and after rebuild of the project I am getting this errorFAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':app:transformClassesWithDesugarForDebug'.

    Please help me resolve this

    ReplyDelete
  79. Hello Anuja,

    Great document, But I am still stuck to install and set up the application.
    1- Android Studio 3.0
    2- java-client-5.0.4.jar
    3- selenium-java-3.6.0.zip

    when re-build the app have following errors: any idea why?
    Error:com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\myuser\AndroidStudioProjects\JavaTest\app\libs\guava-23.0.jar
    Error:com.android.builder.dexing.DexArchiveBuilderException: Error while dexing com/google/common/collect/Maps$AsMapView.class
    Error:com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
    Error:Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
    > com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\myuser\AndroidStudioProjects\JavaTest\app\libs\guava-23.0.jar

    Appreciate your help in advance!

    ReplyDelete
  80. Hi I am getting error in the code which you have asked to copy paste


    import org.junit.After;
    import org.junit.Before;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;



    public class FirstTest {

    WebDriver driver;

    @Before
    public void setUp() throws MalformedURLException {
    // Created object of DesiredCapabilities class.
    DesiredCapabilities capabilities = new DesiredCapabilities();

    /* Set android deviceName desired capability. Set your device name. */
    capabilities.setCapability("deviceName", "XT1562");

    // Set BROWSER_NAME desired capability. It's Android in our case here.
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");

    // Set android VERSION desired capability. Set your mobile device's OS version.
    capabilities.setCapability(CapabilityType.VERSION, "6.0.1");

    // Set android platformName desired capability. It's Android in our case here.
    capabilities.setCapability("platformName", "Android");

    // Set android appPackage desired capability. It is
    // com.android.calculator2 for calculator application.
    // Set your application's appPackage if you are using any other app.
    capabilities.setCapability("appPackage", "com.android.calculator2");

    // Set android appActivity desired capability. It is
    // com.android.calculator2.Calculator for calculator application.
    // Set your application's appPackage if you are using any other app.
    capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");

    // Created object of RemoteWebDriver will all set capabilities.
    // Set appium server address and port number in URL string.
    // It will launch calculator app in android device.
    driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);


    }

    @Test
    public void testFirstCalculator() {


    // Click on DELETE/CLR button to clear result text box before running test.
    driver.findElements(By.xpath("//android.widget.Button")).get(0).click();

    // Click on number 2 button.
    driver.findElement(By.name("7")).click();

    driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
    }

    @After
    public void End() {
    driver.quit();
    }
    }

    I am unable to save.

    Please help

    ReplyDelete
  81. Im getting this error java.lang.ClassCastException: org.openqa.selenium.remote.DesiredCapabilities cannot be cast to org.openqa.selenium.Capabilities

    ReplyDelete
  82. When I download selenium-java-3.8.1 it only contains following jar files
    byte-buddy-1.7.5
    commons-codec-1.10
    commons-exec-1.3
    commons-logging-1.2
    gson-2.8.2
    guava-23.0
    httpclient-4.5.3
    httpcore-4.4.6

    ReplyDelete
  83. Yes, this is what I see in the download. It seems it should be sufficient, but I can not seem to get past a rebuild due to the error above I've commented on:
    Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/HasInputDevices

    Has anyone found a solution to this? Is the author still monitoring these comments?

    ReplyDelete