在 Eclipse 中找不到带有 Appium 的构造函数 AndroidDriver

Not found constructor AndroidDriver with Appium in eclipse

有错误的代码:

package TestCase;

import java.net.MalformedURLException;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.gargoylesoftware.htmlunit.javascript.host.URL;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;

public class TestWebBrowser {
    //AppiumDriver driver = new IOSDriver();
    public static AndroidDriver driver;

    public static void main(String[] args) throws MalformedURLException {           
        DesiredCapabilities capabilities = new DesiredCapabilities();   
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);  
    }
}

消息错误为:

  • The constructor URL(string) is undefined
  • The constructor AndroidDriver(URL, DesiredCapabilities) is undefined
  • AndroidDriver is a raw type

我尝试了不同版本的 java-client,但问题仍然存在

您需要像这样使用现有的构造函数:

https://appium.github.io/java-client/io/appium/java_client/android/AndroidDriver.html

您需要使用 java.net.URL 而不是 com.gargoylesoftware.htmlunit.javascript.host.URL

@Lorena,你好。
1. 首先,请您仔细检查进口商品好吗?与正确的分享下面的代码片段

package tests.web;

import java.net.MalformedURLException;
import java.net.URL;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileBrowserType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
public class AndroidWebTest {
   private static final String ACCESS_KEY = System.getenv(“SEETEST_IO_ACCESS_KEY”);
   private static final String CLOUD_URL = “https://cloud.seetest.io:443/wd/hub”;
   private static final String TITLE = “Testing Website on Android Chrome with Java”;
   private AndroidDriver driver = null;

   @Before
   public void setUp() throws MalformedURLException {
       DesiredCapabilities dc = new DesiredCapabilities();
       dc.setCapability(“testName”, TITLE);
       dc.setCapability(“accessKey”, ACCESS_KEY);
       dc.setBrowserName(MobileBrowserType.CHROME);
       driver = new AndroidDriver(new URL(CLOUD_URL), dc);
   }

   @Test
   public void testAppiumOnChrome() {
       driver.get(“https://amazon.com”);
       System.out.println(driver.getTitle());
       if (driver.getCapabilities().getCapability(“device.category”).equals(“TABLET”)) {
           driver.findElement(By.xpath(“//*[@name=’field-keywords’]”)).sendKeys(“iPhone”);
           driver.findElement(By.xpath(“//*[@text=’Go’]”)).click();
       } else {
           driver.findElement(By.xpath(“//*[@name=’k’]”)).sendKeys(“iPhone”);
           driver.findElement(By.xpath(“//*[@value=’Go’]”)).click();
       }
   }

   @After
   public void tearDown() {
       if (driver != null) {
           driver.quit();
       }
   }
}

详情请参阅Comparing and combining web and mobile test automation drivers文章。

  1. 如果您的项目是 maven-based,请您也仔细检查一下依赖关系好吗? 例如,请查看最新的 appium 更新 here

用于检查(最新)java 客户端的适当 Maven 存储库: https://mvnrepository.com/artifact/io.appium/java-client