【问题标题】:Appium Configuration JavaAppium 配置 Java
【发布时间】:2018-11-21 18:43:31
【问题描述】:

我正在尝试使用 Appium 自动化我的应用程序,但我似乎无法正确配置。

Appium 服务器在 127.0.0.1:4723 上运行并启动。我使用带有 avd 的 Android SDK 模拟器模拟设备。我使用带有 Selenium 和 TestNG 的 Eclipse 来测试我的配置。

我得到的是@BeforeMethod 中的错误

FAILED CONFIGURATION: @BeforeMethod setUp
java.lang.NoClassDefFoundError: org/openqa/selenium/logging/LoggingHandler

任何建议我的配置可能有什么问题?

package xxx_appium.xxx_appium_test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.aspectj.lang.annotation.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.service.DriverCommandExecutor;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class ConnectionTest {

@BeforeMethod
public void setUp() throws MalformedURLException {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("BROWSER_NAME", "Android");
    capabilities.setCapability("avd","ANexus");
    capabilities.setCapability("deviceName", "ANexus");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "9");
    capabilities.setCapability("app", 
    "C:\\Users\\xxx\\Downloads\\yyyy.apk");

    driver = new AndroidDriver<WebElement>(new         
    URL("http://localhost:4723/wd/hub"), capabilities);

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

@Test
public void sampleTest() {
}

这里还有 maven 依赖项,所以你知道我使用 jUnit 的哪些库在那里,因为我也用 jUnit 尝试过:

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>
    <dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>6.1.0</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.14.0</version>
</dependency>
</dependencies>

【问题讨论】:

    标签: appium appium-android


    【解决方案1】:

    你可以尝试两件事。

    1. 尝试使用 selenium 版本 2.53

      <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.0</version>
      </dependency>
      
    2. 也不要传递以下功能,因为您正在传递 apk 的绝对路径,因此您不应传递浏览器名称功能,因为将创建一个会话,即使用浏览器或应用程序。

       capabilities.setCapability("BROWSER_NAME", "Android");
      

    【讨论】:

    • 工作就像一个魅力。问题是硒版本。我不知道是什么变化如此之大,以至于我的配置在 3.x 版上中断,但 2.53 版可以工作。
    • 我遇到了同样的错误,我只需要更改 Selenium-Java 版本。我还提到了 Browser_name 并且通过查看您的评论我已将其删除,但它要求定义 Browser_name ,因此它需要。
    猜你喜欢
    • 2016-03-16
    • 1970-01-01
    • 2013-10-02
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    • 2017-03-21
    相关资源
    最近更新 更多