首页 文章

Appium配置Java

提问于
浏览
1

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

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

我得到的是@BeforeMethod中的错误

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

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

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的libarys,因为我也尝试使用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>

1 回答

  • 2

    你可以尝试两件事 .

    • 尝试使用selenium 2.53版
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>2.53.0</version>
    </dependency>
    
    • 也没有通过以下功能,因为你传递apk的绝对路径,所以你不应该传递浏览器名称功能,因为将创建一个会话,即使用浏览器或应用程序 .
    capabilities.setCapability("BROWSER_NAME", "Android");
    

相关问题