JoCuTo
JoCuTo

Reputation: 2483

Appium test not starting app on Android

I have to learn about Appium and I am doing a "hello Appium".

Windows8, Appium 1.4.13.1 ,IntelliJidea 14.1

        WebDriver driver;
        @Before
        public void setUp() throws MalformedURLException {

        DesiredCapabilities capabilities = new DesiredCapabilities(); 
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"5554:Nexus_5");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "5.1");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION,"Android");
        capabilities.setCapability(MobileCapabilityType.APP,"C:\\Users\\demitria\\Desktop\\testapp.apk");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);

        }

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



        @Test
        public void tapOnLoginNotFilledAnyThing(){

            WebElement mob = driver.findElement(By.id("com.example.testapp:id/login_login_button"));

          //here on mob WebElement I get java.lang.NullPointerException
         //at MyFirstTest.tapOnLoginNotFilledAnyThing(MyFirstTest.java:78)

          mob.click();
        }


        @Test
        public void logInWithInvalidEmail(){


        }

On appium I have the application path to
C:\Users\demitria\Desktop\testapp.apk

Appium works well also the Appium inspector but when I launch the test nothing happen with the emulator(in the sense that the app is not started in the emulator) but in fact the test are executed or at least I think so. I get an alert icons as well on IntelliJidea . Any idea about what I´m doing wrong

enter image description here enter image description here

Upvotes: 1

Views: 1613

Answers (2)

JoCuTo
JoCuTo

Reputation: 2483

Solved.

1.- Uninstall IntelliJidea 14.1 and install Eclipse (the current version), it gives me more information about the errors I have than IntelliJ (you can omit this steep)
2.- Move my .apk to-> sdk\build-tools\ApiVersionYouAreUsingInAppium, my case C:\Android\sdk\build-tools\22.0.1
3.- Set the new path on Appium-> Android Setting-> your aplication path

Modify Capacibilities as show below

    public void setUp() throws MalformedURLException {

     DesiredCapabilities capabilities = new DesiredCapabilities();

     File appDir = new File("C:\\Android\\sdk\\build-tools\\22.0.1\\");
     File app = new File(appDir, "testapp.apk");

     capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"Nexus_5");
     capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "5.1");
     capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION,"Android");
     capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
     capabilities.setCapability(MobileCapabilityType.APP_PACKAGE,"com.example.testapp");
     capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY,"com.example.testapp.MainActivity");

     driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
     driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);

}

Upvotes: 1

debugger89
debugger89

Reputation: 2776

Please try the modified capabilities a shown below.

public void setUp() throws MalformedURLException {

    DesiredCapabilities capabilities = new DesiredCapabilities(); 
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"5554:Nexus_5");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "5.1");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION,"Android");
    capabilities.setCapability(MobileCapabilityType.APP,"C:\\Users\\demitria\\Desktop\\testapp.apk");
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);

}

If you have the APK file with you when you set the MobileCapabilityType.APP capability Appium automatically opens the main activity of the app while running.

Upvotes: 0

Related Questions