Use Appium tests with Android Studio

Hi,

I’m trying to start my Appium tests through Android studio.
I have dowloaded Appium (graphic interface), I launch Appium, I launch my android virtual device (Genymotion) and then I run my test:

public class ConnectionTest {

    AppiumDriver driver;

    @Before
    public void setUp() throws Exception {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("appium-version", "1.0");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("platformVersion", "4.4");
        capabilities.setCapability("deviceName", "192.168.56.101:5555");// Genymotion 
        capabilities.setCapability("app", "/Users/me/Projects/myAndroidProject/app/build/outputs/apk/app-debug.apk");
        capabilities.setCapability("appPackage", "com.tabletapp.activities");

        //http://0.0.0.0:4723/wd/hub
        driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities) {
            @Override
            public MobileElement scrollTo(String text) {
                return null;
            }

            @Override
            public MobileElement scrollToExact(String text) {
                return null;
            }
        };
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    }

    @After
    public void tearDown() throws Exception {
        driver.close();
    }

    @Test
    public void apiDemo() {
        driver.findElement(By.xpath("//android.view.View[1]/android.widget.FrameLayout[2]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.EditText[1]")).click();
        driver.findElement(By.xpath("//android.view.View[1]/android.widget.FrameLayout[2]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.EditText[1]")).sendKeys("o2demo");
        driver.findElement(By.xpath("//android.view.View[1]/android.widget.FrameLayout[2]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.EditText[2]")).click();
        driver.findElement(By.xpath("//android.view.View[1]/android.widget.FrameLayout[2]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.EditText[2]")).sendKeys("demo3");
        driver.findElement(By.xpath("//android.view.View[1]/android.widget.FrameLayout[2]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.Button[1]")).click();
    }
}

First of all I got an error message “Gradle running. Failed to complete Gradle execution” (Error:Execution failed for task ‘:app:preDexAppDebugTest’) then a virtual device is launched but it’s not the one that I have specified in my code above (192.168.56.101:5555) it’s AVD which crash and nothing happen.

I would really appreciate if someone can tell me if I’m doing something wrong and if I missed something.

How did you run the test? In Android Studio or with command line?
If you could post your gradle file maybe I would be able to help you!
I’m trying the same.

Thanks

It wast just because of:

capabilities.setCapability(“appPackage”, “com.tabletapp.activities”); which wasn’t the good path.

and

I changed AppiumDriver by AndroidDriver

Then it fixed my issue.