Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Run tests on the JUnit Jupiter Platform #1721

Merged
merged 23 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dcfdbbe
refactor!: Migrated all tests to JUnit 5
RameshBabuPrudhvi Jul 25, 2022
ca0378b
refactor!: updated missing junit tests
RameshBabuPrudhvi Jul 25, 2022
667f58f
refactor!: updated review comments
RameshBabuPrudhvi Jul 25, 2022
ccf1349
refactor!: updated import statement order
RameshBabuPrudhvi Jul 25, 2022
9c12104
refactor!: Removed unwanted test methods
RameshBabuPrudhvi Jul 25, 2022
e904926
refactor!: Fixed Formatter
RameshBabuPrudhvi Jul 25, 2022
7fa1cb8
refactor!: Updated existing class specific check styles
RameshBabuPrudhvi Jul 26, 2022
6fdd68b
refactor!: Updated existing class specific check styles
RameshBabuPrudhvi Jul 26, 2022
7c2fae3
refactor!: Updated check styles
RameshBabuPrudhvi Jul 26, 2022
b2b646d
refactor!: Updated check styles
RameshBabuPrudhvi Jul 26, 2022
c1c6aec
refactor!: Updated check styles
RameshBabuPrudhvi Jul 26, 2022
fc379cb
Revert noisy changes
valfirst Jul 26, 2022
9904f4e
refactor!: Updated WidgetTests
RameshBabuPrudhvi Jul 27, 2022
e95df72
refactor!: Reverted WidgetTest changes and execute using vintage engine
RameshBabuPrudhvi Jul 27, 2022
4a5dda0
refactor!: update import
RameshBabuPrudhvi Jul 27, 2022
a849e46
refactor!: Reverted format changes
RameshBabuPrudhvi Jul 27, 2022
8fd7141
refactor!: Added Test annotation for all test override methods
RameshBabuPrudhvi Jul 27, 2022
b4b026d
refactor!: Reverted Widget Tests
RameshBabuPrudhvi Jul 27, 2022
589709b
Widget Tests (#1)
RameshBabuPrudhvi Jul 27, 2022
5abd0e3
refactor!: Added missing import
RameshBabuPrudhvi Jul 27, 2022
022b576
refactor!: Updated Widget Parameterized Tests
RameshBabuPrudhvi Jul 27, 2022
dd77163
refactor!: Updated Tests
RameshBabuPrudhvi Jul 27, 2022
3741d7c
refactor!: Merged WidgetTest classes
RameshBabuPrudhvi Jul 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencies {
implementation 'commons-io:commons-io:2.11.0'
implementation 'org.slf4j:slf4j-api:1.7.36'

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

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

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

task miscTest( type: Test ) {
useJUnit()
useJUnitPlatform()
testLogging.showStandardStreams = true
testLogging.exceptionFormat = 'full'
filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import static io.appium.java_client.touch.WaitOptions.waitOptions;
import static io.appium.java_client.touch.offset.ElementOption.element;
import static java.time.Duration.ofSeconds;
import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.functions.ActionSupplier;
import io.appium.java_client.touch.offset.ElementOption;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

package io.appium.java_client.android;

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

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

public class AndroidActivityTest extends BaseAndroidTest {

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

package io.appium.java_client.android;

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

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

public class AndroidAppStringsTest extends BaseAndroidTest {

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

package io.appium.java_client.android;

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

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

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

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

package io.appium.java_client.android;

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

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

public class AndroidContextTest extends BaseAndroidTest {

@BeforeClass public static void beforeClass2() throws Exception {
@BeforeAll public static void beforeClass2() throws Exception {
Activity activity = new Activity("io.appium.android.apis", ".view.WebView1");
driver.startActivity(activity);
Thread.sleep(20000);
Expand All @@ -46,9 +47,12 @@ public class AndroidContextTest extends BaseAndroidTest {
assertEquals(driver.getContext(), "NATIVE_APP");
}

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

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

import java.time.Duration;

import static org.junit.Assert.assertNotNull;
RameshBabuPrudhvi marked this conversation as resolved.
Show resolved Hide resolved
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class AndroidDataMatcherTest extends BaseEspressoTest {

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

package io.appium.java_client.android;

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

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

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

package io.appium.java_client.android;

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

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

public class AndroidElementTest extends BaseAndroidTest {

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

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

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

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

@Before
@BeforeEach
public void setUp() {

driver.context("NATIVE_APP");
Expand All @@ -92,7 +93,8 @@ public void complexWaitingTestWithPreCondition() {
assertThat("WebView is expected", driver.getContext(), containsString("WEBVIEW"));
}

@Test public void complexWaitingTestWithPostConditions() {
@Test
public void complexWaitingTestWithPostConditions() {
valfirst marked this conversation as resolved.
Show resolved Hide resolved
final List<Boolean> calls = new ArrayList<>();

AppiumFunction<Pattern, WebDriver> waitingForContext = input -> {
Expand Down Expand Up @@ -127,17 +129,19 @@ public void complexWaitingTestWithPreCondition() {
assertThat("There should be 3 calls", calls.size(), is(3));
}

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

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

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

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

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

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

import java.time.Duration;

public class AndroidScreenRecordTest extends BaseAndroidTest {

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

package io.appium.java_client.android;

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

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

public class AndroidSearchingTest extends BaseAndroidTest {

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

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

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

public class AndroidTouchTest extends BaseAndroidTest {

@Before
@BeforeEach
public void setUp() {
driver.resetApp();
}
Expand Down