如何在Eclipse for Appium Server中修复URL定义

时间:2018-11-14 06:32:08

标签: appium appium-android

我是新来的蚀者。我正在尝试在Android设备上开始Appium测试。我的首选:

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

因此,在安装,配置Appiumserver,Android SDK,Android设备管理器后-下一步是开始在Eclipse IDE中进行测试,我在定义URL时遇到问题,不知道该怎么做。 jar文件:

  • 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系统库

仅此而已

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

2 个答案:

答案 0 :(得分:0)

  

我建议您使用Maven项目及其依赖项: java-client selenium-java testng

如果您不想使用Maven项目,则需要在eclipse中导入上述库。为此,在Eclipse工作区中,右键单击左窗格中的项目->属性-> Java构建路径->添加jar->在此处添加jar。

按以下步骤更改代码:

public class FirstScript {

   public static AppiumDriver<MobileElement> driver;

    @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");

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


}

答案 1 :(得分:0)

解决此问题的方法是使用最新稳定的Selenium版本,即3.141.5

如果您正在使用Java项目,则在添加最新版本的jar之前,请确保首先删除所有与硒相关的旧jar,然后添加最新下载的jar版本以构建路径。

对于Maven项目,请将硒依赖版本更新为最新版本,然后在终端上运行,

$ mvn clean install