Skip to content

Commit

Permalink
Got the AppCenter Appium Android test working
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardKrupa-Cap committed Jul 5, 2023
1 parent 7102720 commit 895d7a2
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 100 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ yarn-error.log

# Maven testing
target/
android/app/src/main/assets/
android/app/src/main/res
14 changes: 14 additions & 0 deletions build-android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

mkdir -p ./android/app/src/main/assets

npx react-native bundle \
--dev false \
--platform android \
--entry-file index.js \
--bundle-output ./android/app/src/main/assets/index.android.bundle \
--assets-dest ./android/app/src/main/res

cd android
./gradlew assembleDebug
87 changes: 81 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.capgemini.gjk.training</groupId>
<artifactId>app-appium-test</artifactId>
Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.5.1</version>
<version>7.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -24,18 +24,93 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.appcenter</groupId>
<artifactId>appium-test-extension</artifactId>
<version>1.6</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>prepare-for-upload</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/dependency-jars/
</outputDirectory>
<useRepositoryLayout>true</useRepositoryLayout>
<copyPom>true</copyPom>
<addParentPoms>true</addParentPoms>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>generate-pom</id>
<phase>package</phase>
<goals>
<goal>effective-pom</goal>
</goals>
<configuration>
<output>${project.build.directory}/upload/pom.xml</output>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-testclasses</id>
<phase>package</phase>
<goals>
<goal>testResources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/test-classes</outputDirectory>
<resources>
<resource>
<directory>
${project.build.testOutputDirectory}
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
10 changes: 10 additions & 0 deletions run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
mvn -DskipTests -P prepare-for-upload package

appcenter test run appium \
--app "gerard-krupa-u0hs/TrainingApp" \
--devices "gerard-krupa-u0hs/demo" \
--app-path ./android/app/build/outputs/apk/debug/app-debug.apk \
--test-series "master" \
--locale "en_US" \
--build-dir target/upload
72 changes: 0 additions & 72 deletions src/test/java/AppleSimulatorTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,69 +1,77 @@
import io.appium.java_client.android.AndroidDriver;
import com.microsoft.appcenter.appium.EnhancedAndroidDriver;
import com.microsoft.appcenter.appium.Factory;
import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import io.appium.java_client.service.local.flags.GeneralServerFlag;
import org.junit.*;

import io.appium.java_client.android.options.UiAutomator2Options;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import org.junit.*;
import org.junit.rules.TestWatcher;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.concurrent.TimeUnit;

public class RemoteAndroidTest {

public class AndroidEmulatorTest {
@Rule
public TestWatcher watcher = Factory.createWatcher();

private EnhancedAndroidDriver<WebElement> driver;

private AndroidDriver driver;
private static AppiumDriverLocalService appiumDriverLocalService;

@BeforeClass
public static void setupClass() throws MalformedURLException {
appiumDriverLocalService = new AppiumServiceBuilder()
.usingPort(4723)
.build();
appiumDriverLocalService.start();
// appiumDriverLocalService = new AppiumServiceBuilder()
// .usingPort(4723)
// .build();
// appiumDriverLocalService.start();

}

@AfterClass
public static void tearDownClass() {
if (appiumDriverLocalService != null) {
appiumDriverLocalService.stop();
}
// if (appiumDriverLocalService != null) {
// appiumDriverLocalService.stop();
// }
}

@Before
public void setup() throws MalformedURLException {
UiAutomator2Options options = new UiAutomator2Options()
.setPlatformName("Android")
.setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2)
.setApp("android/app/build/outputs/apk/debug/app-debug.apk");

driver = new AndroidDriver(new URL("http://127.0.0.1:4723"), options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setPlatform(Platform.ANDROID);
capabilities.setCapability("automationName", AutomationName.ANDROID_UIAUTOMATOR2);
driver = Factory.createAndroidDriver(new URL("http://127.0.0.1:4723"), capabilities);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}

@After
public void tearDown() {
if (driver != null) {
driver.label("Stopping App");
driver.quit();
}
}

@Test
public void theButtonsNavigate() {
driver.label("Selecting Beer tag");
driver.findElement(By.id("test:id/Beer")).click();
Assert.assertNotNull(driver.findElement(By.id("test:id/tagged-image")));
driver.label("Clicking the home button");
driver.findElement(By.id("test:id/navigate-home")).click();
Assert.assertNotNull(driver.findElement(By.id("test:id/Beer")));
}

@Test
public void backGoesBackHome() {
driver.label("Selecting Beer tag");
driver.findElement(By.id("test:id/Beer")).click();
Assert.assertNotNull(driver.findElement(By.id("test:id/tagged-image")));
driver.label("Clicking the back button");
driver.navigate().back();
Assert.assertNotNull(driver.findElement(By.id("test:id/Beer")));
}
Expand Down

0 comments on commit 895d7a2

Please sign in to comment.