android - 使用 Appium + TestNG + Eclipse 在 Android 上运行自动测试

标签 android eclipse selenium testng appium

我是自动测试和 Appium 的初学者,我正在尝试测试(针对 Android)。

我下载了:

  1. Appium - 运行服务器

  2. Android 模拟器(Android 虚拟设备管理器)

  3. TestNG

测试的目的是将联系人添加到联系人列表。

有人知道我错过了什么吗?

测试:

package com.appium;

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

import java.io.File;
import java.net.URL;
import java.util.List;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;

public class One {

    private AppiumDriver driver;

    @BeforeSuite
    public void setUp() throws Exception {
        //driver.launchApp();

        // set up appium
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "Nexus5");
        capabilities.setCapability("platformV01ersion", "4.1.2");
        capabilities.setCapability("appPackage",
            "com.example.android.contactmanager");
        capabilities.setCapability("appActivity", ".ContactManager");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                capabilities);
    }

    @Test
    public void addContact() {
        WebElement el = driver.findElement(By.name("Add Contact"));
        el.click();
        List<WebElement> textFieldsList = driver
                .findElementsByClassName("android.widget.EditText");
        textFieldsList.get(0).sendKeys("Some Name");
        textFieldsList.get(2).sendKeys("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5605393b3316332e373b263a337835393b" rel="noreferrer noopener nofollow">[email protected]</a>");
        driver.swipe(100, 500, 100, 100, 2);
        driver.findElementByName("Save").click();
    }

    @AfterSuite
    public void tearDown() throws Exception {
        driver.quit();
    }

}

异常

[TestNG] Running:
  C:\Users\nadav.miran\AppData\Local\Temp\testng-eclipse-451394169\testng-customsuite.xml

FAILED CONFIGURATION: @BeforeSuite setUp
java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials
    at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:88)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:62)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:57)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:153)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:109)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:39)
    at com.appium.One.setUp(One.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:277)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.ClassNotFoundException: org.apache.http.auth.Credentials
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 25 more


===============================================
    Default test
    Tests run: 0, Failures: 0, Skips: 0
    Configuration Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 0, Failures: 0, Skips: 0
Configuration Failures: 1, Skips: 1
===============================================

[TestNG] Time taken by org.testng.reporters.XMLReporter@517ceb9b: 13 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@37610393: 7 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@54fba1ac: 0 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@9e12aac: 34 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@61ed627d: 29 ms

谢谢!

最佳答案

请将以下依赖项添加到您的项目中

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.2.2</version>
</dependency>

还请 从 here 下载 Selenium-server-standalone.jar并添加到类路径中。 请看这个link了解更多详情。

关于android - 使用 Appium + TestNG + Eclipse 在 Android 上运行自动测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29970361/

相关文章:

java - Android 4.4.3 上出现 NullPointerException,但 4.1.2 上没有

java - 将日历设置为特定日期?

android - Jetpack Compose,使用自定义 Lifecycle/ViewModelStore/SavedStateRegistry Owner 时不会触发重组

c++ - 从 Eclipse IDE 运行 C++ 应用程序

Android Studio 中出现 Java 错误,但 Eclipse 中没有

javascript - Python、Selenium 和新窗口的 XPATH

Selenium-Webdriver (Java) 未能始终如一地执行 'hoverover and click' 函数

java - 如何使用 Selenium WebDriver 从下拉框中选择一个项目?

android - 在不更改版本号的情况下更新 Android 应用程序

python - wxPython版本问题