Hi i m new to appium.. i am not able to run a script on demo apk file... please help me

Hi i m new to appium… i am trying to run a script on demo apk file… but its showing the following error in the console… please help me…

Thanks in advance… my code is as below

package PACKAGE.test;

import java.net.MalformedURLException;
import java.net.URL;

import java.util.List;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;

public class script1 {

private static WebDriver driver;

public static void main(String[] args) {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("device", "Android");
    capabilities.setCapability(CapabilityType.VERSION, "5.1");
    capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
    capabilities.setCapability("deviceName","abc1");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("app",
            "C:\\Users\\sudhanva.m\\Downloads\\demo1.apk");
    capabilities.setCapability("app-package",
            "com.gorillalogic.monkeytalk.demo1");
    capabilities.setCapability("app-activity", ".RootActivity");
    try {
        driver = new RemoteWebDriver(new URL("http://127.0.0.1:4724/wd/hub"),
                capabilities);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

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



}

@Test
public void loginTest() throws InterruptedException {

    List<WebElement> textFieldsList = driver.findElements(By
            .className("android.widget.EditText"));
    int size = textFieldsList.size();

    textFieldsList.get(0).sendKeys("Admin");
    textFieldsList.get(1).sendKeys("Admin");
    driver.findElements(By.xpath("android.widget.Button")).get(1).click();
    WebElement logout = driver.findElement(By.name("LOGOUT"));
    String logOut = logout.getText();
    System.out.println(logOut);
    logout.click();
}

@Test
public void formTest() throws InterruptedException {

    List<WebElement> textFieldsList1 = driver.findElements(By
            .className("android.widget.RelativeLayout"));
    textFieldsList1.get(2).click();

    driver.findElement(By.className("android.widget.Spinner")).click();
    List<WebElement> listsDropDown = driver.findElements(By
            .className("android.widget.CheckedTextView"));
    for (WebElement listdropdown : listsDropDown) {
        String list = listdropdown.getText();
        if (list.equals("Oxygen")) {
            listdropdown.click();
        }
    }

    // click on check box
    WebElement checkBox = driver.findElement(By
            .className("android.widget.CheckBox"));
    if (checkBox.isSelected()) {
        checkBox.click();
    }

    // radio button
    driver.findElements(By.className("android.widget.RadioButton")).get(1)
            .click();

}

}

my error is as follows…

When i run my script using android junit test

the emulator opens and i get the following error

[2015-03-09 11:10:17 - com.script.java1] Automatic Target Mode: using existing emulator ‘emulator-5554’ running compatible AVD ‘abc1’
[2015-03-09 11:10:18 - com.script.java1] Application already deployed. No need to reinstall.
[2015-03-09 11:10:18 - com.script.java1] Launching instrumentation android.test.InstrumentationTestRunner on emulator-5554
[2015-03-09 11:10:18 - com.script.java1] Failed to launch test
[2015-03-09 11:11:02 - com.script.java1] ------------------------------
[2015-03-09 11:11:02 - com.script.java1] Android Launch!
[2015-03-09 11:11:02 - com.script.java1] adb is running normally.
[2015-03-09 11:11:02 - com.script.java1] Performing android.test.InstrumentationTestRunner JUnit launch
[2015-03-09 11:11:02 - com.script.java1] Automatic Target Mode: launching new emulator with compatible AVD ‘abc1’
[2015-03-09 11:11:02 - com.script.java1] Launching a new emulator with Virtual Device ‘abc1’
[2015-03-09 11:11:22 - Emulator] emulator: warning: opening audio output failed
[2015-03-09 11:11:22 - Emulator]
[2015-03-09 11:11:22 - com.script.java1] New emulator found: emulator-5554
[2015-03-09 11:11:22 - com.script.java1] Waiting for HOME (‘android.process.acore’) to be launched…
[2015-03-09 11:12:32 - com.script.java1] HOME is up on device ‘emulator-5554’
[2015-03-09 11:12:32 - com.script.java1] Uploading com.script.java1.apk onto device ‘emulator-5554’
[2015-03-09 11:12:33 - com.script.java1] Installing com.script.java1.apk…
[2015-03-09 11:12:56 - com.script.java1] Success!
[2015-03-09 11:12:56 - com.script.java1] Launching instrumentation android.test.InstrumentationTestRunner on emulator-5554
[2015-03-09 11:12:56 - com.script.java1] Failed to launch test

Hello,

In order for me to understand what happened, I need you to attach your Appium server logs.

Thanks

  1. You should be using AppiumDriver, not WebDriver, and instantiate either AndroidDriver or IOSDriver, depending on which type of app you’re testing.
  2. Try putting in an implicit wait or explicit wait at the beginning of the test.

Also, as Hassan Radi said, please provide appium logs as they are essential for troubleshooting.

@Simon_K

Thankyou:) It solved and running fine now.

@Simon_K

Hi Simon,
There is an button next to recent tab… How to click on it?

And how to click on back home and recent tab in android?
Thanks in advance