【问题标题】:Testing an Android application failed in Eclipse using Appium使用 Appium 在 Eclipse 中测试 Android 应用程序失败
【发布时间】:2023-03-24 18:03:01
【问题描述】:

我想了解一个测试 Android 应用程序的工具。经过一番谷歌搜索后,我发现了一个名为 Appium 的奇妙工具,它用于测试 Android 应用程序,也是一个开源的。我想了解一下。所以我继续创建了一个简单的 Android 应用程序,只需点击几下按钮即可开始测试。

我做了以下所有事情:

  1. 将所有必要的 jar 插入 Eclipse IDE。
  2. 已下载并安装 Appium 服务器。
  3. Eclipse 插入 MavenTestNG
  4. 已成功将SampleApp.apk 安装到模拟器中。

接下来我创建了一个TestNG 类来测试SampleApp.apk。其代码粘贴在下面。但是在运行应用程序时,我收到了java.lang.NullPointerException。已经两天了。我尝试做所有事情,构建、清理、重新启动 Eclipse、创建新应用程序、重新安装所有依赖项。但我仍然收到同样的例外。我已经通过Execute Automation 推荐了视频,并且做了完全相同的操作,但减去了我的情况不同的应用程序。

package com.example.appium;

import java.net.MalformedURLException;
import java.net.URL;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.junit.BeforeClass;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.Test;

public class TestJavaAppium {

    AppiumDriver<WebElement> driver;

    @BeforeClass
    public void Setup() throws MalformedURLException{

        DesiredCapabilities capability =  new DesiredCapabilities();
        capability.setCapability(MobileCapabilityType.DEVICE_NAME, "Emulator");
        capability.setCapability(MobileCapabilityType.APP_PACKAGE, "com.example.sampleapp");
        capability.setCapability("avd", "Emulator4.2");         
        driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4273/wd/hub"), capability);
    }

    @Test
  public void simpleTest() {

      Assert.assertNotNull(driver.getContext());
  }
}

我的 Appium 配置如下,只是为了确保我的所有信息都是正确的。

理想情况下,代码应该成功运行并启动应用程序(至少在视频中是这样)。但我收到的是以下异常:

[TestNG] Running:
  C:\Users\KC\AppData\Local\Temp\testng-eclipse-518994855\testng-customsuite.xml

FAILED: simpleTest
java.lang.NullPointerException
    at com.example.appium.TestJavaAppium.simpleTest(TestJavaAppium.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:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:773)
    at org.testng.TestRunner.run(TestRunner.java:623)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
    at org.testng.SuiteRunner.run(SuiteRunner.java:259)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
    at org.testng.TestNG.run(TestNG.java:1018)
    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)


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


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

[TestNG] Time taken by org.testng.reporters.jq.Main@6d9c638: 225 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@7fbe847c: 230 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 26 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@5e265ba4: 14 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@2401f4c3: 14 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@182decdb: 12 ms

激怒我的 Eclipse 的地方可能是哪里出错了?

【问题讨论】:

  • 您的代码看起来不错,您可以稍等一下以启动应用程序
  • 您能否为 Appium 服务器提供更多功能,例如 app 的 activityName 。 capa.setCapability("appActivity", ".LauncherActivity");根据您的应用更改活动名称。您可以查看示例程序@mylearningdiaree.blogspot.in/2015/06/…
  • 需要提供appPackage和appActivity,Android应用才能通过Appium启动。

标签: java eclipse testng appium


【解决方案1】:

代码看起来不错。提供应用活动。

【讨论】:

    【解决方案2】:

    您可以在 PC 中使用 .apk 完整路径来设置 Appium,而不是 APP_PACKAGE

    capability.setCapability(MobileCapabilityType.APP, "/full/path/to/app.apk");
    

    【讨论】:

      猜你喜欢
      • 2014-10-01
      • 2015-10-09
      • 2018-09-13
      • 1970-01-01
      • 1970-01-01
      • 2019-03-16
      • 1970-01-01
      • 2017-11-23
      • 1970-01-01
      相关资源
      最近更新 更多