0

I am trying to run my first test case for appium using eclipse oxygen. i followed up tutorial step by step

http://www.automationtestinghub.com/appium-tutorial/

My actual code is

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

    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.MobileElement;
    import io.appium.java_client.android.AndroidDriver;

    public class AppiumTest {
    public static void main(String[] args) {

    //Set the Desired Capabilities
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("deviceName", "SM-T211");
    caps.setCapability("udid", "41022b138d311100"); //Give Device ID of your mobile phone
    caps.setCapability("platformName", "Android");
    caps.setCapability(CapabilityType.VERSION, "4.4.2");
    caps.setCapability("appPackage", "com.isinolsun.app");
    caps.setCapability("appActivity", "com.isinolsun.app.activities.OnBoarderActivity");
    caps.setCapability("noReset", "true");

    //Instantiate Appium Driver
    try {
        AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
        driver.closeApp();
    } catch (MalformedURLException e) {
        System.out.println(e.getMessage());
    }
}

i am using real device.

Appium Desktop application is installed. when i run program it gives me exception on that line

    AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
        driver.closeApp();
    } catch (MalformedURLException e) {
        System.out.println(e.getMessage());
    }

Exception msg is

    Exception in thread "main" java.lang.NoClassDefFoundError: javax/websocket/DeploymentException
at io.appium.java_client.android.ListensToLogcatMessages.<clinit>(ListensToLogcatMessages.java:34)
at com.appiumtest.firsttestscript.AppiumTest.main(AppiumTest.java:27)

    Caused by: java.lang.ClassNotFoundException: javax.websocket.DeploymentException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more

all the jar files are included according to tutorial steps. sdk, android studio, jdk are also added.

Can anyone guide me?

2
  • Hi, could you please provide the details like, which appium version you are using, java-client version, which device version you are using? Commented May 16, 2018 at 5:55
  • @SurajJogdand ...! appium 3.11, java-client-6.0.0BETA, Samsung. now it works with java-client-5.0.0. according to Gustavo answer. Commented May 17, 2018 at 7:59

2 Answers 2

2

You have to remove the java-client-6.0.0-BETA5 JAR and add the java-client-5.0.0-BETA5 JAR.

Cheers.

0
2

Do below code :

public class AppiumTest
{
   public static void main(String[] args) throws Exception
    {
        // start appium server
           Runtime.getRuntime().exec("cmd.exe /c start cmd.exe /k \"appium -a 0.0.0.0 -p 4723\"");
           //get address of appium server
                URL u=new URL("http://0.0.0.0:4723/wd/hub");
                //provide device and app info
                DesiredCapabilities dc=new DesiredCapabilities();
                dc.setCapability(CapabilityType.BROWSER_NAME,"");
                dc.setCapability("deviceName","NVRW499T9PVCSGTO");
                dc.setCapability("platformName","android");
                dc.setCapability("platformVersion","6.0");
                dc.setCapability("appPackage","com.isinolsun.app");
                dc.setCapability("appActivity","com.isinolsun.app.activities.OnBoarderActivity");
                //create driver object to launch app in device
                AndroidDriver driver;
                while(2>1)
                {
                    try
                    {
                        driver=new AndroidDriver(u,dc);
                        break;//terminate from loop
                    }
                    catch(Exception e)
                    {
                        System.out.println(e.getMessage());
                    }
                }
             driver.closeApp();
            //stop appium server
              Runtime.getRuntime().exec("taskkill /F /IM node.exe");
              Runtime.getRuntime().exec("taskkill /F /IM cmd.exe");

}
}
1
  • Why are you using while(2>1) in your code? If it catch error won't it go to infinite loop printing e.getMessage? Commented Jul 31, 2018 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.