Skip to content

Commit

Permalink
refactor!: Migrated all tests to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
RameshBabuPrudhvi committed Jul 25, 2022
1 parent 3127fda commit dcfdbbe
Show file tree
Hide file tree
Showing 60 changed files with 799 additions and 695 deletions.
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ dependencies {
implementation 'commons-io:commons-io:2.11.0'
implementation 'org.slf4j:slf4j-api:1.7.36'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation 'org.hamcrest:hamcrest:2.2'
testImplementation (group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.2.1') {
exclude group: 'org.seleniumhq.selenium'
Expand Down Expand Up @@ -192,7 +193,7 @@ processResources {
}

task xcuiTest( type: Test ) {
useJUnit()
useJUnitPlatform()
testLogging.showStandardStreams = true
testLogging.exceptionFormat = 'full'
filter {
Expand All @@ -207,7 +208,7 @@ task xcuiTest( type: Test ) {
}

task uiAutomationTest( type: Test ) {
useJUnit()
useJUnitPlatform()
testLogging.showStandardStreams = true
testLogging.exceptionFormat = 'full'
filter {
Expand All @@ -223,7 +224,7 @@ task uiAutomationTest( type: Test ) {
}

task miscTest( type: Test ) {
useJUnit()
useJUnitPlatform()
testLogging.showStandardStreams = true
testLogging.exceptionFormat = 'full'
filter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package io.appium.java_client.android;

import static io.appium.java_client.TestUtils.getCenter;
import static io.appium.java_client.touch.WaitOptions.waitOptions;
import static io.appium.java_client.touch.offset.ElementOption.element;
import static java.time.Duration.ofSeconds;
import static org.junit.Assert.assertNotEquals;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.functions.ActionSupplier;
import io.appium.java_client.touch.offset.ElementOption;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;

import java.util.List;

import static io.appium.java_client.TestUtils.getCenter;
import static io.appium.java_client.touch.WaitOptions.waitOptions;
import static io.appium.java_client.touch.offset.ElementOption.element;
import static java.time.Duration.ofSeconds;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {

private final ActionSupplier<AndroidTouchAction> horizontalSwipe = () -> {
Expand All @@ -26,8 +26,8 @@ public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {
Point location = gallery.getLocation();
Point center = getCenter(gallery, location);

ElementOption pressOption = element(images.get(2),-10,center.y - location.y);
ElementOption moveOption = element(gallery, 10,center.y - location.y);
ElementOption pressOption = element(images.get(2), -10, center.y - location.y);
ElementOption moveOption = element(gallery, 10, center.y - location.y);

return new AndroidTouchAction(driver)
.press(pressOption)
Expand All @@ -37,15 +37,16 @@ public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {
};

private final ActionSupplier<AndroidTouchAction> verticalSwiping = () ->
new AndroidTouchAction(driver)
.press(element(driver.findElement(AppiumBy.accessibilityId("Gallery"))))
new AndroidTouchAction(driver)
.press(element(driver.findElement(AppiumBy.accessibilityId("Gallery"))))

.waitAction(waitOptions(ofSeconds(2)))
.waitAction(waitOptions(ofSeconds(2)))

.moveTo(element(driver.findElement(AppiumBy.accessibilityId("Auto Complete"))))
.release();
.moveTo(element(driver.findElement(AppiumBy.accessibilityId("Auto Complete"))))
.release();

@Test public void horizontalSwipingWithSupplier() {
@Test
public void horizontalSwipingWithSupplier() {
Activity activity = new Activity("io.appium.android.apis", ".view.Gallery1");
driver.startActivity(activity);
WebElement gallery = driver.findElement(By.id("io.appium.android.apis:id/gallery"));
Expand All @@ -58,7 +59,8 @@ public class AndroidAbilityToUseSupplierTest extends BaseAndroidTest {
gallery.findElements(AppiumBy.className("android.widget.ImageView")).size());
}

@Test public void verticalSwipingWithSupplier() throws Exception {
@Test
public void verticalSwipingWithSupplier() throws Exception {
driver.resetApp();
driver.findElement(AppiumBy.accessibilityId("Views")).click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,54 @@

package io.appium.java_client.android;

import static org.junit.Assert.assertEquals;

import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AndroidActivityTest extends BaseAndroidTest {

@Before public void setUp() {
@BeforeEach
public void setUp() {
Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
driver.startActivity(activity);
}

@Test public void startActivityInThisAppTestCase() {
@Test
public void startActivityInThisAppTestCase() {
Activity activity = new Activity("io.appium.android.apis",
".accessibility.AccessibilityNodeProviderActivity");
".accessibility.AccessibilityNodeProviderActivity");
driver.startActivity(activity);
assertEquals(driver.currentActivity(),
".accessibility.AccessibilityNodeProviderActivity");
".accessibility.AccessibilityNodeProviderActivity");
}

@Test public void startActivityWithWaitingAppTestCase() {
@Test
public void startActivityWithWaitingAppTestCase() {
final Activity activity = new Activity("io.appium.android.apis",
".accessibility.AccessibilityNodeProviderActivity")
".accessibility.AccessibilityNodeProviderActivity")
.setAppWaitPackage("io.appium.android.apis")
.setAppWaitActivity(".accessibility.AccessibilityNodeProviderActivity");
driver.startActivity(activity);
assertEquals(driver.currentActivity(),
".accessibility.AccessibilityNodeProviderActivity");
".accessibility.AccessibilityNodeProviderActivity");
}

@Test public void startActivityInNewAppTestCase() {
@Test
public void startActivityInNewAppTestCase() {
Activity activity = new Activity("com.android.settings", ".Settings");
driver.startActivity(activity);
assertEquals(driver.currentActivity(), ".Settings");
driver.pressKey(new KeyEvent(AndroidKey.BACK));
assertEquals(driver.currentActivity(), ".ApiDemos");
}

@Test public void startActivityInNewAppTestCaseWithoutClosingApp() {
@Test
public void startActivityInNewAppTestCaseWithoutClosingApp() {
Activity activity = new Activity("io.appium.android.apis",
".accessibility.AccessibilityNodeProviderActivity");
".accessibility.AccessibilityNodeProviderActivity");
driver.startActivity(activity);
assertEquals(driver.currentActivity(), ".accessibility.AccessibilityNodeProviderActivity");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@

package io.appium.java_client.android;

import static org.junit.Assert.assertNotEquals;
import org.junit.jupiter.api.Test;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class AndroidAppStringsTest extends BaseAndroidTest {

@Test public void getAppStrings() {
@Test
public void getAppStrings() {
assertNotEquals(0, driver.getAppStringMap().size());
}

@Test public void getGetAppStringsUsingLang() {
@Test
public void getGetAppStringsUsingLang() {
assertNotEquals(0, driver.getAppStringMap("en").size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

package io.appium.java_client.android;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import io.appium.java_client.android.connection.ConnectionState;
import io.appium.java_client.android.connection.ConnectionStateBuilder;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class AndroidConnectionTest extends BaseAndroidTest {

@Test
Expand Down
31 changes: 20 additions & 11 deletions src/test/java/io/appium/java_client/android/AndroidContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,48 @@

package io.appium.java_client.android;

import static org.junit.Assert.assertEquals;

import io.appium.java_client.NoSuchContextException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class AndroidContextTest extends BaseAndroidTest {

@BeforeClass public static void beforeClass2() throws Exception {
@BeforeAll
public static void beforeClass2() throws Exception {
Activity activity = new Activity("io.appium.android.apis", ".view.WebView1");
driver.startActivity(activity);
Thread.sleep(20000);
}

@Test public void testGetContext() {
@Test
public void testGetContext() {
assertEquals("NATIVE_APP", driver.getContext());
}

@Test public void testGetContextHandles() {
@Test
public void testGetContextHandles() {
assertEquals(driver.getContextHandles().size(), 2);
}

@Test public void testSwitchContext() {
@Test
public void testSwitchContext() {
driver.getContextHandles();
driver.context("WEBVIEW_io.appium.android.apis");
assertEquals(driver.getContext(), "WEBVIEW_io.appium.android.apis");
driver.context("NATIVE_APP");
assertEquals(driver.getContext(), "NATIVE_APP");
}

@Test(expected = NoSuchContextException.class) public void testContextError() {
driver.context("Planet of the Ape-ium");
assertEquals("Planet of the Ape-ium", driver.getContext());
@Test
public void testContextError() {
assertThrows(NoSuchContextException.class,
() -> {
driver.context("Planet of the Ape-ium");
assertEquals("Planet of the Ape-ium", driver.getContext());
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.appium.java_client.AppiumBy;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class AndroidDataMatcherTest extends BaseEspressoTest {

@Test
public void testFindByDataMatcher() {
final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions
.elementToBeClickable(AppiumBy.accessibilityId("Graphics")));
.elementToBeClickable(AppiumBy.accessibilityId("Graphics")));
driver.findElement(AppiumBy.accessibilityId("Graphics")).click();

String selector = new Json().toJson(ImmutableMap.of(
"name", "hasEntry",
"args", ImmutableList.of("title", "Sweep")
"name", "hasEntry",
"args", ImmutableList.of("title", "Sweep")
));

assertNotNull(wait.until(ExpectedConditions
.presenceOfElementLocated(AppiumBy.androidDataMatcher(selector))));
.presenceOfElementLocated(AppiumBy.androidDataMatcher(selector))));
}
}
17 changes: 6 additions & 11 deletions src/test/java/io/appium/java_client/android/AndroidDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,11 @@

package io.appium.java_client.android;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import io.appium.java_client.appmanagement.ApplicationState;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.ScreenOrientation;
import org.openqa.selenium.html5.Location;

Expand All @@ -39,6 +29,11 @@
import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.jupiter.api.Assertions.*;

public class AndroidDriverTest extends BaseAndroidTest {

@Test
Expand Down

0 comments on commit dcfdbbe

Please sign in to comment.