Search code examples
appiumappium-android

How to fix URL definitions in Eclipse for Appium Server


I'm new to eclipse. I'm trying to start Appium test on Android devices. My preferenses:

  • Appium 1.8.2
  • jre1.8.0_191
  • jdk1.8.0_191
  • eclipse 4.9.0
  • TestNG
  • AndroidStudio 3.2.1
  • AndroidDeveloperTools

So after installing, configuration Appiumserver, Android SDK, Android Device Manager - next step is to start testing in Eclipse IDE I've got problem with defining URL and don't know what to do. jar files:

  • java-client-6.1.0.jar
  • gson-2.8.5.jar
  • client-combined-3.9.0-sources.jar
  • client-combined-3.9.0.jar
  • seleium-3.9.0-nodeps-sources.jar
  • seleium-3.9.0-nodeps.jar
  • seleium-html-runner-3.9.0.jar
  • seleium-server-standalone-3.9.0.jar
  • TestNG
  • JRE System Library

that's all

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;


public class FirstScript {
    private URL           serverUrl;

    public static AndroidDriver driver;

        public String APPIUM_PORT = "4723";

    @BeforeClass
    public void setUp() throws MalformedURLException{
        //Set the Desired Capabilities
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("deviceName", "Samsung S7");
        caps.setCapability("udid", "******************"); //Give Device ID of your mobile phone
        caps.setCapability("platformName", "Android");
        caps.setCapability("platformVersion", "8.0");
        caps.setCapability("appPackage", "com.***.***");
        caps.setCapability("appActivity", "com.***.***.MainActivity");
        caps.setCapability("noReset", "true");
        try {
                serverUrl = new URL("http://127.0.0.1:4723/wd/hub");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        driver = new AndroidDriver (serverUrl,caps);
        driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
    }

    @Test
    public void testExample() {***}

    @AfterClass
    public void tearDown() {driver.closeApp();}
}

Running debug for this code with error

Server is working


Solution

  • The solution to your issue is that you use latest stable version of Selenium i.e. 3.141.5

    If you're having Java project then, before adding new latest version of jar's make sure to first remove all selenium related old jar's and then add newly downloaded version of the jar's to build path.

    In case of Maven project, update the selenium dependency version to latest and run following on terminal,

    $ mvn clean install