在 Java Android 中的 Cucumber 测试中使用 Appium 调用 UI 元素导致构建失败并出现大量日志

Invoking UI Elements with Appium in Cucumber tests in Java Android results in build failed with alot of logs

我已经配置了黄瓜测试。我的 activity.
工作正常 我还配置了 Appium UI 测试,这些测试在调用时也能正常工作。
现在我想在 Cucumber 测试下使用 Appium 调用我的 activity 的 UI 元素,这些元素是在 stepdefinitions 文件中编写的。

我的build.gradle

// Cucumber for E2E testing
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
androidTestImplementation 'info.cukes:cucumber-android:1.2.5'
androidTestImplementation 'info.cukes:cucumber-picocontainer:1.2.5'

// Appium for DI  -- implementation / compileOnly
implementation 'io.appium:java-client:6.1.0'
implementation files('libs/java-client-6.1.0.jar')
implementation files('libs/selenium-server-standalone-3.13.0.jar')

在 Cucumber steps 文件夹中。我编写了运行良好的测试。通过日志检查。
现在,当我在步骤设置函数中添加 appium 代码以调用 LoginActivity 时,我可以像这样访问 UI 元素:

@Before("@login-scenarios")
public void setUp() throws java.net.MalformedURLException {
System.out.println(Tag + "start - setUp in LoginStepdefs");

org.openqa.selenium.remote.DesiredCapabilities capabilities = new org.openqa.selenium.remote.DesiredCapabilities();
capabilities.setCapability("deviceName", "Emulator Nexus_4_API_22 Android 5.1.1, API 22");
capabilities.setCapability(org.openqa.selenium.remote.CapabilityType.PLATFORM, "Android");
capabilities.setCapability(org.openqa.selenium.remote.CapabilityType.VERSION, "5.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.my.app");
capabilities.setCapability("appActivity", ".activities.MainActivity");
capabilities.setCapability("unicodeKeyboard", true);
capabilities.setCapability("resetKeyboard", true);
driver = new io.appium.java_client.AppiumDriver(new java.net.URL("http://127.0.0.1:1234/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(5, java.util.concurrent.TimeUnit.SECONDS);
}

@After("@login-scenarios")
public void tearDown() {
System.out.println(Tag + "stop - tearDown in LoginStepdefs");
driver.quit();
}

@Given("^Login screen is launched$")
public void loginScreenIsLaunched() {
System.out.println(Tag + "1 - loginScreenIsLaunched");
org.openqa.selenium.support.ui.WebDriverWait wait = new org.openqa.selenium.support.ui.WebDriverWait(driver, 10);
wait.until(org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated(org.openqa.selenium.By.id(com.my.app.utilities.Constant.APP_PACKAGE + signinEmailId)));
}

现在,当我 运行 我的黄瓜测试时。控制台中有很多日志,一段时间后构建失败。

我正在发布日志。我哪里错了??

    AGPBI: {"kind":"warning","text":"Type `javax.imageio.ImageIO` was not found, it is required for default or static interface methods desugaring of `void io.appium.java_client.ios.HasIOSClipboard.setClipboardImage(java.awt.image.BufferedImage)`","sources":[{"file":"/home/sajid/Git/project-android/app/libs/java-client-6.1.0.jar"}],"tool":"D8"}
    AGPBI: {"kind":"warning","text":"Type `javax.xml.bind.DatatypeConverter` was not found, it is required for default or static interface methods desugaring of `byte[] io.appium.java_client.InteractsWithFiles.pullFile(java.lang.String)`","sources":[{"file":"/home/sajid/Git/project-android/app/libs/java-client-6.1.0.jar"}],"tool":"D8"}
    AGPBI: {"kind":"warning","text":"Type `javax.imageio.ImageIO` was not found, it is required for default or static interface methods desugaring of `void io.appium.java_client.ios.HasIOSClipboard.setClipboardImage(java.awt.image.BufferedImage)`","sources":[{"file":"/home/sajid/.gradle/caches/modules-2/files-2.1/io.appium/java-client/6.1.0/6bb22d04886b87f525e4ea352b1940a6ff8c471b/java-client-6.1.0.jar"}],"tool":"D8"}
    AGPBI: {"kind":"warning","text":"Type `javax.xml.bind.DatatypeConverter` was not found, it is required for default or static interface methods desugaring of `byte[] io.appium.java_client.InteractsWithFiles.pullFile(java.lang.String)`","sources":[{"file":"/home/sajid/.gradle/caches/modules-2/files-2.1/io.appium/java-client/6.1.0/6bb22d04886b87f525e4ea352b1940a6ff8c471b/java-client-6.1.0.jar"}],"tool":"D8"}
    JarCode: JSR encountered; reparse using JSRInlinerAdapter
    AGPBI: {"kind":"warning","text":"Type `javax.imageio.ImageIO` was not found, it is required for default or static interface methods desugaring of `void org.eclipse.jetty.util.preventers.AppContextLeakPreventer.prevent(java.lang.ClassLoader)`","sources":[{"file":"/home/sajid/Git/project-android/app/libs/selenium-server-standalone-3.13.0.jar"}],"tool":"D8"}
    AGPBI: {"kind":"warning","text":"Type `org.apache.log.Hierarchy` was not found, it is required for default or static interface methods desugaring of `org.apache.log.Logger org.apache.commons.logging.impl.LogKitLogger.getLogger()`","sources":[{"file":"/home/sajid/Git/project-android/app/libs/selenium-server-standalone-3.13.0.jar"}],"tool":"D8"}
    JarCode: JSR encountered; reparse using JSRInlinerAdapter
    JarCode: JSR encountered; reparse using JSRInlinerAdapter
    JarCode: JSR encountered; reparse using JSRInlinerAdapter
    Expiring Daemon because JVM Tenured space is exhausted
    Daemon will be stopped at the end of the build after running out of JVM memory
    AGPBI: {"kind":"warning","text":"Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `void com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper.\u003cclinit\u003e()`","sources":[{"file":"/home/sajid/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar"}],"tool":"D8"}
    AGPBI: {"kind":"warning","text":"Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `sun.misc.Unsafe com.google.common.cache.Striped64.getUnsafe()`","sources":[{"file":"/home/sajid/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar"}],"tool":"D8"}
    AGPBI: {"kind":"warning","text":"Type `javax.imageio.ImageIO` was not found, it is required for default or static interface methods desugaring of `void org.seleniumhq.jetty9.util.preventers.AppContextLeakPreventer.prevent(java.lang.ClassLoader)`","sources":[{"file":"/home/sajid/Git/project-android/app/libs/selenium-server-standalone-3.13.0.jar"}],"tool":"D8"}
    JarCode: JSR encountered; reparse using JSRInlinerAdapter
    AGPBI: {"kind":"warning","text":"Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `sun.misc.Unsafe com.google.common.hash.LittleEndianByteArray$UnsafeByteArray.getUnsafe()`","sources":[{"file":"/home/sajid/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar"}],"tool":"D8"}
    > Task :app:transformClassesWithDexBuilderForDebug

    Expiring Daemon because JVM Tenured space is exhausted
    AGPBI: {"kind":"warning","text":"Type `javax.swing.JTree` was not found, it is required for default or static interface methods desugaring of `void net.sourceforge.htmlunit.corejs.javascript.tools.debugger.treetable.JTreeTable$TreeTableCellRenderer.updateUI()`","sources":[{"file":"/home/sajid/Git/project-android/app/libs/selenium-server-standalone-3.13.0.jar"}],"tool":"D8"}
    AGPBI: {"kind":"warning","text":"Type `javax.swing.UIManager` was not found, it is required for default or static interface methods desugaring of `void net.sourceforge.htmlunit.corejs.javascript.tools.debugger.treetable.JTreeTable$TreeTableCellRenderer.updateUI()`","sources":[{"file":"/home/sajid/Git/project-android/app/libs/selenium-server-standalone-3.13.0.jar"}],"tool":"D8"}
    JarCode: JSR encountered; reparse using JSRInlinerAdapter
    AGPBI: {"kind":"warning","text":"Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `void com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper.\u003cclinit\u003e()`","sources":[{"file":"/home/sajid/Git/project-android/app/libs/selenium-server-standalone-3.13.0.jar"}],"tool":"D8"}




> Task :app:transformClassesWithDexBuilderForDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process /home/sajid/Git/project-android/app/libs/selenium-server-standalone-3.13.0.jar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 5m 58s
21 actionable tasks: 6 executed, 15 up-to-date
Expiring Daemon because JVM Tenured space is exhausted

您似乎正在尝试构建 Appium-based test with Android SDK and compilation fails as Appium relies on Java SDK

因此您的测试架构应如下所示:

  1. 使用部署在 Android 设备(或模拟器)上的 Android SDK 编译的应用程序
  2. 您的测试是使用部署在您计算机上的 Java SDK 编译的
  3. Android 设备(或模拟器)通过 ADB
  4. 连接到计算机

这样您的测试将控制 Android 设备并执行点击、滑动、键入、断言等。因此您需要重新考虑构建测试项目的方法。

如果您希望 UI 测试成为 Android 应用程序构建的组成部分,请考虑切换到 Espresso, check out How to Get Started with Espresso (Android) 以了解有关 concept/implementation 的更多信息。