Skip to content

Commit

Permalink
test: Run tests on the JUnit Jupiter Platform (#1721)
Browse files Browse the repository at this point in the history
  • Loading branch information
RameshBabuPrudhvi committed Jul 28, 2022
1 parent 3127fda commit da326d6
Show file tree
Hide file tree
Showing 69 changed files with 429 additions and 424 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ 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:5.9.0'
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 +192,7 @@ processResources {
}

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

task uiAutomationTest( type: Test ) {
useJUnit()
useJUnitPlatform()
testLogging.showStandardStreams = true
testLogging.exceptionFormat = 'full'
filter {
Expand All @@ -223,7 +223,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
Expand Up @@ -4,12 +4,12 @@
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 static org.junit.jupiter.api.Assertions.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;
Expand Down
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.assertEquals;
import static org.junit.jupiter.api.Assertions.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;

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package io.appium.java_client.android;

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

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class AndroidAppStringsTest extends BaseAndroidTest {

Expand Down
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 static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.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;

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

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

package io.appium.java_client.android;

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

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;

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);
Expand All @@ -46,9 +47,12 @@ public class AndroidContextTest extends BaseAndroidTest {
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,14 +19,14 @@
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 {

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

package io.appium.java_client.android;

import static org.hamcrest.MatcherAssert.assertThat;
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 static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@

package io.appium.java_client.android;

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

import io.appium.java_client.AppiumBy;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebElement;

public class AndroidElementTest extends BaseAndroidTest {

@Before public void setup() {
@BeforeEach public void setup() {
Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
driver.startActivity(activity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import static java.time.Duration.ofMillis;
import static java.time.Duration.ofSeconds;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.StringContains.containsString;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import io.appium.java_client.functions.AppiumFunction;
import io.appium.java_client.functions.ExpectedCondition;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
Expand Down Expand Up @@ -65,15 +66,15 @@ public class AndroidFunctionTest extends BaseAndroidTest {
return null;
};

@BeforeClass
@BeforeAll
public static void startWebViewActivity() {
if (driver != null) {
Activity activity = new Activity("io.appium.android.apis", ".view.WebView1");
driver.startActivity(activity);
}
}

@Before
@BeforeEach
public void setUp() {

driver.context("NATIVE_APP");
Expand Down Expand Up @@ -127,17 +128,19 @@ public void complexWaitingTestWithPreCondition() {
assertThat("There should be 3 calls", calls.size(), is(3));
}

@Test(expected = TimeoutException.class)
@Test
public void nullPointerExceptionSafetyTestWithPrecondition() {
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("Fake_context"))
.withTimeout(ofSeconds(30)).pollingEvery(ofMillis(500));
assertTrue(wait.until(searchingFunction.compose(contextFunction)).size() > 0);
assertThrows(TimeoutException.class,
() -> assertTrue(wait.until(searchingFunction.compose(contextFunction)).size() > 0));
}

@Test(expected = TimeoutException.class)
@Test
public void nullPointerExceptionSafetyTestWithPostConditions() {
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("Fake_context"))
.withTimeout(ofSeconds(30)).pollingEvery(ofMillis(500));
assertTrue(wait.until(contextFunction.andThen(searchingFunction).andThen(filteringFunction)).size() > 0);
assertThrows(TimeoutException.class,
() -> assertTrue(wait.until(contextFunction.andThen(searchingFunction).andThen(filteringFunction)).size() > 0));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.appium.java_client.android;

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

import org.apache.commons.lang3.time.DurationFormatUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.util.concurrent.Semaphore;
Expand All @@ -25,9 +25,9 @@ public void verifyLogcatListenerCanBeAssigned() {
messageSemaphore.acquire();
// This is needed for pushing some internal log messages
driver.runAppInBackground(Duration.ofSeconds(1));
assertTrue(String.format("Didn't receive any log message after %s timeout",
DurationFormatUtils.formatDuration(timeout.toMillis(), "H:mm:ss", true)),
messageSemaphore.tryAcquire(timeout.toMillis(), TimeUnit.MILLISECONDS));
assertTrue(messageSemaphore.tryAcquire(timeout.toMillis(), TimeUnit.MILLISECONDS),
String.format("Didn't receive any log message after %s timeout",
DurationFormatUtils.formatDuration(timeout.toMillis(), "H:mm:ss", true)));
} catch (InterruptedException e) {
throw new IllegalStateException(e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriverException;

import java.time.Duration;

public class AndroidScreenRecordTest extends BaseAndroidTest {

@Before
@BeforeEach
public void setUp() {
Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
driver.startActivity(activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

package io.appium.java_client.android;

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

import io.appium.java_client.AppiumBy;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class AndroidSearchingTest extends BaseAndroidTest {

@Before
@BeforeEach
public void setup() {
Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
driver.startActivity(activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import static io.appium.java_client.touch.offset.ElementOption.element;
import static io.appium.java_client.touch.offset.PointOption.point;
import static java.time.Duration.ofSeconds;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.MultiTouchAction;
import io.appium.java_client.TouchAction;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
Expand All @@ -24,7 +24,7 @@

public class AndroidTouchTest extends BaseAndroidTest {

@Before
@BeforeEach
public void setUp() {
driver.resetApp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
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 AndroidViewMatcherTest extends BaseEspressoTest {

Expand Down

0 comments on commit da326d6

Please sign in to comment.