diff --git a/build.gradle b/build.gradle index 016aeaefe..eee2cdf67 100644 --- a/build.gradle +++ b/build.gradle @@ -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' @@ -192,7 +192,7 @@ processResources { } task xcuiTest( type: Test ) { - useJUnit() + useJUnitPlatform() testLogging.showStandardStreams = true testLogging.exceptionFormat = 'full' filter { @@ -207,7 +207,7 @@ task xcuiTest( type: Test ) { } task uiAutomationTest( type: Test ) { - useJUnit() + useJUnitPlatform() testLogging.showStandardStreams = true testLogging.exceptionFormat = 'full' filter { @@ -223,7 +223,7 @@ task uiAutomationTest( type: Test ) { } task miscTest( type: Test ) { - useJUnit() + useJUnitPlatform() testLogging.showStandardStreams = true testLogging.exceptionFormat = 'full' filter { diff --git a/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java b/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java index 0626c4f9d..38fa40b93 100644 --- a/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java @@ -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; diff --git a/src/test/java/io/appium/java_client/android/AndroidActivityTest.java b/src/test/java/io/appium/java_client/android/AndroidActivityTest.java index 0acfd0b49..86377ac11 100644 --- a/src/test/java/io/appium/java_client/android/AndroidActivityTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidActivityTest.java @@ -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); } diff --git a/src/test/java/io/appium/java_client/android/AndroidAppStringsTest.java b/src/test/java/io/appium/java_client/android/AndroidAppStringsTest.java index 87eafb978..9aaeb88b3 100644 --- a/src/test/java/io/appium/java_client/android/AndroidAppStringsTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidAppStringsTest.java @@ -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 { diff --git a/src/test/java/io/appium/java_client/android/AndroidConnectionTest.java b/src/test/java/io/appium/java_client/android/AndroidConnectionTest.java index f1eb1043a..88e1c1d6e 100644 --- a/src/test/java/io/appium/java_client/android/AndroidConnectionTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidConnectionTest.java @@ -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 diff --git a/src/test/java/io/appium/java_client/android/AndroidContextTest.java b/src/test/java/io/appium/java_client/android/AndroidContextTest.java index 60e423fe8..57f5895d8 100644 --- a/src/test/java/io/appium/java_client/android/AndroidContextTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidContextTest.java @@ -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); @@ -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()); + }); } } diff --git a/src/test/java/io/appium/java_client/android/AndroidDataMatcherTest.java b/src/test/java/io/appium/java_client/android/AndroidDataMatcherTest.java index afe0b7653..3db8ade05 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDataMatcherTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDataMatcherTest.java @@ -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 { diff --git a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java index c94669138..145bd32dc 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -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; diff --git a/src/test/java/io/appium/java_client/android/AndroidElementTest.java b/src/test/java/io/appium/java_client/android/AndroidElementTest.java index 911dd8150..8ce9fd2fc 100644 --- a/src/test/java/io/appium/java_client/android/AndroidElementTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidElementTest.java @@ -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); } diff --git a/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java b/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java index e86a58c05..735d0aeda 100644 --- a/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidFunctionTest.java @@ -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; @@ -65,7 +66,7 @@ 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"); @@ -73,7 +74,7 @@ public static void startWebViewActivity() { } } - @Before + @BeforeEach public void setUp() { driver.context("NATIVE_APP"); @@ -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 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 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)); } } diff --git a/src/test/java/io/appium/java_client/android/AndroidLogcatListenerTest.java b/src/test/java/io/appium/java_client/android/AndroidLogcatListenerTest.java index 5cfdee5c2..f1045c8cf 100644 --- a/src/test/java/io/appium/java_client/android/AndroidLogcatListenerTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidLogcatListenerTest.java @@ -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; @@ -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 { diff --git a/src/test/java/io/appium/java_client/android/AndroidScreenRecordTest.java b/src/test/java/io/appium/java_client/android/AndroidScreenRecordTest.java index be34c67b9..63510fc26 100644 --- a/src/test/java/io/appium/java_client/android/AndroidScreenRecordTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidScreenRecordTest.java @@ -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); diff --git a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java index e96ac64e7..262b50c61 100644 --- a/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidSearchingTest.java @@ -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); diff --git a/src/test/java/io/appium/java_client/android/AndroidTouchTest.java b/src/test/java/io/appium/java_client/android/AndroidTouchTest.java index e03485bbf..958da3140 100644 --- a/src/test/java/io/appium/java_client/android/AndroidTouchTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidTouchTest.java @@ -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; @@ -24,7 +24,7 @@ public class AndroidTouchTest extends BaseAndroidTest { - @Before + @BeforeEach public void setUp() { driver.resetApp(); } diff --git a/src/test/java/io/appium/java_client/android/AndroidViewMatcherTest.java b/src/test/java/io/appium/java_client/android/AndroidViewMatcherTest.java index 191055553..852723694 100644 --- a/src/test/java/io/appium/java_client/android/AndroidViewMatcherTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidViewMatcherTest.java @@ -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 { diff --git a/src/test/java/io/appium/java_client/android/BaseAndroidTest.java b/src/test/java/io/appium/java_client/android/BaseAndroidTest.java index b6a4e5421..3e75fe6f1 100644 --- a/src/test/java/io/appium/java_client/android/BaseAndroidTest.java +++ b/src/test/java/io/appium/java_client/android/BaseAndroidTest.java @@ -20,8 +20,8 @@ import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServiceBuilder; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import static io.appium.java_client.TestResources.apiDemosApk; @@ -35,7 +35,7 @@ public class BaseAndroidTest { /** * initialization. */ - @BeforeClass public static void beforeClass() { + @BeforeAll public static void beforeClass() { service = new AppiumServiceBuilder() .withIPAddress("127.0.0.1") .usingPort(PORT) @@ -52,7 +52,7 @@ public class BaseAndroidTest { /** * finishing. */ - @AfterClass public static void afterClass() { + @AfterAll public static void afterClass() { if (driver != null) { driver.quit(); } diff --git a/src/test/java/io/appium/java_client/android/BaseEspressoTest.java b/src/test/java/io/appium/java_client/android/BaseEspressoTest.java index 6375ff58e..cfc690021 100644 --- a/src/test/java/io/appium/java_client/android/BaseEspressoTest.java +++ b/src/test/java/io/appium/java_client/android/BaseEspressoTest.java @@ -19,8 +19,8 @@ import io.appium.java_client.android.options.EspressoOptions; import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import static io.appium.java_client.TestResources.apiDemosApk; @@ -32,7 +32,7 @@ public class BaseEspressoTest { /** * initialization. */ - @BeforeClass public static void beforeClass() { + @BeforeAll public static void beforeClass() { service = AppiumDriverLocalService.buildDefaultService(); service.start(); @@ -51,7 +51,7 @@ public class BaseEspressoTest { /** * finishing. */ - @AfterClass public static void afterClass() { + @AfterAll public static void afterClass() { if (driver != null) { driver.quit(); } diff --git a/src/test/java/io/appium/java_client/android/BatteryTest.java b/src/test/java/io/appium/java_client/android/BatteryTest.java index a48ecc092..619fafac1 100644 --- a/src/test/java/io/appium/java_client/android/BatteryTest.java +++ b/src/test/java/io/appium/java_client/android/BatteryTest.java @@ -21,7 +21,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BatteryTest extends BaseAndroidTest { diff --git a/src/test/java/io/appium/java_client/android/ClipboardTest.java b/src/test/java/io/appium/java_client/android/ClipboardTest.java index 0e58ae3b6..cf9ee8581 100644 --- a/src/test/java/io/appium/java_client/android/ClipboardTest.java +++ b/src/test/java/io/appium/java_client/android/ClipboardTest.java @@ -16,14 +16,14 @@ package io.appium.java_client.android; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ClipboardTest extends BaseAndroidTest { - @Before public void setUp() { + @BeforeEach public void setUp() { driver.resetApp(); } diff --git a/src/test/java/io/appium/java_client/android/ExecuteCDPCommandTest.java b/src/test/java/io/appium/java_client/android/ExecuteCDPCommandTest.java index 634a9a516..fc1a138c6 100644 --- a/src/test/java/io/appium/java_client/android/ExecuteCDPCommandTest.java +++ b/src/test/java/io/appium/java_client/android/ExecuteCDPCommandTest.java @@ -20,9 +20,9 @@ import io.appium.java_client.remote.MobileBrowserType; import io.appium.java_client.remote.MobileCapabilityType; import io.appium.java_client.service.local.AppiumDriverLocalService; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; @@ -34,7 +34,7 @@ import java.util.Map; import static java.time.Duration.ofSeconds; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class ExecuteCDPCommandTest { @@ -49,7 +49,7 @@ public class ExecuteCDPCommandTest { /** * The setting up. */ - @Before + @BeforeEach public void setUp() { service = AppiumDriverLocalService.buildDefaultService(); service.start(); @@ -66,7 +66,7 @@ public void setUp() { /** * finishing. */ - @After + @AfterEach public void tearDown() { if (driver != null) { driver.quit(); diff --git a/src/test/java/io/appium/java_client/android/ExecuteDriverScriptTest.java b/src/test/java/io/appium/java_client/android/ExecuteDriverScriptTest.java index 5b8da2938..d8bf5a65d 100644 --- a/src/test/java/io/appium/java_client/android/ExecuteDriverScriptTest.java +++ b/src/test/java/io/appium/java_client/android/ExecuteDriverScriptTest.java @@ -19,16 +19,16 @@ import io.appium.java_client.driverscripts.ScriptOptions; import io.appium.java_client.driverscripts.ScriptType; import io.appium.java_client.driverscripts.ScriptValue; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; import java.util.Map; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class ExecuteDriverScriptTest extends BaseAndroidTest { diff --git a/src/test/java/io/appium/java_client/android/FingerPrintTest.java b/src/test/java/io/appium/java_client/android/FingerPrintTest.java index 42d696b58..a32c482fe 100644 --- a/src/test/java/io/appium/java_client/android/FingerPrintTest.java +++ b/src/test/java/io/appium/java_client/android/FingerPrintTest.java @@ -20,12 +20,12 @@ import io.appium.java_client.android.options.UiAutomator2Options; import io.appium.java_client.service.local.AppiumDriverLocalService; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +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.NoSuchElementException; import org.openqa.selenium.WebElement; @@ -48,7 +48,7 @@ private static void initDriver() { /** * initialization. */ - @BeforeClass public static void beforeClass() { + @BeforeAll public static void beforeClass() { service = AppiumDriverLocalService.buildDefaultService(); service.start(); @@ -60,7 +60,7 @@ private static void initDriver() { /** * finishing. */ - @AfterClass public static void afterClass() { + @AfterAll public static void afterClass() { if (service != null) { service.stop(); } @@ -98,7 +98,7 @@ private void clickOnSecurity() { /** * enable system security which is required for finger print activation. */ - @Before + @BeforeEach public void before() { initDriver(); clickOnSecurity(); @@ -123,14 +123,14 @@ public void fingerPrintTest() { try { clickNext(); } catch (Exception e) { - Assert.fail("fingerprint command fail to execute"); + Assertions.fail("fingerprint command fail to execute"); } } /** * disabling pin lock mode. */ - @After + @AfterEach public void after() { driver.quit(); diff --git a/src/test/java/io/appium/java_client/android/ImagesComparisonTest.java b/src/test/java/io/appium/java_client/android/ImagesComparisonTest.java index 388b32cf1..adc8795ea 100644 --- a/src/test/java/io/appium/java_client/android/ImagesComparisonTest.java +++ b/src/test/java/io/appium/java_client/android/ImagesComparisonTest.java @@ -16,11 +16,11 @@ package io.appium.java_client.android; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import io.appium.java_client.imagecomparison.FeatureDetector; import io.appium.java_client.imagecomparison.FeaturesMatchingOptions; @@ -31,7 +31,7 @@ import io.appium.java_client.imagecomparison.SimilarityMatchingOptions; import io.appium.java_client.imagecomparison.SimilarityMatchingResult; import org.apache.commons.codec.binary.Base64; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openqa.selenium.OutputType; public class ImagesComparisonTest extends BaseAndroidTest { diff --git a/src/test/java/io/appium/java_client/android/IntentTest.java b/src/test/java/io/appium/java_client/android/IntentTest.java index ea10811e6..a25e6a0bf 100644 --- a/src/test/java/io/appium/java_client/android/IntentTest.java +++ b/src/test/java/io/appium/java_client/android/IntentTest.java @@ -1,14 +1,14 @@ package io.appium.java_client.android; import static io.appium.java_client.TestResources.intentExampleApk; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import io.appium.java_client.android.options.UiAutomator2Options; import io.appium.java_client.service.local.AppiumDriverLocalService; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import java.util.function.Predicate; @@ -20,7 +20,7 @@ public class IntentTest { /** * initialization. */ - @BeforeClass public static void beforeClass() { + @BeforeAll public static void beforeClass() { service = AppiumDriverLocalService.buildDefaultService(); service.start(); @@ -37,7 +37,7 @@ public class IntentTest { /** * finishing. */ - @AfterClass public static void afterClass() { + @AfterAll public static void afterClass() { if (driver != null) { driver.quit(); } diff --git a/src/test/java/io/appium/java_client/android/KeyCodeTest.java b/src/test/java/io/appium/java_client/android/KeyCodeTest.java index 9a6b8ed1e..7a3ae47e3 100644 --- a/src/test/java/io/appium/java_client/android/KeyCodeTest.java +++ b/src/test/java/io/appium/java_client/android/KeyCodeTest.java @@ -16,22 +16,22 @@ package io.appium.java_client.android; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import io.appium.java_client.android.nativekey.AndroidKey; import io.appium.java_client.android.nativekey.KeyEvent; import io.appium.java_client.android.nativekey.KeyEventFlag; import io.appium.java_client.android.nativekey.KeyEventMetaModifier; -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; public class KeyCodeTest extends BaseAndroidTest { private static final By PRESS_RESULT_VIEW = By.id("io.appium.android.apis:id/text"); - @Before + @BeforeEach public void setUp() { final Activity activity = new Activity(driver.getCurrentPackage(), ".text.KeyEventText"); driver.startActivity(activity); diff --git a/src/test/java/io/appium/java_client/android/LogEventTest.java b/src/test/java/io/appium/java_client/android/LogEventTest.java index ab4b0350a..a473fbe32 100644 --- a/src/test/java/io/appium/java_client/android/LogEventTest.java +++ b/src/test/java/io/appium/java_client/android/LogEventTest.java @@ -16,15 +16,15 @@ package io.appium.java_client.android; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import io.appium.java_client.serverevents.CommandEvent; import io.appium.java_client.serverevents.CustomEvent; import io.appium.java_client.serverevents.TimedEvent; import io.appium.java_client.serverevents.ServerEvents; import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LogEventTest extends BaseAndroidTest { diff --git a/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java b/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java index 293479e53..dde09bbc1 100644 --- a/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java +++ b/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java @@ -1,10 +1,9 @@ package io.appium.java_client.android; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.openqa.selenium.By.id; -import org.junit.Test; - +import org.junit.jupiter.api.Test; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.WebDriverWait; diff --git a/src/test/java/io/appium/java_client/android/SettingTest.java b/src/test/java/io/appium/java_client/android/SettingTest.java index 52963e566..380efa1cb 100644 --- a/src/test/java/io/appium/java_client/android/SettingTest.java +++ b/src/test/java/io/appium/java_client/android/SettingTest.java @@ -1,14 +1,14 @@ package io.appium.java_client.android; import io.appium.java_client.Setting; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.time.Duration; import java.util.EnumMap; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SettingTest extends BaseAndroidTest { diff --git a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java index 85b91ab30..6c2bf0857 100644 --- a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java +++ b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java @@ -1,12 +1,12 @@ package io.appium.java_client.android; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import io.appium.java_client.AppiumBy; -import org.junit.After; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.DeviceRotation; import org.openqa.selenium.WebElement; @@ -17,7 +17,7 @@ public class UIAutomator2Test extends BaseAndroidTest { - @After + @AfterEach public void afterMethod() { driver.rotate(new DeviceRotation(0, 0, 0)); } @@ -55,7 +55,8 @@ public void testPortraitUpsideDown() { /** * ignoring. */ - @Ignore + @Disabled + @Test public void testToastMSGIsDisplayed() { final WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); Activity activity = new Activity("io.appium.android.apis", ".view.PopupMenu1"); diff --git a/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java b/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java index 8b842ee32..ab10f1ec1 100644 --- a/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java +++ b/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java @@ -35,17 +35,17 @@ import io.appium.java_client.safari.options.WebrtcData; import io.appium.java_client.windows.options.PowerShellData; import io.appium.java_client.windows.options.WindowsOptions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openqa.selenium.Platform; import java.net.MalformedURLException; import java.net.URL; import java.time.Duration; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; @SuppressWarnings("ConstantConditions") public class OptionsBuildingTest { diff --git a/src/test/java/io/appium/java_client/events/EventsFiringTest.java b/src/test/java/io/appium/java_client/events/EventsFiringTest.java index f6d0d2890..cd00dce37 100644 --- a/src/test/java/io/appium/java_client/events/EventsFiringTest.java +++ b/src/test/java/io/appium/java_client/events/EventsFiringTest.java @@ -17,20 +17,20 @@ package io.appium.java_client.events; import io.appium.java_client.events.stubs.EmptyWebDriver; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.events.EventFiringDecorator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class EventsFiringTest { private final WebDriver emptyWebDriver = new EmptyWebDriver(); private CustomListener listener; private WebDriver decorated; - @Before + @BeforeEach public void beforeTest() { listener = new CustomListener(); decorated = new EventFiringDecorator(listener).decorate(emptyWebDriver); diff --git a/src/test/java/io/appium/java_client/internal/ConfigTest.java b/src/test/java/io/appium/java_client/internal/ConfigTest.java index d9185dc5f..4ae2feb6c 100644 --- a/src/test/java/io/appium/java_client/internal/ConfigTest.java +++ b/src/test/java/io/appium/java_client/internal/ConfigTest.java @@ -2,10 +2,11 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ConfigTest { private static final String EXISTING_KEY = "selenium.version"; @@ -17,14 +18,16 @@ public void verifyGettingExistingValue() { assertTrue(Config.main().getOptionalValue(EXISTING_KEY, String.class).isPresent()); } - @Test(expected = IllegalArgumentException.class) + @Test public void verifyGettingNonExistingValue() { - assertThat(Config.main().getValue(MISSING_KEY, String.class).length(), greaterThan(0)); + assertThrows(IllegalArgumentException.class, + () -> assertThat(Config.main().getValue(MISSING_KEY, String.class).length(), greaterThan(0))); } - @Test(expected = ClassCastException.class) + @Test public void verifyGettingExistingValueWithWrongClass() { - assertThat(Config.main().getValue(EXISTING_KEY, Integer.class), greaterThan(0)); + assertThrows(ClassCastException.class, + () -> assertThat(Config.main().getValue(EXISTING_KEY, Integer.class), greaterThan(0))); } @Test diff --git a/src/test/java/io/appium/java_client/ios/AppIOSTest.java b/src/test/java/io/appium/java_client/ios/AppIOSTest.java index e84ae96fa..b049a15bb 100644 --- a/src/test/java/io/appium/java_client/ios/AppIOSTest.java +++ b/src/test/java/io/appium/java_client/ios/AppIOSTest.java @@ -1,7 +1,7 @@ package io.appium.java_client.ios; import io.appium.java_client.ios.options.XCUITestOptions; -import org.junit.BeforeClass; +import org.junit.jupiter.api.BeforeAll; import org.openqa.selenium.SessionNotCreatedException; import java.time.Duration; @@ -12,7 +12,7 @@ public class AppIOSTest extends BaseIOSTest { public static final String BUNDLE_ID = "io.appium.TestApp"; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { startAppiumServer(); @@ -29,4 +29,4 @@ public static void beforeClass() throws Exception { driver = new IOSDriver(service.getUrl(), options); } } -} \ No newline at end of file +} diff --git a/src/test/java/io/appium/java_client/ios/BaseIOSTest.java b/src/test/java/io/appium/java_client/ios/BaseIOSTest.java index 2f4d1f5f1..dfdf3c4da 100644 --- a/src/test/java/io/appium/java_client/ios/BaseIOSTest.java +++ b/src/test/java/io/appium/java_client/ios/BaseIOSTest.java @@ -18,7 +18,7 @@ import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServiceBuilder; -import org.junit.AfterClass; +import org.junit.jupiter.api.AfterAll; import java.time.Duration; @@ -52,7 +52,7 @@ public static AppiumDriverLocalService startAppiumServer() { /** * finishing. */ - @AfterClass public static void afterClass() { + @AfterAll public static void afterClass() { if (driver != null) { driver.quit(); } diff --git a/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java b/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java index 7aed47831..c461ded8a 100644 --- a/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java +++ b/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java @@ -17,7 +17,7 @@ package io.appium.java_client.ios; import io.appium.java_client.ios.options.XCUITestOptions; -import org.junit.BeforeClass; +import org.junit.jupiter.api.BeforeAll; import org.openqa.selenium.SessionNotCreatedException; import java.io.IOException; @@ -30,7 +30,7 @@ public class BaseIOSWebViewTest extends BaseIOSTest { private static final Duration WEB_VIEW_DETECT_INTERVAL = Duration.ofSeconds(1); private static final Duration WEB_VIEW_DETECT_DURATION = Duration.ofSeconds(15); - @BeforeClass + @BeforeAll public static void beforeClass() throws IOException { startAppiumServer(); diff --git a/src/test/java/io/appium/java_client/ios/BaseSafariTest.java b/src/test/java/io/appium/java_client/ios/BaseSafariTest.java index 4204cff41..654c4e58b 100644 --- a/src/test/java/io/appium/java_client/ios/BaseSafariTest.java +++ b/src/test/java/io/appium/java_client/ios/BaseSafariTest.java @@ -18,13 +18,13 @@ import io.appium.java_client.ios.options.XCUITestOptions; import io.appium.java_client.remote.MobileBrowserType; -import org.junit.BeforeClass; +import org.junit.jupiter.api.BeforeAll; import java.io.IOException; public class BaseSafariTest extends BaseIOSTest { - @BeforeClass public static void beforeClass() throws IOException { + @BeforeAll public static void beforeClass() throws IOException { startAppiumServer(); XCUITestOptions options = new XCUITestOptions() diff --git a/src/test/java/io/appium/java_client/ios/ClipboardTest.java b/src/test/java/io/appium/java_client/ios/ClipboardTest.java index ac7618fd8..af6b8a51d 100644 --- a/src/test/java/io/appium/java_client/ios/ClipboardTest.java +++ b/src/test/java/io/appium/java_client/ios/ClipboardTest.java @@ -16,9 +16,9 @@ package io.appium.java_client.ios; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ClipboardTest extends AppIOSTest { diff --git a/src/test/java/io/appium/java_client/ios/IOSAlertTest.java b/src/test/java/io/appium/java_client/ios/IOSAlertTest.java index 8fa3afd13..3c731e007 100644 --- a/src/test/java/io/appium/java_client/ios/IOSAlertTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSAlertTest.java @@ -16,16 +16,16 @@ package io.appium.java_client.ios; -import static junit.framework.TestCase.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent; import io.appium.java_client.AppiumBy; import org.apache.commons.lang3.StringUtils; -import org.junit.After; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.support.ui.WebDriverWait; @@ -33,7 +33,7 @@ import java.time.Duration; import java.util.function.Supplier; -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestMethodOrder(MethodOrderer.MethodName.class) public class IOSAlertTest extends AppIOSTest { private static final Duration ALERT_TIMEOUT = Duration.ofSeconds(5); @@ -63,7 +63,7 @@ private void ensureAlertPresence() { } } - @After + @AfterEach public void afterEach() { try { driver.switchTo().alert().accept(); diff --git a/src/test/java/io/appium/java_client/ios/IOSAppStringsTest.java b/src/test/java/io/appium/java_client/ios/IOSAppStringsTest.java index d1cb976d0..6080737f8 100644 --- a/src/test/java/io/appium/java_client/ios/IOSAppStringsTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSAppStringsTest.java @@ -16,9 +16,9 @@ package io.appium.java_client.ios; -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 IOSAppStringsTest extends AppIOSTest { diff --git a/src/test/java/io/appium/java_client/ios/IOSContextTest.java b/src/test/java/io/appium/java_client/ios/IOSContextTest.java index 369ea3292..57915a1f7 100644 --- a/src/test/java/io/appium/java_client/ios/IOSContextTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSContextTest.java @@ -16,12 +16,13 @@ package io.appium.java_client.ios; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +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.Test; +import org.junit.jupiter.api.Test; public class IOSContextTest extends BaseIOSWebViewTest { @@ -40,8 +41,11 @@ public class IOSContextTest extends BaseIOSWebViewTest { driver.context("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()); + }); } } diff --git a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java index f06e5b882..bcfd41d7d 100644 --- a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java @@ -19,18 +19,18 @@ import static io.appium.java_client.TestUtils.waitUntilTrue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import com.google.common.collect.ImmutableMap; import io.appium.java_client.appmanagement.ApplicationState; import io.appium.java_client.remote.HideKeyboardStrategy; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.ScreenOrientation; import org.openqa.selenium.WebElement; @@ -44,7 +44,7 @@ import java.time.Duration; public class IOSDriverTest extends AppIOSTest { - @Before + @BeforeEach public void setupEach() { if (driver.queryAppState(BUNDLE_ID).ordinal() < ApplicationState.RUNNING_IN_FOREGROUND.ordinal()) { driver.activateApp(BUNDLE_ID); @@ -94,7 +94,7 @@ public void getDeviceTimeTest() { driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done"); } - @Ignore + @Disabled @Test public void geolocationTest() { Location location = new Location(45, 45, 100); try { @@ -132,7 +132,7 @@ public void getDeviceTimeTest() { assertTrue(driver.isKeyboardShown()); } - @Ignore("The app crashes when restored from the background") + @Disabled("The app crashes when restored from the background") @Test public void putAppIntoBackgroundAndRestoreTest() { final long msStarted = System.currentTimeMillis(); @@ -140,7 +140,7 @@ public void putAppIntoBackgroundAndRestoreTest() { assertThat(System.currentTimeMillis() - msStarted, greaterThan(3000L)); } - @Ignore("The app crashes when restored from the background") + @Disabled("The app crashes when restored from the background") @Test public void applicationsManagementTest() { driver.runAppInBackground(Duration.ofSeconds(-1)); @@ -153,7 +153,7 @@ public void applicationsManagementTest() { Duration.ofSeconds(10), Duration.ofSeconds(1)); } - @Ignore("The app crashes when restored from the background") + @Disabled("The app crashes when restored from the background") @Test public void putAIntoBackgroundWithoutRestoreTest() { waitUntilTrue(() -> !driver.findElements(By.id("IntegerA")).isEmpty(), @@ -164,7 +164,7 @@ public void putAIntoBackgroundWithoutRestoreTest() { driver.activateApp(BUNDLE_ID); } - @Ignore + @Disabled @Test public void touchIdTest() { driver.toggleTouchIDEnrollment(true); driver.performTouchID(true); diff --git a/src/test/java/io/appium/java_client/ios/IOSElementTest.java b/src/test/java/io/appium/java_client/ios/IOSElementTest.java index ca57c4cb4..18db02e2b 100644 --- a/src/test/java/io/appium/java_client/ios/IOSElementTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSElementTest.java @@ -3,12 +3,12 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNot.not; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.FixMethodOrder; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.WebDriverWait; @@ -16,7 +16,7 @@ import java.time.Duration; -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestMethodOrder(MethodOrderer.MethodName.class) public class IOSElementTest extends AppIOSTest { @Test @@ -25,7 +25,7 @@ public void findByAccessibilityIdTest() { } // FIXME: Stabilize the test on CI - @Ignore + @Disabled @Test public void setValueTest() { WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20)); diff --git a/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java b/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java index 67f388d34..e4d27f327 100644 --- a/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSNativeWebTapSettingTest.java @@ -1,11 +1,11 @@ package io.appium.java_client.ios; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Duration; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; @@ -14,7 +14,7 @@ public class IOSNativeWebTapSettingTest extends BaseSafariTest { @Test - @Ignore("https://github.com/appium/appium/issues/17014") + @Disabled("https://github.com/appium/appium/issues/17014") public void nativeWebTapSettingTest() { assertTrue(driver.isBrowser()); driver.get("https://saucelabs.com/test/guinea-pig"); diff --git a/src/test/java/io/appium/java_client/ios/IOSScreenRecordTest.java b/src/test/java/io/appium/java_client/ios/IOSScreenRecordTest.java index 5657b1ff2..cf88b7b4a 100644 --- a/src/test/java/io/appium/java_client/ios/IOSScreenRecordTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSScreenRecordTest.java @@ -5,7 +5,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.time.Duration; diff --git a/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java b/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java index a90196bbe..30213f480 100644 --- a/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java @@ -16,9 +16,9 @@ package io.appium.java_client.ios; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import io.appium.java_client.AppiumBy; diff --git a/src/test/java/io/appium/java_client/ios/IOSSyslogListenerTest.java b/src/test/java/io/appium/java_client/ios/IOSSyslogListenerTest.java index ce627e8f9..d5e2b377f 100644 --- a/src/test/java/io/appium/java_client/ios/IOSSyslogListenerTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSSyslogListenerTest.java @@ -1,9 +1,9 @@ package io.appium.java_client.ios; -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; @@ -25,9 +25,9 @@ public void verifySyslogListenerCanBeAssigned() { 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 { diff --git a/src/test/java/io/appium/java_client/ios/IOSTouchTest.java b/src/test/java/io/appium/java_client/ios/IOSTouchTest.java index dab6dde45..46a4d0474 100644 --- a/src/test/java/io/appium/java_client/ios/IOSTouchTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSTouchTest.java @@ -5,22 +5,22 @@ import static io.appium.java_client.touch.WaitOptions.waitOptions; import static io.appium.java_client.touch.offset.ElementOption.element; import static java.time.Duration.ofMillis; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent; import io.appium.java_client.AppiumBy; import io.appium.java_client.MultiTouchAction; -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 org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.WebDriverWait; import java.time.Duration; -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestMethodOrder(MethodOrderer.MethodName.class) public class IOSTouchTest extends AppIOSTest { @Test diff --git a/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java b/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java index 4afb89cd1..d03f1acdc 100644 --- a/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java @@ -1,11 +1,11 @@ package io.appium.java_client.ios; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Duration; import io.appium.java_client.AppiumBy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; diff --git a/src/test/java/io/appium/java_client/ios/ImagesComparisonTest.java b/src/test/java/io/appium/java_client/ios/ImagesComparisonTest.java index b3bbcf0c2..ef52196b5 100644 --- a/src/test/java/io/appium/java_client/ios/ImagesComparisonTest.java +++ b/src/test/java/io/appium/java_client/ios/ImagesComparisonTest.java @@ -16,11 +16,11 @@ package io.appium.java_client.ios; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import io.appium.java_client.imagecomparison.FeatureDetector; import io.appium.java_client.imagecomparison.FeaturesMatchingOptions; @@ -31,7 +31,7 @@ import io.appium.java_client.imagecomparison.SimilarityMatchingOptions; import io.appium.java_client.imagecomparison.SimilarityMatchingResult; import org.apache.commons.codec.binary.Base64; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openqa.selenium.OutputType; public class ImagesComparisonTest extends AppIOSTest { diff --git a/src/test/java/io/appium/java_client/ios/RotationTest.java b/src/test/java/io/appium/java_client/ios/RotationTest.java index 7e65b12b7..21d177fff 100644 --- a/src/test/java/io/appium/java_client/ios/RotationTest.java +++ b/src/test/java/io/appium/java_client/ios/RotationTest.java @@ -16,15 +16,15 @@ package io.appium.java_client.ios; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.openqa.selenium.DeviceRotation; public class RotationTest extends AppIOSTest { - @After public void afterMethod() { + @AfterEach public void afterMethod() { driver.rotate(new DeviceRotation(0, 0, 0)); } diff --git a/src/test/java/io/appium/java_client/ios/SettingTest.java b/src/test/java/io/appium/java_client/ios/SettingTest.java index 9d0fbcf80..9fc2bfa4b 100644 --- a/src/test/java/io/appium/java_client/ios/SettingTest.java +++ b/src/test/java/io/appium/java_client/ios/SettingTest.java @@ -18,9 +18,9 @@ import io.appium.java_client.Setting; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.EnumMap; import java.util.HashMap; diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java index 56c423ab4..c183c44e0 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java @@ -18,10 +18,11 @@ import static io.appium.java_client.pagefactory.LocatorGroupStrategy.ALL_POSSIBLE; import static java.time.Duration.ofSeconds; -import static junit.framework.TestCase.assertNotNull; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +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 static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import io.appium.java_client.android.BaseAndroidTest; @@ -31,8 +32,8 @@ import io.appium.java_client.pagefactory.AndroidFindBys; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.HowToUseLocators; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebElement; import org.openqa.selenium.WrapsDriver; @@ -221,7 +222,7 @@ public class AndroidPageObjectTest extends BaseAndroidTest { /** * The setting up. */ - @Before public void setUp() { + @BeforeEach public void setUp() { if (!populated) { //This time out is set because test can be run on slow Android SDK emulator PageFactory.initElements(new AppiumFieldDecorator(driver, ofSeconds(5)), this); @@ -323,9 +324,10 @@ public class AndroidPageObjectTest extends BaseAndroidTest { assertNotEquals(null, textAndroidId.getAttribute("text")); } - @Test(expected = NoSuchElementException.class) public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy() { - assertNotNull( - elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.getAttribute("text")); + @Test public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy() { + assertThrows(NoSuchElementException.class, + () -> assertNotNull( + elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.getAttribute("text"))); } @Test public void checkThatTestWillNotBeFailedBecauseOfInvalidFindByList() { @@ -347,9 +349,10 @@ public class AndroidPageObjectTest extends BaseAndroidTest { assertEquals(((RemoteWebElement) cached).getId(), ((RemoteWebElement) cached).getId()); } - @Test(expected = NoSuchElementException.class) + @Test public void checkThatElementSearchingThrowsExpectedExceptionIfChainedLocatorIsInvalid() { - assertNotNull(elementFoundByInvalidChainedSelector.getAttribute("text")); + assertThrows(NoSuchElementException.class, + () -> assertNotNull(elementFoundByInvalidChainedSelector.getAttribute("text"))); } @Test public void checkThatListSearchingWorksIfChainedLocatorIsInvalid() { diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java index 81b3be1cf..c2cb1b6f4 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/DesktopBrowserCompatibilityTest.java @@ -20,16 +20,16 @@ import static io.appium.java_client.pagefactory.LocatorGroupStrategy.ALL_POSSIBLE; import static io.github.bonigarcia.wdm.WebDriverManager.chromedriver; import static java.time.Duration.ofSeconds; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.pagefactory.AndroidFindBy; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.HowToUseLocators; import io.appium.java_client.pagefactory.iOSXCUITFindBy; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; @@ -53,7 +53,7 @@ public class DesktopBrowserCompatibilityTest { /** * The starting. */ - @BeforeClass public static void beforeClass() { + @BeforeAll public static void beforeClass() { chromedriver().setup(); } diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/MobileBrowserCompatibilityTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/MobileBrowserCompatibilityTest.java index d9f4b6707..dad9d7a18 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/MobileBrowserCompatibilityTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/MobileBrowserCompatibilityTest.java @@ -24,10 +24,10 @@ import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.remote.MobileBrowserType; import io.appium.java_client.service.local.AppiumDriverLocalService; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.RemoteWebElement; @@ -58,7 +58,7 @@ public class MobileBrowserCompatibilityTest { /** * The setting up. */ - @Before + @BeforeEach public void setUp() { service = AppiumDriverLocalService.buildDefaultService(); service.start(); @@ -74,7 +74,7 @@ public void setUp() { /** * finishing. */ - @After + @AfterEach public void tearDown() { if (driver != null) { driver.quit(); @@ -91,7 +91,7 @@ public void test() { searchTextField.sendKeys("Hello"); btnG.click(); - Assert.assertNotEquals(0, foundLinks.size()); + Assertions.assertNotEquals(0, foundLinks.size()); } } diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/TimeoutTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/TimeoutTest.java index ea2300e09..cfba2ba36 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/TimeoutTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/TimeoutTest.java @@ -24,16 +24,16 @@ import static java.time.Duration.ofSeconds; import static java.time.temporal.ChronoUnit.SECONDS; import static org.apache.commons.lang3.time.DurationFormatUtils.formatDuration; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.junit.Assert.assertThat; import static org.openqa.selenium.support.PageFactory.initElements; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.WithTimeout; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; @@ -77,7 +77,7 @@ private static String assertionMessage(Duration expectedDuration) { formatDuration(expectedDuration.toMillis(), "H:mm:ss:SSS", true)); } - @BeforeClass + @BeforeAll public static void beforeAll() { chromedriver().setup(); } @@ -85,7 +85,7 @@ public static void beforeAll() { /** * The setting up. */ - @Before public void setUp() { + @BeforeEach public void setUp() { driver = new ChromeDriver(); timeOutDuration = DEFAULT_WAITING_TIMEOUT; initElements(new AppiumFieldDecorator(driver, timeOutDuration), this); @@ -94,7 +94,7 @@ public static void beforeAll() { /** * finishing. */ - @After public void tearDown() { + @AfterEach public void tearDown() { driver.quit(); } diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java index b56f67859..418f35e71 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java @@ -22,25 +22,25 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +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 static org.junit.jupiter.api.Assertions.assertTrue; import io.appium.java_client.ios.AppIOSTest; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.HowToUseLocators; import io.appium.java_client.pagefactory.iOSXCUITFindBy; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.PageFactory; import java.util.List; -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestMethodOrder(MethodOrderer.MethodName.class) public class XCUITModeTest extends AppIOSTest { private boolean populated = false; @@ -91,7 +91,7 @@ public class XCUITModeTest extends AppIOSTest { /** * The setting up. */ - @Before public void setUp() { + @BeforeEach public void setUp() { if (!populated) { PageFactory.initElements(new AppiumFieldDecorator(driver), this); } diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ExtendedWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ExtendedWidgetTest.java deleted file mode 100644 index d8d3a7b60..000000000 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ExtendedWidgetTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package io.appium.java_client.pagefactory_tests.widget.tests; - -import static java.util.stream.Collectors.toList; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; - -import java.util.List; - -public abstract class ExtendedWidgetTest extends WidgetTest { - - protected ExtendedWidgetTest(ExtendedApp app, WebDriver driver) { - super(app, driver); - } - - @Test - public abstract void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation(); - - @Test - public abstract void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass(); - - @Test - public abstract void checkCaseWhenBothWidgetFieldAndClassHaveDeclaredAnnotations(); - - protected static void checkThatLocatorsAreCreatedCorrectly(DefaultStubWidget single, - List multiple, By rootLocator, - By subLocator) { - - assertThat(single.toString(), containsString(rootLocator.toString())); - assertThat(multiple.stream().map(DefaultStubWidget::toString).collect(toList()), - contains(containsString(rootLocator.toString()), - containsString(rootLocator.toString()))); - - assertThat(single.getSubWidget().toString(), containsString(subLocator.toString())); - assertThat(single.getSubWidgets().stream().map(Object::toString).collect(toList()), - contains(containsString(subLocator.toString()), - containsString(subLocator.toString()))); - - assertThat(multiple.stream().map(abstractWidget -> abstractWidget.getSubWidget().toString()).collect(toList()), - contains(containsString(subLocator.toString()), - containsString(subLocator.toString()))); - } -} diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/WidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/WidgetTest.java index 6ef019438..0420d44f6 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/WidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/WidgetTest.java @@ -1,20 +1,22 @@ package io.appium.java_client.pagefactory_tests.widget.tests; -import static java.util.Arrays.copyOf; +import static java.util.stream.Collectors.toList; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; import static org.openqa.selenium.support.PageFactory.initElements; import io.appium.java_client.pagefactory.AppiumFieldDecorator; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; +import java.util.List; + public abstract class WidgetTest { protected final AbstractApp app; - protected static Object[] dataArray(Object...objects) { - return copyOf(objects, objects.length); - } - protected WidgetTest(AbstractApp app, WebDriver driver) { this.app = app; initElements(new AppiumFieldDecorator(driver), app); @@ -22,4 +24,32 @@ protected WidgetTest(AbstractApp app, WebDriver driver) { @Test public abstract void checkThatWidgetsAreCreatedCorrectly(); + + @Test + public abstract void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation(); + + @Test + public abstract void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass(); + + @Test + public abstract void checkCaseWhenBothWidgetFieldAndClassHaveDeclaredAnnotations(); + + protected static void checkThatLocatorsAreCreatedCorrectly(DefaultStubWidget single, + List multiple, By rootLocator, + By subLocator) { + + assertThat(single.toString(), containsString(rootLocator.toString())); + assertThat(multiple.stream().map(DefaultStubWidget::toString).collect(toList()), + contains(containsString(rootLocator.toString()), + containsString(rootLocator.toString()))); + + assertThat(single.getSubWidget().toString(), containsString(subLocator.toString())); + assertThat(single.getSubWidgets().stream().map(Object::toString).collect(toList()), + contains(containsString(subLocator.toString()), + containsString(subLocator.toString()))); + + assertThat(multiple.stream().map(abstractWidget -> abstractWidget.getSubWidget().toString()).collect(toList()), + contains(containsString(subLocator.toString()), + containsString(subLocator.toString()))); + } } diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidWidgetTest.java index 93047222b..a3eee515a 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/android/AndroidWidgetTest.java @@ -8,20 +8,23 @@ import io.appium.java_client.pagefactory_tests.widget.tests.AbstractStubWebDriver; import io.appium.java_client.pagefactory_tests.widget.tests.ExtendedApp; -import io.appium.java_client.pagefactory_tests.widget.tests.ExtendedWidgetTest; +import io.appium.java_client.pagefactory_tests.widget.tests.WidgetTest; +import org.junit.jupiter.api.Test; -public class AndroidWidgetTest extends ExtendedWidgetTest { +public class AndroidWidgetTest extends WidgetTest { public AndroidWidgetTest() { super(new AndroidApp(), new AbstractStubWebDriver.StubAndroidDriver()); } + @Test @Override public void checkThatWidgetsAreCreatedCorrectly() { checkThatLocatorsAreCreatedCorrectly(app.getWidget(), app.getWidgets(), androidUIAutomator(ANDROID_DEFAULT_WIDGET_LOCATOR), androidUIAutomator(ANDROID_SUB_WIDGET_LOCATOR)); } + @Test @Override public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() { checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getAnnotatedWidget(), @@ -29,6 +32,7 @@ public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() { androidUIAutomator(ANDROID_ROOT_WIDGET_LOCATOR), androidUIAutomator(ANDROID_SUB_WIDGET_LOCATOR)); } + @Test @Override public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() { checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidget(), @@ -36,6 +40,7 @@ public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() androidUIAutomator(ANDROID_ROOT_WIDGET_LOCATOR), androidUIAutomator(ANDROID_SUB_WIDGET_LOCATOR)); } + @Test @Override public void checkCaseWhenBothWidgetFieldAndClassHaveDeclaredAnnotations() { checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(), diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedAppTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedAppTest.java index 9953578be..8c93632ec 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedAppTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedAppTest.java @@ -1,66 +1,60 @@ package io.appium.java_client.pagefactory_tests.widget.tests.combined; -import static java.util.Arrays.asList; import static java.util.stream.Collectors.toList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalTo; +import static org.openqa.selenium.support.PageFactory.initElements; +import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.OverrideWidget; import io.appium.java_client.pagefactory_tests.widget.tests.AbstractApp; import io.appium.java_client.pagefactory_tests.widget.tests.AbstractStubWebDriver; import io.appium.java_client.pagefactory_tests.widget.tests.DefaultStubWidget; -import io.appium.java_client.pagefactory_tests.widget.tests.WidgetTest; import io.appium.java_client.pagefactory_tests.widget.tests.android.DefaultAndroidWidget; import io.appium.java_client.pagefactory_tests.widget.tests.windows.DefaultWindowsWidget; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.openqa.selenium.WebDriver; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; @SuppressWarnings({"unused", "unchecked"}) -@RunWith(Parameterized.class) -public class CombinedAppTest extends WidgetTest { - - private final Class widgetClass; +public class CombinedAppTest { /** * Test data generation. * * @return test parameters */ - @Parameterized.Parameters - public static Collection data() { - return asList( - dataArray(new CombinedApp(), new AbstractStubWebDriver.StubAndroidDriver(), DefaultAndroidWidget.class), - dataArray(new CombinedApp(), new AbstractStubWebDriver.StubIOSXCUITDriver(), + public static Stream data() { + return Stream.of( + Arguments.of(new CombinedApp(), new AbstractStubWebDriver.StubAndroidDriver(), DefaultAndroidWidget.class), + Arguments.of(new CombinedApp(), new AbstractStubWebDriver.StubIOSXCUITDriver(), DefaultIosXCUITWidget.class), - dataArray(new CombinedApp(), new AbstractStubWebDriver.StubWindowsDriver(), DefaultWindowsWidget.class), - dataArray(new CombinedApp(), new AbstractStubWebDriver.StubBrowserDriver(), DefaultFindByWidget.class), - dataArray(new CombinedApp(), new AbstractStubWebDriver.StubAndroidBrowserOrWebViewDriver(), + Arguments.of(new CombinedApp(), new AbstractStubWebDriver.StubWindowsDriver(), DefaultWindowsWidget.class), + Arguments.of(new CombinedApp(), new AbstractStubWebDriver.StubBrowserDriver(), DefaultFindByWidget.class), + Arguments.of(new CombinedApp(), new AbstractStubWebDriver.StubAndroidBrowserOrWebViewDriver(), DefaultFindByWidget.class), - dataArray(new PartiallyCombinedApp(), new AbstractStubWebDriver.StubAndroidDriver(), + Arguments.of(new PartiallyCombinedApp(), new AbstractStubWebDriver.StubAndroidDriver(), DefaultAndroidWidget.class), - dataArray(new PartiallyCombinedApp(), new AbstractStubWebDriver.StubIOSXCUITDriver(), + Arguments.of(new PartiallyCombinedApp(), new AbstractStubWebDriver.StubIOSXCUITDriver(), DefaultStubWidget.class), - dataArray(new PartiallyCombinedApp(), new AbstractStubWebDriver.StubWindowsDriver(), + Arguments.of(new PartiallyCombinedApp(), new AbstractStubWebDriver.StubWindowsDriver(), DefaultStubWidget.class), - dataArray(new PartiallyCombinedApp(), new AbstractStubWebDriver.StubBrowserDriver(), + Arguments.of(new PartiallyCombinedApp(), new AbstractStubWebDriver.StubBrowserDriver(), DefaultFindByWidget.class), - dataArray(new PartiallyCombinedApp(), new AbstractStubWebDriver.StubAndroidBrowserOrWebViewDriver(), + Arguments.of(new PartiallyCombinedApp(), new AbstractStubWebDriver.StubAndroidBrowserOrWebViewDriver(), DefaultFindByWidget.class) ); } - public CombinedAppTest(AbstractApp app, WebDriver driver, Class widgetClass) { - super(app, driver); - this.widgetClass = widgetClass; - } - - @Override - public void checkThatWidgetsAreCreatedCorrectly() { + @ParameterizedTest + @MethodSource("data") + public void checkThatWidgetsAreCreatedCorrectly(AbstractApp app, WebDriver driver, Class widgetClass) { + initElements(new AppiumFieldDecorator(driver), app); assertThat("Expected widget class was " + widgetClass.getName(), app.getWidget().getSelfReference().getClass(), equalTo(widgetClass)); diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedWidgetTest.java index cbae48bcc..1d686c58e 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedWidgetTest.java @@ -1,72 +1,66 @@ package io.appium.java_client.pagefactory_tests.widget.tests.combined; -import static java.util.Arrays.asList; import static java.util.stream.Collectors.toList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalTo; +import static org.openqa.selenium.support.PageFactory.initElements; +import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.OverrideWidget; import io.appium.java_client.pagefactory_tests.widget.tests.AbstractApp; import io.appium.java_client.pagefactory_tests.widget.tests.AbstractStubWebDriver; import io.appium.java_client.pagefactory_tests.widget.tests.DefaultStubWidget; -import io.appium.java_client.pagefactory_tests.widget.tests.WidgetTest; import io.appium.java_client.pagefactory_tests.widget.tests.android.DefaultAndroidWidget; import io.appium.java_client.pagefactory_tests.widget.tests.windows.DefaultWindowsWidget; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.stream.Stream; @SuppressWarnings({"unchecked", "unused"}) -@RunWith(Parameterized.class) -public class CombinedWidgetTest extends WidgetTest { - - private final Class widgetClass; +public class CombinedWidgetTest { /** * Test data generation. * * @return test parameters */ - @Parameterized.Parameters - public static Collection data() { - return asList( - dataArray(new AppWithCombinedWidgets(), + public static Stream data() { + return Stream.of( + Arguments.of(new AppWithCombinedWidgets(), new AbstractStubWebDriver.StubAndroidDriver(), DefaultAndroidWidget.class), - dataArray(new AppWithCombinedWidgets(), + Arguments.of(new AppWithCombinedWidgets(), new AbstractStubWebDriver.StubIOSXCUITDriver(), DefaultIosXCUITWidget.class), - dataArray(new AppWithCombinedWidgets(), + Arguments.of(new AppWithCombinedWidgets(), new AbstractStubWebDriver.StubWindowsDriver(), DefaultWindowsWidget.class), - dataArray(new AppWithCombinedWidgets(), + Arguments.of(new AppWithCombinedWidgets(), new AbstractStubWebDriver.StubBrowserDriver(), DefaultFindByWidget.class), - dataArray(new AppWithCombinedWidgets(), + Arguments.of(new AppWithCombinedWidgets(), new AbstractStubWebDriver.StubAndroidBrowserOrWebViewDriver(), DefaultFindByWidget.class), - dataArray(new AppWithPartiallyCombinedWidgets(), + Arguments.of(new AppWithPartiallyCombinedWidgets(), new AbstractStubWebDriver.StubAndroidDriver(), DefaultAndroidWidget.class), - dataArray(new AppWithPartiallyCombinedWidgets(), + Arguments.of(new AppWithPartiallyCombinedWidgets(), new AbstractStubWebDriver.StubIOSXCUITDriver(), DefaultStubWidget.class), - dataArray(new AppWithPartiallyCombinedWidgets(), + Arguments.of(new AppWithPartiallyCombinedWidgets(), new AbstractStubWebDriver.StubWindowsDriver(), DefaultStubWidget.class), - dataArray(new AppWithPartiallyCombinedWidgets(), + Arguments.of(new AppWithPartiallyCombinedWidgets(), new AbstractStubWebDriver.StubBrowserDriver(), DefaultFindByWidget.class), - dataArray(new AppWithPartiallyCombinedWidgets(), + Arguments.of(new AppWithPartiallyCombinedWidgets(), new AbstractStubWebDriver.StubAndroidBrowserOrWebViewDriver(), DefaultFindByWidget.class) ); } - public CombinedWidgetTest(AbstractApp app, WebDriver driver, Class widgetClass) { - super(app, driver); - this.widgetClass = widgetClass; - } - - @Override - public void checkThatWidgetsAreCreatedCorrectly() { + @ParameterizedTest + @MethodSource("data") + public void checkThatWidgetsAreCreatedCorrectly(AbstractApp app, WebDriver driver, Class widgetClass) { + initElements(new AppiumFieldDecorator(driver), app); assertThat("Expected widget class was " + widgetClass.getName(), app.getWidget().getSubWidget().getSelfReference().getClass(), equalTo(widgetClass)); diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ios/XCUITWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ios/XCUITWidgetTest.java index d2e4d483f..6a9bb0d53 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ios/XCUITWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/ios/XCUITWidgetTest.java @@ -8,20 +8,23 @@ import io.appium.java_client.pagefactory_tests.widget.tests.AbstractStubWebDriver; import io.appium.java_client.pagefactory_tests.widget.tests.ExtendedApp; -import io.appium.java_client.pagefactory_tests.widget.tests.ExtendedWidgetTest; +import io.appium.java_client.pagefactory_tests.widget.tests.WidgetTest; +import org.junit.jupiter.api.Test; -public class XCUITWidgetTest extends ExtendedWidgetTest { +public class XCUITWidgetTest extends WidgetTest { public XCUITWidgetTest() { super(new IosApp(), new AbstractStubWebDriver.StubIOSXCUITDriver()); } + @Test @Override public void checkThatWidgetsAreCreatedCorrectly() { checkThatLocatorsAreCreatedCorrectly(app.getWidget(), app.getWidgets(), iOSNsPredicateString(IOS_XCUIT_WIDGET_LOCATOR), iOSNsPredicateString(XCUIT_SUB_WIDGET_LOCATOR)); } + @Test @Override public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() { checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getAnnotatedWidget(), @@ -29,6 +32,7 @@ public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() { iOSNsPredicateString(XCUIT_ROOT_WIDGET_LOCATOR), iOSNsPredicateString(XCUIT_SUB_WIDGET_LOCATOR)); } + @Test @Override public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() { checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidget(), @@ -36,6 +40,7 @@ public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() iOSNsPredicateString(XCUIT_ROOT_WIDGET_LOCATOR), iOSNsPredicateString(XCUIT_SUB_WIDGET_LOCATOR)); } + @Test @Override public void checkCaseWhenBothWidgetFieldAndClassHaveDeclaredAnnotations() { checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(), diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/windows/WindowsWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/windows/WindowsWidgetTest.java index fbd9da9a6..d5990b7e5 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/windows/WindowsWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/windows/WindowsWidgetTest.java @@ -8,20 +8,23 @@ import io.appium.java_client.pagefactory_tests.widget.tests.AbstractStubWebDriver; import io.appium.java_client.pagefactory_tests.widget.tests.ExtendedApp; -import io.appium.java_client.pagefactory_tests.widget.tests.ExtendedWidgetTest; +import io.appium.java_client.pagefactory_tests.widget.tests.WidgetTest; +import org.junit.jupiter.api.Test; -public class WindowsWidgetTest extends ExtendedWidgetTest { +public class WindowsWidgetTest extends WidgetTest { public WindowsWidgetTest() { super(new WindowsApp(), new AbstractStubWebDriver.StubWindowsDriver()); } + @Test @Override public void checkThatWidgetsAreCreatedCorrectly() { checkThatLocatorsAreCreatedCorrectly(app.getWidget(), app.getWidgets(), windowsAutomation(WINDOWS_DEFAULT_WIDGET_LOCATOR), windowsAutomation(WINDOWS_SUB_WIDGET_LOCATOR)); } + @Test @Override public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() { checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getAnnotatedWidget(), @@ -29,6 +32,7 @@ public void checkCaseWhenWidgetClassHasDeclaredLocatorAnnotation() { windowsAutomation(WINDOWS_ROOT_WIDGET_LOCATOR), windowsAutomation(WINDOWS_SUB_WIDGET_LOCATOR)); } + @Test @Override public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() { checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidget(), @@ -36,6 +40,7 @@ public void checkCaseWhenWidgetClassHasNoDeclaredAnnotationButItHasSuperclass() windowsAutomation(WINDOWS_ROOT_WIDGET_LOCATOR), windowsAutomation(WINDOWS_SUB_WIDGET_LOCATOR)); } + @Test @Override public void checkCaseWhenBothWidgetFieldAndClassHaveDeclaredAnnotations() { checkThatLocatorsAreCreatedCorrectly(((ExtendedApp) app).getExtendedWidgetWithOverriddenLocators(), diff --git a/src/test/java/io/appium/java_client/remote/MobileOptionsTest.java b/src/test/java/io/appium/java_client/remote/MobileOptionsTest.java index ab2b776e1..13faeb583 100644 --- a/src/test/java/io/appium/java_client/remote/MobileOptionsTest.java +++ b/src/test/java/io/appium/java_client/remote/MobileOptionsTest.java @@ -16,7 +16,7 @@ package io.appium.java_client.remote; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.ScreenOrientation; @@ -24,7 +24,9 @@ import java.net.URL; import java.time.Duration; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class MobileOptionsTest { private MobileOptions mobileOptions = new MobileOptions<>(); diff --git a/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java b/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java index 3c3fed15e..fe5b9a3b6 100644 --- a/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java +++ b/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java @@ -16,20 +16,20 @@ import static java.util.Arrays.asList; import static java.util.Optional.ofNullable; import static java.util.concurrent.TimeUnit.SECONDS; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.common.collect.ImmutableMap; import io.appium.java_client.android.options.UiAutomator2Options; import io.github.bonigarcia.wdm.WebDriverManager; -import org.junit.After; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.FileOutputStream; @@ -67,14 +67,14 @@ public class ServerBuilderTest { /** * initialization. */ - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { testIP = getLocalIp4Address(); chromeManager = chromedriver(); chromeManager.setup(); } - @After + @AfterEach public void tearDown() throws Exception { ofNullable(service).ifPresent(AppiumDriverLocalService::stop); diff --git a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java b/src/test/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java index 34b0e2565..3d248f462 100644 --- a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java +++ b/src/test/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java @@ -23,16 +23,16 @@ import io.appium.java_client.remote.MobilePlatform; import io.appium.java_client.service.local.flags.GeneralServerFlag; import io.github.bonigarcia.wdm.WebDriverManager; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openqa.selenium.Capabilities; import java.time.Duration; import static io.appium.java_client.TestResources.apiDemosApk; import static io.github.bonigarcia.wdm.WebDriverManager.chromedriver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class StartingAppLocallyAndroidTest { diff --git a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java b/src/test/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java index b7bc4786c..ec629f8ba 100644 --- a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java +++ b/src/test/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java @@ -17,10 +17,10 @@ package io.appium.java_client.service.local; import static io.appium.java_client.TestResources.uiCatalogAppZip; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import io.appium.java_client.ios.BaseIOSTest; import io.appium.java_client.ios.IOSDriver; @@ -29,7 +29,7 @@ import io.appium.java_client.remote.MobileCapabilityType; import io.appium.java_client.remote.MobilePlatform; import io.appium.java_client.service.local.flags.GeneralServerFlag; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openqa.selenium.Capabilities; import org.openqa.selenium.Platform; diff --git a/src/test/java/io/appium/java_client/service/local/ThreadSafetyTest.java b/src/test/java/io/appium/java_client/service/local/ThreadSafetyTest.java index fa1ba1d5c..50d59a5df 100644 --- a/src/test/java/io/appium/java_client/service/local/ThreadSafetyTest.java +++ b/src/test/java/io/appium/java_client/service/local/ThreadSafetyTest.java @@ -1,12 +1,12 @@ package io.appium.java_client.service.local; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ThreadSafetyTest { diff --git a/src/test/java/io/appium/java_client/touch/TouchOptionsTests.java b/src/test/java/io/appium/java_client/touch/TouchOptionsTests.java index 1500e2f81..b08249962 100644 --- a/src/test/java/io/appium/java_client/touch/TouchOptionsTests.java +++ b/src/test/java/io/appium/java_client/touch/TouchOptionsTests.java @@ -8,15 +8,15 @@ import static io.appium.java_client.touch.offset.PointOption.point; import static java.time.Duration.ofMillis; import static java.time.Duration.ofSeconds; -import static junit.framework.TestCase.fail; import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.in; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertThrows; import io.appium.java_client.touch.offset.ElementOption; import io.appium.java_client.touch.offset.PointOption; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openqa.selenium.Point; import org.openqa.selenium.remote.RemoteWebElement; @@ -28,16 +28,16 @@ public class TouchOptionsTests { private static final RemoteWebElement DUMMY_ELEMENT = new DummyElement(); - @Test(expected = IllegalArgumentException.class) + @Test public void invalidEmptyPointOptionsShouldFailOnBuild() { - new PointOption<>().build(); - fail("The exception throwing was expected"); + assertThrows(IllegalArgumentException.class, + () -> new PointOption<>().build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void invalidEmptyElementOptionsShouldFailOnBuild() { - new ElementOption().build(); - fail("The exception throwing was expected"); + assertThrows(IllegalArgumentException.class, + () -> new ElementOption().build()); } @Test