I have configured cucumber tests. Working fine for my activity.
I have also configured Appium UI Tests which are also working fine when invoked.
Now i want to invoke my activity's UI Elements with Appium under Cucumber tests which are written in stepdefinitions file.
My 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')
In Cucumber steps folder. I have written tests which are working fine. Checked through logs.
Now when i add code of appium in steps setup function to invoke LoginActivity and i can access UI elements like this:
@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)));
}
Now when i run my cucumber tests. Alot of logs in console and after some time build failed.
I am posting logs. Where i am wrong??
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
It appears that you're trying to build an Appium-based test with Android SDK and compilation fails as Appium relies on Java SDK
So the architecture of your test should look like:
This way your tests will control Android device and perform clicks, swipes, typing, assertions, etc. So you need to reconsider the approach of building your test project.
If you want UI tests to be an integral part of your Android application build consider switching to Espresso, check out How to Get Started with Espresso (Android) to learn more about the concept/implementation.