diff --git a/.idea/libraries/assertj.xml b/.idea/libraries/assertj.xml
new file mode 100644
index 0000000000000..7d00f8040dc88
--- /dev/null
+++ b/.idea/libraries/assertj.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/java/client/client.iml b/java/client/client.iml
index 6a6da69a15555..2481842a3ad2f 100644
--- a/java/client/client.iml
+++ b/java/client/client.iml
@@ -43,6 +43,7 @@
+
diff --git a/java/client/test/org/openqa/selenium/AlertsTest.java b/java/client/test/org/openqa/selenium/AlertsTest.java
index 1067f3a4683f0..757552725b7e6 100644
--- a/java/client/test/org/openqa/selenium/AlertsTest.java
+++ b/java/client/test/org/openqa/selenium/AlertsTest.java
@@ -17,11 +17,8 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assume.assumeFalse;
import static org.openqa.selenium.WaitingConditions.newWindowIsOpened;
import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
@@ -33,10 +30,10 @@
import static org.openqa.selenium.testing.Driver.IE;
import static org.openqa.selenium.testing.Driver.MARIONETTE;
import static org.openqa.selenium.testing.Driver.SAFARI;
-import static org.openqa.selenium.testing.TestUtilities.catchThrowable;
import static org.openqa.selenium.testing.TestUtilities.getFirefoxVersion;
import static org.openqa.selenium.testing.TestUtilities.isFirefox;
+import org.assertj.core.api.Assumptions;
import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.environment.webserver.Page;
@@ -93,7 +90,7 @@ public void testShouldBeAbleToOverrideTheWindowAlertMethod() {
driver.findElement(By.id("alert")).click();
// If we can perform any action, we're good to go
- assertEquals("Testing Alerts", driver.getTitle());
+ assertThat(driver.getTitle()).isEqualTo("Testing Alerts");
}
@Test
@@ -105,7 +102,7 @@ public void testShouldAllowUsersToAcceptAnAlertManually() {
alert.accept();
// If we can perform any action, we're good to go
- assertEquals("Testing Alerts", driver.getTitle());
+ assertThat(driver.getTitle()).isEqualTo("Testing Alerts");
}
@Test
@@ -115,8 +112,8 @@ public void testShouldThrowIllegalArgumentExceptionWhenKeysNull() {
driver.findElement(By.id("alert")).click();
Alert alert = wait.until(alertIsPresent());
try {
- Throwable t = catchThrowable(() -> alert.sendKeys(null));
- assertThat(t, instanceOf(IllegalArgumentException.class));
+ assertThatExceptionOfType(IllegalArgumentException.class)
+ .isThrownBy(() -> alert.sendKeys(null));
} finally {
alert.accept();
}
@@ -131,7 +128,7 @@ public void testShouldAllowUsersToAcceptAnAlertWithNoTextManually() {
alert.accept();
// If we can perform any action, we're good to go
- assertEquals("Testing Alerts", driver.getTitle());
+ assertThat(driver.getTitle()).isEqualTo("Testing Alerts");
}
@NeedsLocalEnvironment(reason = "Carefully timing based")
@@ -154,7 +151,7 @@ public void testShouldGetTextOfAlertOpenedInSetTimeout() {
// and only if it happens before the alert actually loads.
Alert alert = driver.switchTo().alert();
try {
- assertEquals("Slow", alert.getText());
+ assertThat(alert.getText()).isEqualTo("Slow");
} finally {
alert.accept();
}
@@ -169,7 +166,7 @@ public void testShouldAllowUsersToDismissAnAlertManually() {
alert.dismiss();
// If we can perform any action, we're good to go
- assertEquals("Testing Alerts", driver.getTitle());
+ assertThat(driver.getTitle()).isEqualTo("Testing Alerts");
}
@Test
@@ -181,7 +178,7 @@ public void testShouldAllowAUserToAcceptAPrompt() {
alert.accept();
// If we can perform any action, we're good to go
- assertEquals("Testing Prompt", driver.getTitle());
+ assertThat(driver.getTitle()).isEqualTo("Testing Prompt");
}
@Test
@@ -193,7 +190,7 @@ public void testShouldAllowAUserToDismissAPrompt() {
alert.dismiss();
// If we can perform any action, we're good to go
- assertEquals("Testing Prompt", driver.getTitle());
+ assertThat(driver.getTitle()).isEqualTo("Testing Prompt");
}
@Test
@@ -218,8 +215,8 @@ public void testSettingTheValueOfAnAlertThrows() {
Alert alert = wait.until(alertIsPresent());
try {
- Throwable t = catchThrowable(() -> alert.sendKeys("cheese"));
- assertThat(t, instanceOf(ElementNotInteractableException.class));
+ assertThatExceptionOfType(ElementNotInteractableException.class)
+ .isThrownBy(() -> alert.sendKeys("cheese"));
} finally {
alert.accept();
}
@@ -234,7 +231,7 @@ public void testShouldAllowTheUserToGetTheTextOfAnAlert() {
String value = alert.getText();
alert.accept();
- assertEquals("cheese", value);
+ assertThat(value).isEqualTo("cheese");
}
@Test
@@ -246,7 +243,7 @@ public void testShouldAllowTheUserToGetTheTextOfAPrompt() {
String value = alert.getText();
alert.accept();
- assertEquals("Enter something", value);
+ assertThat(value).isEqualTo("Enter something");
}
@Test
@@ -257,8 +254,8 @@ public void testAlertShouldNotAllowAdditionalCommandsIfDismissed() {
Alert alert = wait.until(alertIsPresent());
alert.accept();
- Throwable t = catchThrowable(alert::getText);
- assertThat(t, instanceOf(NoAlertPresentException.class));
+ assertThatExceptionOfType(NoAlertPresentException.class)
+ .isThrownBy(alert::getText);
}
@SwitchToTopAfterTest
@@ -276,7 +273,7 @@ public void testShouldAllowUsersToAcceptAnAlertInAFrame() {
alert.accept();
// If we can perform any action, we're good to go
- assertEquals("Testing Alerts", driver.getTitle());
+ assertThat(driver.getTitle()).isEqualTo("Testing Alerts");
}
@SwitchToTopAfterTest
@@ -297,15 +294,15 @@ public void testShouldAllowUsersToAcceptAnAlertInANestedFrame() {
alert.accept();
// If we can perform any action, we're good to go
- assertEquals("Testing Alerts", driver.getTitle());
+ assertThat(driver.getTitle()).isEqualTo("Testing Alerts");
}
@Test
public void testSwitchingToMissingAlertThrows() {
driver.get(alertPage("cheese"));
- Throwable t = catchThrowable(() -> driver.switchTo().alert());
- assertThat(t, instanceOf(NoAlertPresentException.class));
+ assertThatExceptionOfType(NoAlertPresentException.class)
+ .isThrownBy(() -> driver.switchTo().alert());
}
@Test
@@ -321,8 +318,8 @@ public void testSwitchingToMissingAlertInAClosedWindowThrows() {
wait.until(ableToSwitchToWindow("newwindow"));
driver.close();
- Throwable t = catchThrowable(() -> driver.switchTo().alert());
- assertThat(t, instanceOf(NoSuchWindowException.class));
+ assertThatExceptionOfType(NoSuchWindowException.class)
+ .isThrownBy(() -> driver.switchTo().alert());
} finally {
driver.switchTo().window(mainWindow);
@@ -394,7 +391,7 @@ public void testShouldHandleAlertOnPageLoad() {
String value = alert.getText();
alert.accept();
- assertEquals("onload", value);
+ assertThat(value).isEqualTo("onload");
wait.until(textInElementLocated(By.tagName("p"), "Page with onload event handler"));
}
@@ -409,7 +406,7 @@ public void testShouldHandleAlertOnPageLoadUsingGet() {
String value = alert.getText();
alert.accept();
- assertEquals("onload", value);
+ assertThat(value).isEqualTo("onload");
wait.until(textInElementLocated(By.tagName("p"), "Page with onload event handler"));
}
@@ -433,8 +430,8 @@ public void testShouldNotHandleAlertInAnotherWindow() {
driver.findElement(By.id("open-new-window")).click();
wait.until(newWindowIsOpened(currentWindowHandles));
- Throwable t = catchThrowable(() -> wait.until(alertIsPresent()));
- assertThat(t, instanceOf(TimeoutException.class));
+ assertThatExceptionOfType(TimeoutException.class)
+ .isThrownBy(() -> wait.until(alertIsPresent()));
} finally {
driver.switchTo().window("newwindow");
@@ -466,7 +463,7 @@ public void testShouldHandleAlertOnPageUnload() {
String value = alert.getText();
alert.accept();
- assertEquals("onbeforeunload", value);
+ assertThat(value).isEqualTo("onbeforeunload");
wait.until(textInElementLocated(By.id("link"), "open new page"));
}
@@ -513,7 +510,7 @@ public void testShouldHandleAlertOnWindowClose() {
String value = alert.getText();
alert.accept();
- assertEquals("onbeforeunload", value);
+ assertThat(value).isEqualTo("onbeforeunload");
} finally {
driver.switchTo().window(mainWindow);
@@ -533,10 +530,10 @@ public void testIncludesAlertTextInUnhandledAlertException() {
driver.findElement(By.id("alert")).click();
wait.until(alertIsPresent());
- Throwable t = catchThrowable(driver::getTitle);
- assertThat(t, instanceOf(UnhandledAlertException.class));
- assertThat(((UnhandledAlertException) t).getAlertText(), is("cheese"));
- assertThat(t.getMessage(), containsString("cheese"));
+ assertThatExceptionOfType(UnhandledAlertException.class)
+ .isThrownBy(driver::getTitle)
+ .withMessage("cheese")
+ .satisfies(ex -> assertThat(ex.getAlertText()).isEqualTo("cheese"));
}
@NoDriverAfterTest
@@ -564,8 +561,8 @@ public void shouldHandleAlertOnFormSubmit() {
String value = alert.getText();
alert.accept();
- assertEquals("Tasty cheese", value);
- assertEquals("Testing Alerts", driver.getTitle());
+ assertThat(value).isEqualTo("Tasty cheese");
+ assertThat(driver.getTitle()).isEqualTo("Testing Alerts");
}
private static ExpectedCondition textInElementLocated(
diff --git a/java/client/test/org/openqa/selenium/ArchitectureTest.java b/java/client/test/org/openqa/selenium/ArchitectureTest.java
index 0987d6845e13c..f1e6aef55f7da 100644
--- a/java/client/test/org/openqa/selenium/ArchitectureTest.java
+++ b/java/client/test/org/openqa/selenium/ArchitectureTest.java
@@ -17,152 +17,148 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.openqa.selenium.testing.TestUtilities.catchThrowable;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.openqa.selenium.Architecture.ANY;
+import static org.openqa.selenium.Architecture.ARM;
+import static org.openqa.selenium.Architecture.X64;
+import static org.openqa.selenium.Architecture.X86;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-@RunWith(JUnit4.class)
public class ArchitectureTest {
@Test
public void anyMatchesX86() {
- assertTrue(Architecture.ANY.is(Architecture.X86));
+ assertThat(ANY.is(X86)).isTrue();
}
@Test
public void anyMatchesX64() {
- assertTrue(Architecture.ANY.is(Architecture.X64));
+ assertThat(ANY.is(X64)).isTrue();
}
@Test
public void anyMatchesARM() {
- assertTrue(Architecture.ANY.is(Architecture.ARM));
+ assertThat(ANY.is(ARM)).isTrue();
}
@Test
public void anyMatchesANY() {
- assertTrue(Architecture.ANY.is(Architecture.ANY));
+ assertThat(ANY.is(ANY)).isTrue();
}
@Test
public void currentArchitecture() {
Architecture current = Architecture.getCurrent();
- assertNotNull(current);
- assertFalse(current.is(Architecture.ANY));
+ assertThat(current).isNotNull();
+ assertThat(current.is(ANY)).isFalse();
}
@Test
public void determineArchI386() {
- assertTrue(Architecture.extractFromSysProperty("i386").is(Architecture.X86));
+ assertThat(Architecture.extractFromSysProperty("i386").is(X86)).isTrue();
}
@Test
public void determineArchIA32() {
- assertTrue(Architecture.extractFromSysProperty("ia32").is(Architecture.X86));
+ assertThat(Architecture.extractFromSysProperty("ia32").is(X86)).isTrue();
}
@Test
public void determineArchI686() {
- assertTrue(Architecture.extractFromSysProperty("i686").is(Architecture.X86));
+ assertThat(Architecture.extractFromSysProperty("i686").is(X86)).isTrue();
}
@Test
public void determineArchI486() {
- assertTrue(Architecture.extractFromSysProperty("i486").is(Architecture.X86));
+ assertThat(Architecture.extractFromSysProperty("i486").is(X86)).isTrue();
}
@Test
public void determineArchI86() {
- assertTrue(Architecture.extractFromSysProperty("i86").is(Architecture.X86));
+ assertThat(Architecture.extractFromSysProperty("i86").is(X86)).isTrue();
}
@Test
public void determineArchPentium() {
- assertTrue(Architecture.extractFromSysProperty("pentium").is(Architecture.X86));
+ assertThat(Architecture.extractFromSysProperty("pentium").is(X86)).isTrue();
}
@Test
public void determineArchPentiumPro() {
- assertTrue(Architecture.extractFromSysProperty("pentium_pro").is(Architecture.X86));
+ assertThat(Architecture.extractFromSysProperty("pentium_pro").is(X86)).isTrue();
}
@Test
public void determineArchPentiumProMmx() {
- assertTrue(Architecture.extractFromSysProperty("pentium_pro+mmx").is(Architecture.X86));
+ assertThat(Architecture.extractFromSysProperty("pentium_pro+mmx").is(X86))
+ .isTrue();
}
@Test
public void determineArchPentiumMmx() {
- assertTrue(Architecture.extractFromSysProperty("pentium+mmx").is(Architecture.X86));
+ assertThat(Architecture.extractFromSysProperty("pentium+mmx").is(X86)).isTrue();
}
@Test
public void determineArchAMD64() {
- assertTrue(Architecture.extractFromSysProperty("amd64").is(Architecture.X64));
+ assertThat(Architecture.extractFromSysProperty("amd64").is(X64)).isTrue();
}
@Test
public void determineArchIA64() {
- assertTrue(Architecture.extractFromSysProperty("ia64").is(Architecture.X64));
+ assertThat(Architecture.extractFromSysProperty("ia64").is(X64)).isTrue();
}
@Test
public void determineArchARM() {
- assertTrue(Architecture.extractFromSysProperty("arm").is(Architecture.ARM));
+ assertThat(Architecture.extractFromSysProperty("arm").is(ARM)).isTrue();
}
@Test
public void determineArchEmpty() {
- Throwable t = catchThrowable(() -> Architecture.extractFromSysProperty(""));
- assertThat(t, instanceOf(UnsupportedOperationException.class));
- assertThat(t.getMessage(), containsString("Unknown architecture"));
+ assertThatExceptionOfType(UnsupportedOperationException.class)
+ .isThrownBy(() -> Architecture.extractFromSysProperty(""))
+ .withMessageContaining("Unknown architecture");
}
@Test
public void determineArchBogus() {
- Throwable t = catchThrowable(() -> Architecture.extractFromSysProperty("hoobaflooba"));
- assertThat(t, instanceOf(UnsupportedOperationException.class));
- assertThat(t.getMessage(), containsString("Unknown architecture"));
+ assertThatExceptionOfType(UnsupportedOperationException.class)
+ .isThrownBy(() -> Architecture.extractFromSysProperty("hoobaflooba"))
+ .withMessageContaining("Unknown architecture");
}
@Test
public void determineArchMixedCasing() {
- assertTrue(Architecture.extractFromSysProperty("AmD64").is(Architecture.X64));
+ assertThat(Architecture.extractFromSysProperty("AmD64").is(X64)).isTrue();
}
@Test
public void dataModelIs32Or64BitOnCurrentArchitecture() {
int model = Architecture.getCurrent().getDataModel();
- assertTrue(model == 32 || model == 64);
+ assertThat(model == 32 || model == 64).isTrue();
}
@Test
public void x86DataModelIs32Bit() {
- assertEquals(32, Architecture.X86.getDataModel());
+ assertThat(X86.getDataModel()).isEqualTo(32);
}
@Test
public void x64DataModelIs64Bit() {
- assertEquals(64, Architecture.X64.getDataModel());
+ assertThat(X64.getDataModel()).isEqualTo(64);
}
@Test
public void armDataModelIs64Bit() {
- assertEquals(64, Architecture.ARM.getDataModel());
+ assertThat(ARM.getDataModel()).isEqualTo(64);
}
@Test
public void anyDataModelIs64Bit() {
- assertEquals(64, Architecture.ANY.getDataModel());
+ assertThat(ANY.getDataModel()).isEqualTo(64);
}
}
diff --git a/java/client/test/org/openqa/selenium/AtomsInjectionTest.java b/java/client/test/org/openqa/selenium/AtomsInjectionTest.java
index e374c7b0773fe..780253c7bb699 100644
--- a/java/client/test/org/openqa/selenium/AtomsInjectionTest.java
+++ b/java/client/test/org/openqa/selenium/AtomsInjectionTest.java
@@ -17,7 +17,7 @@
package org.openqa.selenium;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.openqa.selenium.testing.JUnit4TestBase;
@@ -28,6 +28,6 @@ public class AtomsInjectionTest extends JUnit4TestBase {
public void testInjectingAtomShouldNotTrampleOnUnderscoreGlobal() {
driver.get(pages.underscorePage);
driver.findElement(By.tagName("body"));
- assertEquals("123", ((JavascriptExecutor) driver).executeScript("return _.join('');"));
+ assertThat(((JavascriptExecutor) driver).executeScript("return _.join('');")).isEqualTo("123");
}
}
diff --git a/java/client/test/org/openqa/selenium/BUCK b/java/client/test/org/openqa/selenium/BUCK
index cce37e4e6842c..c61b65e287a90 100644
--- a/java/client/test/org/openqa/selenium/BUCK
+++ b/java/client/test/org/openqa/selenium/BUCK
@@ -87,7 +87,7 @@ java_library(name = 'tests',
'//java/client/test/org/openqa/selenium/testing/drivers:drivers',
'//third_party/java/gson:gson',
'//third_party/java/guava:guava',
- '//third_party/java/hamcrest:hamcrest-library',
+ '//third_party/java/assertj:assertj',
'//third_party/java/jetty:jetty',
'//third_party/java/junit:junit',
'//third_party/java/mockito:mockito-core',
diff --git a/java/client/test/org/openqa/selenium/ByTest.java b/java/client/test/org/openqa/selenium/ByTest.java
index e912565f5fa92..c013b9c831fc0 100644
--- a/java/client/test/org/openqa/selenium/ByTest.java
+++ b/java/client/test/org/openqa/selenium/ByTest.java
@@ -17,15 +17,20 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.openqa.selenium.By.ByClassName;
+import static org.openqa.selenium.By.ByCssSelector;
+import static org.openqa.selenium.By.ById;
+import static org.openqa.selenium.By.ByLinkText;
+import static org.openqa.selenium.By.ByName;
+import static org.openqa.selenium.By.ByPartialLinkText;
+import static org.openqa.selenium.By.ByTagName;
+import static org.openqa.selenium.By.ByXPath;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
import org.openqa.selenium.internal.FindsByClassName;
import org.openqa.selenium.internal.FindsById;
import org.openqa.selenium.internal.FindsByLinkText;
@@ -35,7 +40,6 @@
import java.util.List;
-@RunWith(JUnit4.class)
public class ByTest {
@Test
@@ -138,14 +142,14 @@ public void searchesByXPathIfFindingByClassNameNotSupported() {
@Test
public void innerClassesArePublicSoThatTheyCanBeReusedElsewhere() {
- assertThat(new By.ByXPath("a").toString(), equalTo("By.xpath: a"));
- assertThat(new By.ById("a").toString(), equalTo("By.id: a"));
- assertThat(new By.ByClassName("a").toString(), equalTo("By.className: a"));
- assertThat(new By.ByLinkText("a").toString(), equalTo("By.linkText: a"));
- assertThat(new By.ByName("a").toString(), equalTo("By.name: a"));
- assertThat(new By.ByTagName("a").toString(), equalTo("By.tagName: a"));
- assertThat(new By.ByCssSelector("a").toString(), equalTo("By.cssSelector: a"));
- assertThat(new By.ByPartialLinkText("a").toString(), equalTo("By.partialLinkText: a"));
+ assertThat(new ByXPath("a").toString()).isEqualTo("By.xpath: a");
+ assertThat(new ById("a").toString()).isEqualTo("By.id: a");
+ assertThat(new ByClassName("a").toString()).isEqualTo("By.className: a");
+ assertThat(new ByLinkText("a").toString()).isEqualTo("By.linkText: a");
+ assertThat(new ByName("a").toString()).isEqualTo("By.name: a");
+ assertThat(new ByTagName("a").toString()).isEqualTo("By.tagName: a");
+ assertThat(new ByCssSelector("a").toString()).isEqualTo("By.cssSelector: a");
+ assertThat(new ByPartialLinkText("a").toString()).isEqualTo("By.partialLinkText: a");
}
// See http://code.google.com/p/selenium/issues/detail?id=2917
diff --git a/java/client/test/org/openqa/selenium/ChildrenFindingTest.java b/java/client/test/org/openqa/selenium/ChildrenFindingTest.java
index d8b7ab9c6beac..d7eee1a6487e3 100644
--- a/java/client/test/org/openqa/selenium/ChildrenFindingTest.java
+++ b/java/client/test/org/openqa/selenium/ChildrenFindingTest.java
@@ -17,19 +17,12 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.openqa.selenium.testing.Driver.CHROME;
import static org.openqa.selenium.testing.Driver.SAFARI;
-import static org.openqa.selenium.testing.TestUtilities.catchThrowable;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JUnit4TestBase;
@@ -38,15 +31,12 @@
public class ChildrenFindingTest extends JUnit4TestBase {
- @Rule
- public final ExpectedException expectedException = ExpectedException.none();
-
@Test
public void testFindElementByXPath() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.name("form2"));
WebElement child = element.findElement(By.xpath("select"));
- assertThat(child.getAttribute("id"), is("2"));
+ assertThat(child.getAttribute("id")).isEqualTo("2");
}
@Test
@@ -55,7 +45,7 @@ public void testFindingElementsOnElementByXPathShouldFindTopLevelElements() {
WebElement parent = driver.findElement(By.id("multiline"));
List allPs = driver.findElements(By.xpath("//p"));
List children = parent.findElements(By.xpath("//p"));
- assertEquals(allPs.size(), children.size());
+ assertThat(allPs.size()).isEqualTo(children.size());
}
@Test
@@ -63,16 +53,16 @@ public void testFindingDotSlashElementsOnElementByXPathShouldFindNotTopLevelElem
driver.get(pages.simpleTestPage);
WebElement parent = driver.findElement(By.id("multiline"));
List children = parent.findElements(By.xpath("./p"));
- assertEquals(1, children.size());
- assertEquals("A div containing", children.get(0).getText());
+ assertThat(children).hasSize(1);
+ assertThat(children.get(0).getText()).isEqualTo("A div containing");
}
@Test
public void testFindElementByXPathWhenNoMatch() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.name("form2"));
- Throwable t = catchThrowable(() -> element.findElement(By.xpath(".//select/x")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> element.findElement(By.xpath(".//select/x")));
}
@Test
@@ -80,9 +70,9 @@ public void testFindElementsByXPath() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.name("form2"));
List children = element.findElements(By.xpath("select/option"));
- assertThat(children.size(), is(8));
- assertThat(children.get(0).getText(), is("One"));
- assertThat(children.get(1).getText(), is("Two"));
+ assertThat(children).hasSize(8);
+ assertThat(children.get(0).getText()).isEqualTo("One");
+ assertThat(children.get(1).getText()).isEqualTo("Two");
}
@Test
@@ -90,7 +80,7 @@ public void testFindElementsByXPathWhenNoMatch() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.name("form2"));
List children = element.findElements(By.xpath(".//select/x"));
- assertEquals(0, children.size());
+ assertThat(children).hasSize(0);
}
@Test
@@ -98,7 +88,7 @@ public void testFindElementByName() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.name("form2"));
WebElement child = element.findElement(By.name("selectomatic"));
- assertThat(child.getAttribute("id"), is("2"));
+ assertThat(child.getAttribute("id")).isEqualTo("2");
}
@Test
@@ -106,7 +96,7 @@ public void testFindElementsByName() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.name("form2"));
List children = element.findElements(By.name("selectomatic"));
- assertThat(children.size(), is(2));
+ assertThat(children).hasSize(2);
}
@Test
@@ -114,7 +104,7 @@ public void testFindElementById() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.name("form2"));
WebElement child = element.findElement(By.id("2"));
- assertThat(child.getAttribute("name"), is("selectomatic"));
+ assertThat(child.getAttribute("name")).isEqualTo("selectomatic");
}
@Test
@@ -122,7 +112,7 @@ public void testFindElementByIdWhenMultipleMatchesExist() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.id("test_id_div"));
WebElement child = element.findElement(By.id("test_id"));
- assertThat(child.getText(), is("inside"));
+ assertThat(child.getText()).isEqualTo("inside");
}
@Test
@@ -132,17 +122,17 @@ public void testFindElementByIdWhenIdContainsNonAlphanumericCharacters() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.id("test_special_chars"));
WebElement childWithSpaces = element.findElement(By.id("white space"));
- assertThat(childWithSpaces.getText(), is("space"));
+ assertThat(childWithSpaces.getText()).isEqualTo("space");
WebElement childWithCssChars = element.findElement(By.id("css#.chars"));
- assertThat(childWithCssChars.getText(), is("css escapes"));
+ assertThat(childWithCssChars.getText()).isEqualTo("css escapes");
}
@Test
public void testFindElementByIdWhenNoMatchInContext() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.id("test_id_div"));
- Throwable t = catchThrowable(() -> element.findElement(By.id("test_id_out")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> element.findElement(By.id("test_id_out")));
}
@Test
@@ -150,7 +140,7 @@ public void testFindElementsById() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.name("form2"));
List children = element.findElements(By.id("2"));
- assertThat(children.size(), is(2));
+ assertThat(children).hasSize(2);
}
@Test
@@ -160,9 +150,9 @@ public void testFindElementsByIdWithNonAlphanumericCharacters() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.id("test_special_chars"));
List children = element.findElements(By.id("white space"));
- assertThat(children.size(), is(1));
+ assertThat(children).hasSize(1);
List children2 = element.findElements(By.id("css#.chars"));
- assertThat(children2.size(), is(1));
+ assertThat(children2).hasSize(1);
}
@Test
@@ -171,8 +161,8 @@ public void testFindElementByLinkText() {
WebElement element = driver.findElement(By.name("div1"));
WebElement child = element.findElement(By.linkText("hello world"));
List invalidChildren = element.findElements(By.linkText("HellO WorLD"));
- assertEquals(0, invalidChildren.size());
- assertThat(child.getAttribute("name"), is("link1"));
+ assertThat(invalidChildren).hasSize(0);
+ assertThat(child.getAttribute("name")).isEqualTo("link1");
}
@Test
@@ -181,9 +171,9 @@ public void testFindElementsByLinkTest() {
WebElement element = driver.findElement(By.name("div1"));
List elements = element.findElements(By.linkText("hello world"));
- assertEquals(2, elements.size());
- assertThat(elements.get(0).getAttribute("name"), is("link1"));
- assertThat(elements.get(1).getAttribute("name"), is("link2"));
+ assertThat(elements).hasSize(2);
+ assertThat(elements.get(0).getAttribute("name")).isEqualTo("link1");
+ assertThat(elements.get(1).getAttribute("name")).isEqualTo("link2");
}
@Test
@@ -191,7 +181,7 @@ public void testShouldFindChildElementsById() {
driver.get(pages.nestedPage);
WebElement parent = driver.findElement(By.id("test_id_div"));
WebElement element = parent.findElement(By.id("test_id"));
- assertEquals("inside", element.getText());
+ assertThat(element.getText()).isEqualTo("inside");
}
@Test
@@ -200,9 +190,9 @@ public void testShouldNotReturnRootElementWhenFindingChildrenById() {
driver.get(pages.nestedPage);
WebElement parent = driver.findElement(By.id("test_id"));
- assertEquals(0, parent.findElements(By.id("test_id")).size());
- expectedException.expect(NoSuchElementException.class);
- parent.findElement(By.id("test_id"));
+ assertThat(parent.findElements(By.id("test_id"))).hasSize(0);
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> parent.findElement(By.id("test_id")));
}
@Test
@@ -212,7 +202,7 @@ public void testShouldFindChildElementsByClassName() {
WebElement element = parent.findElement(By.className("one"));
- assertEquals("Find me", element.getText());
+ assertThat(element.getText()).isEqualTo("Find me");
}
@Test
@@ -222,7 +212,7 @@ public void testShouldFindChildrenByClassName() {
List elements = parent.findElements(By.className("one"));
- assertEquals(2, elements.size());
+ assertThat(elements).hasSize(2);
}
@Test
@@ -232,7 +222,7 @@ public void testShouldFindChildElementsByTagName() {
WebElement element = parent.findElement(By.tagName("a"));
- assertEquals("link1", element.getAttribute("name"));
+ assertThat(element.getAttribute("name")).isEqualTo("link1");
}
@Test
@@ -242,7 +232,7 @@ public void testShouldFindChildrenByTagName() {
List elements = parent.findElements(By.tagName("a"));
- assertEquals(2, elements.size());
+ assertThat(elements).hasSize(2);
}
@Test
@@ -252,7 +242,7 @@ public void testShouldBeAbleToFindAnElementByCssSelector() {
WebElement element = parent.findElement(By.cssSelector("*[name=\"selectomatic\"]"));
- assertEquals("2", element.getAttribute("id"));
+ assertThat(element.getAttribute("id")).isEqualTo("2");
}
@Test
@@ -262,7 +252,7 @@ public void testShouldBeAbleToFindAnElementByCss3Selector() {
WebElement element = parent.findElement(By.cssSelector("*[name^=\"selecto\"]"));
- assertEquals("2", element.getAttribute("id"));
+ assertThat(element.getAttribute("id")).isEqualTo("2");
}
@Test
@@ -272,7 +262,7 @@ public void testShouldBeAbleToFindElementsByCssSelector() {
List elements = parent.findElements(By.cssSelector("*[name=\"selectomatic\"]"));
- assertEquals(2, elements.size());
+ assertThat(elements).hasSize(2);
}
@Test
@@ -281,7 +271,7 @@ public void testShouldBeAbleToFindChildrenOfANode() {
List elements = driver.findElements(By.xpath("/html/head"));
WebElement head = elements.get(0);
List importedScripts = head.findElements(By.tagName("script"));
- assertThat(importedScripts.size(), equalTo(3));
+ assertThat(importedScripts).hasSize(3);
}
@Test
@@ -290,7 +280,7 @@ public void testReturnAnEmptyListWhenThereAreNoChildrenOfANode() {
WebElement table = driver.findElement(By.id("table"));
List rows = table.findElements(By.tagName("tr"));
- assertThat(rows.size(), equalTo(0));
+ assertThat(rows).hasSize(0);
}
@Test
@@ -304,8 +294,8 @@ public void testShouldFindGrandChildren() {
public void testShouldNotFindElementOutSideTree() {
driver.get(pages.formPage);
WebElement element = driver.findElement(By.name("login"));
- Throwable t = catchThrowable(() -> element.findElement(By.name("x")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> element.findElement(By.name("x")));
}
@Test
@@ -313,8 +303,8 @@ public void testFindingByTagNameShouldNotIncludeParentElementIfSameTagType() {
driver.get(pages.xhtmlTestPage);
WebElement parent = driver.findElement(By.id("my_span"));
- assertEquals(2, parent.findElements(By.tagName("div")).size());
- assertEquals(2, parent.findElements(By.tagName("span")).size());
+ assertThat(parent.findElements(By.tagName("div"))).hasSize(2);
+ assertThat(parent.findElements(By.tagName("span"))).hasSize(2);
}
@Test
@@ -323,7 +313,7 @@ public void testFindingByCssShouldNotIncludeParentElementIfSameTagType() {
WebElement parent = driver.findElement(By.cssSelector("div#parent"));
WebElement child = parent.findElement(By.cssSelector("div"));
- assertEquals("child", child.getAttribute("id"));
+ assertThat(child.getAttribute("id")).isEqualTo("child");
}
@Test
@@ -332,8 +322,7 @@ public void testFindMultipleElements() {
WebElement elem = driver.findElement(By.id("links"));
List elements = elem.findElements(By.partialLinkText("link"));
- assertNotNull(elements);
- assertEquals(6, elements.size());
+ assertThat(elements).hasSize(6);
}
@Test
@@ -343,7 +332,7 @@ public void testLinkWithLeadingSpaces() {
WebElement elem = driver.findElement(By.id("links"));
WebElement res = elem.findElement(By.partialLinkText("link with leading space"));
- assertEquals("link with leading space", res.getText());
+ assertThat(res.getText()).isEqualTo("link with leading space");
}
@Test
@@ -353,7 +342,7 @@ public void testLinkWithTrailingSpace() {
WebElement elem = driver.findElement(By.id("links"));
WebElement res = elem.findElement(By.partialLinkText("link with trailing space"));
- assertEquals("link with trailing space", res.getText());
+ assertThat(res.getText()).isEqualTo("link with trailing space");
}
@Test
@@ -362,7 +351,7 @@ public void testElementCanGetLinkByLinkTestIgnoringTrailingWhitespace() {
WebElement elem = driver.findElement(By.id("links"));
WebElement link = elem.findElement(By.linkText("link with trailing space"));
- assertEquals("linkWithTrailingSpace", link.getAttribute("id"));
+ assertThat(link.getAttribute("id")).isEqualTo("linkWithTrailingSpace");
}
}
diff --git a/java/client/test/org/openqa/selenium/ClearTest.java b/java/client/test/org/openqa/selenium/ClearTest.java
index eab3eee5f0e81..2317d4d0e14e5 100644
--- a/java/client/test/org/openqa/selenium/ClearTest.java
+++ b/java/client/test/org/openqa/selenium/ClearTest.java
@@ -17,16 +17,14 @@
package org.openqa.selenium;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.openqa.selenium.testing.Driver.CHROME;
import static org.openqa.selenium.testing.Driver.FIREFOX;
import static org.openqa.selenium.testing.Driver.HTMLUNIT;
import static org.openqa.selenium.testing.Driver.IE;
import static org.openqa.selenium.testing.Driver.MARIONETTE;
import static org.openqa.selenium.testing.Driver.SAFARI;
-import static org.openqa.selenium.testing.TestUtilities.catchThrowable;
import org.junit.Test;
import org.openqa.selenium.testing.JUnit4TestBase;
@@ -39,24 +37,24 @@ public void testWritableTextInputShouldClear() {
driver.get(pages.readOnlyPage);
WebElement element = driver.findElement(By.id("writableTextInput"));
element.clear();
- assertEquals("", element.getAttribute("value"));
+ assertThat(element.getAttribute("value")).isEqualTo("");
}
@Test
public void testTextInputShouldNotClearWhenDisabled() {
driver.get(pages.readOnlyPage);
WebElement element = driver.findElement(By.id("textInputnotenabled"));
- assertEquals(false, element.isEnabled());
- Throwable t = catchThrowable(element::clear);
- assertThat(t, instanceOf(InvalidElementStateException.class));
+ assertThat(element.isEnabled()).isFalse();
+ assertThatExceptionOfType(InvalidElementStateException.class)
+ .isThrownBy(element::clear);
}
@Test
public void testTextInputShouldNotClearWhenReadOnly() {
driver.get(pages.readOnlyPage);
WebElement element = driver.findElement(By.id("readOnlyTextInput"));
- Throwable t = catchThrowable(element::clear);
- assertThat(t, instanceOf(InvalidElementStateException.class));
+ assertThatExceptionOfType(InvalidElementStateException.class)
+ .isThrownBy(element::clear);
}
@Test
@@ -64,23 +62,23 @@ public void testWritableTextAreaShouldClear() {
driver.get(pages.readOnlyPage);
WebElement element = driver.findElement(By.id("writableTextArea"));
element.clear();
- assertEquals("", element.getAttribute("value"));
+ assertThat(element.getAttribute("value")).isEqualTo("");
}
@Test
public void testTextAreaShouldNotClearWhenDisabled() {
driver.get(pages.readOnlyPage);
WebElement element = driver.findElement(By.id("textAreaNotenabled"));
- Throwable t = catchThrowable(element::clear);
- assertThat(t, instanceOf(InvalidElementStateException.class));
+ assertThatExceptionOfType(InvalidElementStateException.class)
+ .isThrownBy(element::clear);
}
@Test
public void testTextAreaShouldNotClearWhenReadOnly() {
driver.get(pages.readOnlyPage);
WebElement element = driver.findElement(By.id("textAreaReadOnly"));
- Throwable t = catchThrowable(element::clear);
- assertThat(t, instanceOf(InvalidElementStateException.class));
+ assertThatExceptionOfType(InvalidElementStateException.class)
+ .isThrownBy(element::clear);
}
@Test
@@ -88,7 +86,7 @@ public void testContentEditableAreaShouldClear() {
driver.get(pages.readOnlyPage);
WebElement element = driver.findElement(By.id("content-editable"));
element.clear();
- assertEquals("", element.getText());
+ assertThat(element.getText()).isEqualTo("");
}
@Test
@@ -205,9 +203,9 @@ public void shouldBeAbleToClearWeekInput() {
private void shouldBeAbleToClearInput(By locator, String oldValue) {
driver.get(appServer.whereIs("inputs.html"));
WebElement element = driver.findElement(locator);
- assertEquals(oldValue, element.getAttribute("value"));
+ assertThat(element.getAttribute("value")).isEqualTo(oldValue);
element.clear();
- assertEquals("", element.getAttribute("value"));
+ assertThat(element.getAttribute("value")).isEqualTo("");
}
}
diff --git a/java/client/test/org/openqa/selenium/ClickScrollingTest.java b/java/client/test/org/openqa/selenium/ClickScrollingTest.java
index 012733a3b4467..1f24e4590c640 100644
--- a/java/client/test/org/openqa/selenium/ClickScrollingTest.java
+++ b/java/client/test/org/openqa/selenium/ClickScrollingTest.java
@@ -17,12 +17,8 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assume.assumeFalse;
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
@@ -33,7 +29,6 @@
import static org.openqa.selenium.testing.Driver.IE;
import static org.openqa.selenium.testing.Driver.MARIONETTE;
import static org.openqa.selenium.testing.Driver.SAFARI;
-import static org.openqa.selenium.testing.TestUtilities.catchThrowable;
import org.junit.Test;
import org.openqa.selenium.interactions.MoveTargetOutOfBoundsException;
@@ -65,7 +60,7 @@ public void testClickingOnAnchorScrollsPage() {
// Focusing on to click, but not actually following,
// the link will scroll it in to view, which is a few pixels further than 0
- assertThat("Did not scroll", yOffset, is(greaterThan(300L)));
+ assertThat(yOffset).describedAs("Did not scroll").isGreaterThan(300L);
}
@Test
@@ -84,7 +79,7 @@ public void testShouldBeAbleToClickOnAnElementHiddenByOverflow() {
WebElement link = driver.findElement(By.id("line8"));
// This used to throw a MoveTargetOutOfBoundsException - we don't expect it to
link.click();
- assertEquals("line8", driver.findElement(By.id("clicked")).getText());
+ assertThat(driver.findElement(By.id("clicked")).getText()).isEqualTo("line8");
}
@Test
@@ -122,7 +117,7 @@ public void testShouldNotScrollOverflowElementsWhichAreVisible() {
item.click();
long yOffset =
(Long)((JavascriptExecutor)driver).executeScript("return arguments[0].scrollTop;", list);
- assertEquals("Should not have scrolled", 0, yOffset);
+ assertThat(yOffset).describedAs("Should not have scrolled").isEqualTo(0);
}
@Test
@@ -133,7 +128,7 @@ public void testShouldNotScrollIfAlreadyScrolledAndElementIsInView() {
driver.findElement(By.id("button1")).click();
long scrollTop = getScrollTop();
driver.findElement(By.id("button2")).click();
- assertEquals(scrollTop, getScrollTop());
+ assertThat(getScrollTop()).isEqualTo(scrollTop);
}
@Test
@@ -149,7 +144,7 @@ public void testShouldBeAbleToClickRadioButtonScrolledIntoView() {
public void testShouldScrollOverflowElementsIfClickPointIsOutOfViewButElementIsInView() {
driver.get(appServer.whereIs("scroll5.html"));
driver.findElement(By.id("inner")).click();
- assertEquals("clicked", driver.findElement(By.id("clicked")).getText());
+ assertThat(driver.findElement(By.id("clicked")).getText()).isEqualTo("clicked");
}
@SwitchToTopAfterTest
@@ -161,7 +156,7 @@ public void testShouldBeAbleToClickElementInAFrameThatIsOutOfView() {
driver.switchTo().frame("frame");
WebElement element = driver.findElement(By.name("checkbox"));
element.click();
- assertTrue(element.isSelected());
+ assertThat(element.isSelected()).isTrue();
}
@SwitchToTopAfterTest
@@ -172,7 +167,7 @@ public void testShouldBeAbleToClickElementThatIsOutOfViewInAFrame() {
driver.switchTo().frame("scrolling_frame");
WebElement element = driver.findElement(By.name("scroll_checkbox"));
element.click();
- assertTrue(element.isSelected());
+ assertThat(element.isSelected()).isTrue();
}
@SwitchToTopAfterTest
@@ -182,8 +177,7 @@ public void testShouldNotBeAbleToClickElementThatIsOutOfViewInANonScrollableFram
driver.get(appServer.whereIs("scrolling_tests/page_with_non_scrolling_frame.html"));
driver.switchTo().frame("scrolling_frame");
WebElement element = driver.findElement(By.name("scroll_checkbox"));
- Throwable t = catchThrowable(element::click);
- assertThat(t, instanceOf(MoveTargetOutOfBoundsException.class));
+ assertThatExceptionOfType(MoveTargetOutOfBoundsException.class).isThrownBy(element::click);
}
@SwitchToTopAfterTest
@@ -194,7 +188,7 @@ public void testShouldBeAbleToClickElementThatIsOutOfViewInAFrameThatIsOutOfView
driver.switchTo().frame("scrolling_frame");
WebElement element = driver.findElement(By.name("scroll_checkbox"));
element.click();
- assertTrue(element.isSelected());
+ assertThat(element.isSelected()).isTrue();
}
@SwitchToTopAfterTest
@@ -206,7 +200,7 @@ public void testShouldBeAbleToClickElementThatIsOutOfViewInANestedFrame() {
driver.switchTo().frame("nested_scrolling_frame");
WebElement element = driver.findElement(By.name("scroll_checkbox"));
element.click();
- onlyPassIfNotOnMac(651, () -> assertTrue(element.isSelected()));
+ onlyPassIfNotOnMac(651, () -> assertThat(element.isSelected()).isTrue());
}
@SwitchToTopAfterTest
@@ -219,7 +213,7 @@ public void testShouldBeAbleToClickElementThatIsOutOfViewInANestedFrameThatIsOut
WebElement element = driver.findElement(By.name("scroll_checkbox"));
element.click();
- onlyPassIfNotOnMac(651, () -> assertTrue(element.isSelected()));
+ onlyPassIfNotOnMac(651, () -> assertThat(element.isSelected()).isTrue());
}
private void onlyPassIfNotOnMac(int mozIssue, Runnable toCheck) {
@@ -241,7 +235,7 @@ public void testShouldNotScrollWhenGettingElementSize() {
driver.get(appServer.whereIs("scroll3.html"));
long scrollTop = getScrollTop();
driver.findElement(By.id("button1")).getSize();
- assertEquals(scrollTop, getScrollTop());
+ assertThat(getScrollTop()).isEqualTo(scrollTop);
}
private long getScrollTop() {
@@ -258,6 +252,6 @@ public void testShouldBeAbleToClickElementInATallFrame() {
driver.switchTo().frame("tall_frame");
WebElement element = driver.findElement(By.name("checkbox"));
element.click();
- assertTrue(element.isSelected());
+ assertThat(element.isSelected()).isTrue();
}
}
diff --git a/java/client/test/org/openqa/selenium/ClickTest.java b/java/client/test/org/openqa/selenium/ClickTest.java
index d7b4a6190cb9b..33f47169e17c9 100644
--- a/java/client/test/org/openqa/selenium/ClickTest.java
+++ b/java/client/test/org/openqa/selenium/ClickTest.java
@@ -17,8 +17,7 @@
package org.openqa.selenium;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.openqa.selenium.Platform.ANDROID;
@@ -76,7 +75,7 @@ public void testCanClickOnAnAnchorAndNotReloadThePage() {
Boolean samePage = (Boolean) ((JavascriptExecutor) driver)
.executeScript("return document.latch");
- assertEquals("Latch was reset", Boolean.TRUE, samePage);
+ assertThat(samePage).as("Latch was reset").isTrue();
}
@SwitchToTopAfterTest
@@ -131,7 +130,7 @@ public void testCanClickOnAnElementWithTopSetToANegativeNumber() {
driver.findElement(By.name("btn")).click();
String log = driver.findElement(By.id("log")).getText();
- assertEquals("click", log);
+ assertThat(log).isEqualTo("click");
}
@Test
@@ -144,7 +143,7 @@ public void testShouldSetRelatedTargetForMouseOver() {
String log = driver.findElement(By.id("result")).getText();
- assertEquals("parent matches? true", log);
+ assertThat(log).isEqualTo("parent matches? true");
}
@Test
@@ -183,9 +182,7 @@ public void testClickingLabelShouldSetCheckbox() {
driver.findElement(By.id("label-for-checkbox-with-label")).click();
- assertTrue(
- "Should be selected",
- driver.findElement(By.id("checkbox-with-label")).isSelected());
+ assertThat(driver.findElement(By.id("checkbox-with-label")).isSelected()).isTrue();
}
@Test
diff --git a/java/client/test/org/openqa/selenium/ContentEditableTest.java b/java/client/test/org/openqa/selenium/ContentEditableTest.java
index 8cc77f92eb86a..028d099250c1c 100644
--- a/java/client/test/org/openqa/selenium/ContentEditableTest.java
+++ b/java/client/test/org/openqa/selenium/ContentEditableTest.java
@@ -17,10 +17,7 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.anyOf;
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeFalse;
import static org.openqa.selenium.testing.Driver.CHROME;
import static org.openqa.selenium.testing.Driver.EDGE;
@@ -56,12 +53,8 @@ public void testTypingIntoAnIFrameWithContentEditableOrDesignModeSet() {
WebElement trusted = driver.findElement(By.id("istrusted"));
WebElement id = driver.findElement(By.id("tagId"));
- assertThat(trusted.getText(), anyOf(
- equalTo("[true]"),
- // Chrome does not set a trusted flag.
- equalTo("[n/a]"),
- equalTo("[]")));
- assertThat(id.getText(), anyOf(equalTo("[frameHtml]"), equalTo("[theBody]")));
+ assertThat(trusted.getText()).isIn("[true]", "[n/a]", "[]");
+ assertThat(id.getText()).isIn("[frameHtml]", "[theBody]");
}
@Test
@@ -79,7 +72,7 @@ public void testNonPrintableCharactersShouldWorkWithContentEditableOrDesignModeS
element.sendKeys("Dishy", Keys.BACK_SPACE, Keys.LEFT, Keys.LEFT);
element.sendKeys(Keys.LEFT, Keys.LEFT, "F", Keys.DELETE, Keys.END, "ee!");
- assertEquals("Fishee!", element.getText());
+ assertThat(element.getText()).isEqualTo("Fishee!");
}
@Test
@@ -89,7 +82,7 @@ public void testShouldBeAbleToTypeIntoEmptyContentEditableElement() {
editable.sendKeys("cheese");
- assertThat(editable.getText(), equalTo("cheese"));
+ assertThat(editable.getText()).isEqualTo("cheese");
}
@Test
@@ -104,7 +97,7 @@ public void testShouldBeAbleToTypeIntoContentEditableElementWithExistingValue()
String initialText = editable.getText();
editable.sendKeys(", edited");
- assertThat(editable.getText(), equalTo(initialText + ", edited"));
+ assertThat(editable.getText()).isEqualTo(initialText + ", edited");
}
@Test
@@ -118,7 +111,7 @@ public void testShouldBeAbleToTypeIntoTinyMCE() {
editable.clear();
editable.sendKeys("cheese"); // requires focus on OS X
- assertThat(editable.getText(), equalTo("cheese"));
+ assertThat(editable.getText()).isEqualTo("cheese");
}
@Test
@@ -134,7 +127,7 @@ public void testShouldAppendToTinyMCE() {
editable.sendKeys(" and cheese"); // requires focus on OS X
- assertThat(editable.getText(), equalTo("Initial content and cheese"));
+ assertThat(editable.getText()).isEqualTo("Initial content and cheese");
}
@Test
@@ -146,8 +139,7 @@ public void appendsTextToEndOfContentEditableWithMultipleTextNodes() {
driver.get(appServer.whereIs("content-editable.html"));
WebElement input = driver.findElement(By.id("editable"));
input.sendKeys(", world!");
- System.out.println("input.getText() = " + input.getText());
- assertEquals("Why hello, world!", input.getText());
+ assertThat(input.getText()).isEqualTo("Why hello, world!");
}
}
diff --git a/java/client/test/org/openqa/selenium/CookieImplementationTest.java b/java/client/test/org/openqa/selenium/CookieImplementationTest.java
index 06c70689ce3f2..c125bd40d99d3 100644
--- a/java/client/test/org/openqa/selenium/CookieImplementationTest.java
+++ b/java/client/test/org/openqa/selenium/CookieImplementationTest.java
@@ -17,15 +17,7 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
import static org.openqa.selenium.testing.Driver.ALL;
import static org.openqa.selenium.testing.Driver.CHROME;
@@ -85,14 +77,14 @@ public void testShouldGetCookieByName() {
addCookieOnServerSide(new Cookie(key, value));
Cookie cookie = driver.manage().getCookieNamed(key);
- assertEquals(value, cookie.getValue());
+ assertThat(cookie.getValue()).isEqualTo(value);
}
@Test
public void testShouldBeAbleToAddCookie() {
String key = generateUniqueKey();
String value = "foo";
- Cookie cookie = new Cookie.Builder(key, value).build();
+ Cookie cookie = new Cookie.Builder(key, value).domain("comp1").build();
assertCookieIsNotPresentWithName(key);
driver.manage().addCookie(cookie);
@@ -122,10 +114,10 @@ public void testGetAllCookies() {
openAnotherPage();
cookies = driver.manage().getCookies();
- assertEquals(countBefore + 2, cookies.size());
+ assertThat(cookies.size()).isEqualTo(countBefore + 2);
- assertTrue(cookies.contains(one));
- assertTrue(cookies.contains(two));
+ assertThat(cookies.contains(one)).isTrue();
+ assertThat(cookies.contains(two)).isTrue();
}
@Test
@@ -178,8 +170,8 @@ public void testShouldNotDeleteCookiesWithASimilarName() {
options.deleteCookieNamed(cookieOneName);
Set cookies = options.getCookies();
- assertFalse(cookies.toString(), cookies.contains(cookie1));
- assertTrue(cookies.toString(), cookies.contains(cookie2));
+ assertThat(cookies).doesNotContain(cookie1);
+ assertThat(cookies).contains(cookie2);
}
@Test
@@ -224,7 +216,7 @@ public void testCannotGetCookiesWithPathDifferingOnlyInCase() {
driver.manage().addCookie(cookie);
driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));
- assertNull(driver.manage().getCookieNamed(cookieName));
+ assertThat(driver.manage().getCookieNamed(cookieName)).isNull();
}
@Test
@@ -288,7 +280,7 @@ public void testShouldBeAbleToSetDomainToTheCurrentDomain() throws Exception {
driver.get(domainHelper.getUrlForFirstValidHostname("javascriptPage.html"));
Set cookies = driver.manage().getCookies();
- assertTrue(cookies.contains(cookie));
+ assertThat(cookies).contains(cookie);
}
@Test
@@ -307,12 +299,12 @@ public void testShouldWalkThePathToDeleteACookie() {
driver.get(domainHelper.getUrlForFirstValidHostname("child/grandchild/grandchildPage.html"));
driver.manage().deleteCookieNamed("rodent");
- assertNull(driver.manage().getCookies().toString(), driver.manage().getCookieNamed("rodent"));
+ assertThat(driver.manage().getCookieNamed("rodent")).isNull();
Set cookies = driver.manage().getCookies();
- assertEquals(2, cookies.size());
- assertTrue(cookies.contains(cookie1));
- assertTrue(cookies.contains(cookie3));
+ assertThat(cookies).hasSize(2);
+ assertThat(cookies).contains(cookie1);
+ assertThat(cookies).contains(cookie3);
driver.manage().deleteAllCookies();
driver.get(domainHelper.getUrlForFirstValidHostname("child/grandchild/grandchildPage.html"));
@@ -355,9 +347,9 @@ public void testCookieEqualityAfterSetAndGet() {
}
}
- assertNotNull("Cookie was null", retrievedCookie);
+ assertThat(retrievedCookie).isNotNull();
// Cookie.equals only compares name, domain and path
- assertEquals(addedCookie, retrievedCookie);
+ assertThat(retrievedCookie).isEqualTo(addedCookie);
}
@Test
@@ -370,8 +362,8 @@ public void testRetainsCookieExpiry() {
driver.manage().addCookie(addedCookie);
Cookie retrieved = driver.manage().getCookieNamed("fish");
- assertNotNull(retrieved);
- assertEquals(addedCookie.getExpiry(), retrieved.getExpiry());
+ assertThat(retrieved).isNotNull();
+ assertThat(retrieved.getExpiry()).isEqualTo(addedCookie.getExpiry());
}
@Test
@@ -390,7 +382,7 @@ public void canHandleSecureCookie() {
driver.navigate().refresh();
Cookie retrieved = driver.manage().getCookieNamed("fish");
- assertNotNull(retrieved);
+ assertThat(retrieved).isNotNull();
}
@Test
@@ -409,8 +401,8 @@ public void testRetainsCookieSecure() {
driver.navigate().refresh();
Cookie retrieved = driver.manage().getCookieNamed("fish");
- assertNotNull(retrieved);
- assertTrue(retrieved.isSecure());
+ assertThat(retrieved).isNotNull();
+ assertThat(retrieved.isSecure()).isTrue();
}
@Test
@@ -426,7 +418,7 @@ public void canHandleHttpOnlyCookie() {
driver.get(domainHelper.getUrlForFirstValidHostname("animals"));
Cookie retrieved = driver.manage().getCookieNamed("fish");
- assertNotNull(retrieved);
+ assertThat(retrieved).isNotNull();
}
@Test
@@ -443,8 +435,8 @@ public void testRetainsHttpOnlyFlag() {
driver.get(domainHelper.getUrlForFirstValidHostname("animals"));
Cookie retrieved = driver.manage().getCookieNamed("fish");
- assertNotNull(retrieved);
- assertTrue(retrieved.isHttpOnly());
+ assertThat(retrieved).isNotNull();
+ assertThat(retrieved.isHttpOnly()).isTrue();
}
@Test
@@ -454,8 +446,7 @@ public void testSettingACookieThatExpiredInThePast() {
driver.manage().addCookie(cookie);
cookie = driver.manage().getCookieNamed("fish");
- assertNull(
- "Cookie expired before it was set, so nothing should be returned: " + cookie, cookie);
+ assertThat(cookie).as("Cookie expired before it was set, so nothing should be returned").isNull();
}
@Test
@@ -492,14 +483,13 @@ public void testShouldDeleteOneOfTheCookiesWithTheSameName() {
WebDriver.Options options = driver.manage();
options.addCookie(cookie1);
options.addCookie(cookie2);
- assertEquals(driver.manage().getCookies().size(), 2);
+ assertThat(driver.manage().getCookies()).hasSize(2);
driver.manage().deleteCookie(cookie1);
- assertEquals(driver.manage().getCookies().size(), 1);
+ assertThat(driver.manage().getCookies()).hasSize(1);
Cookie retrieved = driver.manage().getCookieNamed("fish");
- assertNotNull("Cookie was null", retrieved);
- assertEquals(cookie2, retrieved);
+ assertThat(retrieved).isEqualTo(cookie2);
}
private String generateUniqueKey() {
@@ -507,53 +497,46 @@ private String generateUniqueKey() {
}
private void assertNoCookiesArePresent() {
- Set cookies = driver.manage().getCookies();
- assertTrue("Cookies were not empty, present: " + cookies,
- cookies.isEmpty());
+ assertThat(driver.manage().getCookies()).isEmpty();
String documentCookie = getDocumentCookieOrNull();
if (documentCookie != null) {
- assertEquals("Cookies were not empty", "", documentCookie);
+ assertThat(documentCookie).isEqualTo("");
}
}
private void assertSomeCookiesArePresent() {
- assertFalse("Cookies were empty",
- driver.manage().getCookies().isEmpty());
+ assertThat(driver.manage().getCookies()).isNotEmpty();
String documentCookie = getDocumentCookieOrNull();
if (documentCookie != null) {
- assertNotSame("Cookies were empty", "", documentCookie);
+ assertThat(documentCookie).as("Cookies were empty").isNotEqualTo("");
}
}
private void assertCookieIsNotPresentWithName(final String key) {
- assertNull("Cookie was present with name " + key, driver.manage().getCookieNamed(key));
+ assertThat(driver.manage().getCookieNamed(key)).as("Cookie with name " + key).isNull();
String documentCookie = getDocumentCookieOrNull();
if (documentCookie != null) {
- assertThat("Cookie was present with name " + key,
- documentCookie,
- not(containsString(key + "=")));
+ assertThat(documentCookie).as("Cookie with name " + key).doesNotContain((key + "="));
}
}
private void assertCookieIsPresentWithName(final String key) {
- assertNotNull("Cookie was not present with name " + key, driver.manage().getCookieNamed(key));
+ assertThat(driver.manage().getCookieNamed(key)).as("Cookie with name " + key).isNotNull();
String documentCookie = getDocumentCookieOrNull();
if (documentCookie != null) {
- assertThat("Cookie was not present with name " + key + ", got: " + documentCookie,
- documentCookie,
- containsString(key + "="));
+ assertThat(documentCookie)
+ .as("Cookie was not present with name " + key + ", got: " + documentCookie)
+ .contains(key + "=");
}
}
private void assertCookieHasValue(final String key, final String value) {
- assertEquals("Cookie had wrong value",
- value,
- driver.manage().getCookieNamed(key).getValue());
+ assertThat(driver.manage().getCookieNamed(key).getValue()).isEqualTo(value);
String documentCookie = getDocumentCookieOrNull();
if (documentCookie != null) {
- assertThat("Cookie was present with name " + key,
- documentCookie,
- containsString(key + "=" + value));
+ assertThat(documentCookie)
+ .as("Cookie was present with name " + key)
+ .contains(key + "=" + value);
}
}
diff --git a/java/client/test/org/openqa/selenium/CookieTest.java b/java/client/test/org/openqa/selenium/CookieTest.java
index 296ad56f23a6d..4e8ca5ecc5562 100644
--- a/java/client/test/org/openqa/selenium/CookieTest.java
+++ b/java/client/test/org/openqa/selenium/CookieTest.java
@@ -17,16 +17,10 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.openqa.selenium.testing.TestUtilities.catchThrowable;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -35,7 +29,6 @@
import java.io.ObjectOutputStream;
import java.util.Date;
-@RunWith(JUnit4.class)
public class CookieTest {
@Test
@@ -46,39 +39,39 @@ public void testCanCreateAWellFormedCookie() {
@Test
public void testShouldThrowAnExceptionWhenSemiColonExistsInTheCookieAttribute() {
Cookie cookie = new Cookie("hi;hi", "value", null, null, null, false);
- Throwable t = catchThrowable(cookie::validate);
- assertThat(t, instanceOf(IllegalArgumentException.class));
+ assertThatExceptionOfType(IllegalArgumentException.class)
+ .isThrownBy(cookie::validate);
}
@Test
public void testShouldThrowAnExceptionTheNameIsNull() {
Cookie cookie = new Cookie(null, "value", null, null, null, false);
- Throwable t = catchThrowable(cookie::validate);
- assertThat(t, instanceOf(IllegalArgumentException.class));
+ assertThatExceptionOfType(IllegalArgumentException.class)
+ .isThrownBy(cookie::validate);
}
@Test
public void testCookiesShouldAllowSecureToBeSet() {
Cookie cookie = new Cookie("name", "value", "", "/", new Date(), true);
- assertTrue(cookie.isSecure());
+ assertThat(cookie.isSecure()).isTrue();
}
@Test
public void testSecureDefaultsToFalse() {
Cookie cookie = new Cookie("name", "value");
- assertFalse(cookie.isSecure());
+ assertThat(cookie.isSecure()).isFalse();
}
@Test
public void testCookiesShouldAllowHttpOnlyToBeSet() {
Cookie cookie = new Cookie("name", "value", "", "/", new Date(), false, true);
- assertTrue(cookie.isHttpOnly());
+ assertThat(cookie.isHttpOnly()).isTrue();
}
@Test
public void testHttpOnlyDefaultsToFalse() {
Cookie cookie = new Cookie("name", "value");
- assertFalse(cookie.isHttpOnly());
+ assertThat(cookie.isHttpOnly()).isFalse();
}
@Test
@@ -93,6 +86,6 @@ public void testCookieSerializes() throws IOException, ClassNotFoundException {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(serializedCookie);
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
Cookie deserializedCookie = (Cookie) objectInputStream.readObject();
- assertThat(cookieToSerialize, equalTo(deserializedCookie));
+ assertThat(cookieToSerialize).isEqualTo(deserializedCookie);
}
}
diff --git a/java/client/test/org/openqa/selenium/CorrectEventFiringTest.java b/java/client/test/org/openqa/selenium/CorrectEventFiringTest.java
index c4e4b6f03dea4..e710880d73937 100644
--- a/java/client/test/org/openqa/selenium/CorrectEventFiringTest.java
+++ b/java/client/test/org/openqa/selenium/CorrectEventFiringTest.java
@@ -17,17 +17,8 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.anyOf;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.openqa.selenium.WaitingConditions.elementTextToContain;
@@ -40,7 +31,6 @@
import static org.openqa.selenium.testing.Driver.IE;
import static org.openqa.selenium.testing.Driver.MARIONETTE;
import static org.openqa.selenium.testing.Driver.SAFARI;
-import static org.openqa.selenium.testing.TestUtilities.catchThrowable;
import static org.openqa.selenium.testing.TestUtilities.isOldIe;
import org.junit.Test;
@@ -170,8 +160,8 @@ public void testShouldFireEventsInTheRightOrder() {
for (String event : new String[] {"mousedown", "focus", "mouseup", "click"}) {
int index = text.indexOf(event);
- assertTrue(event + " did not fire at all", index != -1);
- assertTrue(event + " did not fire in the correct order", index > lastIndex);
+ assertThat(index).as(event + " did not fire at all").isNotEqualTo(-1);
+ assertThat(index).as(event + " did not fire in the correct order").isGreaterThan(lastIndex);
lastIndex = index;
}
}
@@ -184,7 +174,7 @@ public void testsShouldIssueMouseDownEvents() {
assertEventFired("mouse down", driver);
String result = driver.findElement(By.id("result")).getText();
- assertThat(result, equalTo("mouse down"));
+ assertThat(result).isEqualTo("mouse down");
}
@Test
@@ -195,7 +185,7 @@ public void testShouldIssueClickEvents() {
WebElement result = driver.findElement(By.id("result"));
wait.until(elementTextToEqual(result, "mouse click"));
- assertThat(result.getText(), equalTo("mouse click"));
+ assertThat(result.getText()).isEqualTo("mouse click");
}
@Test
@@ -206,7 +196,7 @@ public void testShouldIssueMouseUpEvents() {
WebElement result = driver.findElement(By.id("result"));
wait.until(elementTextToEqual(result, "mouse up"));
- assertThat(result.getText(), equalTo("mouse up"));
+ assertThat(result.getText()).isEqualTo("mouse up");
}
@Test
@@ -217,7 +207,7 @@ public void testMouseEventsShouldBubbleUpToContainingElements() {
WebElement result = driver.findElement(By.id("result"));
wait.until(elementTextToEqual(result, "mouse down"));
- assertThat(result.getText(), equalTo("mouse down"));
+ assertThat(result.getText()).isEqualTo("mouse down");
}
@Test
@@ -234,9 +224,9 @@ public void testShouldEmitOnChangeEventsWhenSelectingElements() {
WebElement bar = allOptions.get(1);
foo.click();
- assertThat(driver.findElement(By.id("result")).getText(), equalTo(initialTextValue));
+ assertThat(driver.findElement(By.id("result")).getText()).isEqualTo(initialTextValue);
bar.click();
- assertThat(driver.findElement(By.id("result")).getText(), equalTo("bar"));
+ assertThat(driver.findElement(By.id("result")).getText()).isEqualTo("bar");
}
@Test
@@ -250,9 +240,9 @@ public void testShouldEmitOnClickEventsWhenSelectingElements() {
WebElement bar = allOptions.get(1);
foo.click();
- assertThat(driver.findElement(By.id("result")).getText(), equalTo("foo"));
+ assertThat(driver.findElement(By.id("result")).getText()).isEqualTo("foo");
bar.click();
- assertThat(driver.findElement(By.id("result")).getText(), equalTo("bar"));
+ assertThat(driver.findElement(By.id("result")).getText()).isEqualTo("bar");
}
@Test
@@ -275,7 +265,7 @@ public void testShouldEmitClickEventWhenClickingOnATextInputElement() {
clicker.click();
wait.until(elementValueToEqual(clicker, "Clicked"));
- assertThat(clicker.getAttribute("value"), equalTo("Clicked"));
+ assertThat(clicker.getAttribute("value")).isEqualTo("Clicked");
}
@Test
@@ -285,7 +275,7 @@ public void testShouldFireTwoClickEventsWhenClickingOnALabel() {
driver.findElement(By.id("labelForCheckbox")).click();
WebElement result = driver.findElement(By.id("result"));
- assertNotNull(wait.until(elementTextToContain(result, "labelclick chboxclick")));
+ assertThat(wait.until(elementTextToContain(result, "labelclick chboxclick"))).isNotNull();
}
@Test
@@ -297,7 +287,7 @@ public void testClearingAnElementShouldCauseTheOnChangeHandlerToFire() {
element.clear();
WebElement result = driver.findElement(By.id("result"));
- assertThat(result.getText(), equalTo("Cleared"));
+ assertThat(result.getText()).isEqualTo("Cleared");
}
@Test
@@ -400,8 +390,7 @@ public void testClickingAnUnfocusableChildShouldNotBlurTheParent() {
assertEventNotFired("blur", driver);
// Click on child. It is not focusable, so focus should stay on the parent.
driver.findElement(By.id("hideOnBlurChild")).click();
- assertTrue("#hideOnBlur should still be displayed after click",
- parent.isDisplayed());
+ assertThat(parent.isDisplayed()).as("#hideOnBlur should still be displayed after click").isTrue();
assertEventNotFired("blur", driver);
// Click elsewhere, and let the element disappear.
driver.findElement(By.id("result")).click();
@@ -441,7 +430,7 @@ public void testUploadingFileShouldFireOnChangeEvent() throws IOException {
driver.get(pages.formPage);
WebElement uploadElement = driver.findElement(By.id("upload"));
WebElement result = driver.findElement(By.id("fileResults"));
- assertThat(result.getText(), equalTo(""));
+ assertThat(result.getText()).isEqualTo("");
File file = File.createTempFile("test", "txt");
file.deleteOnExit();
@@ -450,7 +439,7 @@ public void testUploadingFileShouldFireOnChangeEvent() throws IOException {
// Shift focus to something else because send key doesn't make the focus leave
driver.findElement(By.id("id-name1")).click();
- assertThat(result.getText(), equalTo("changed"));
+ assertThat(result.getText()).isEqualTo("changed");
}
private String getTextFromElementOnceAvailable(String elementId) {
@@ -470,8 +459,8 @@ public void testShouldReportTheXAndYCoordinatesWhenClicking() {
String clientX = getTextFromElementOnceAvailable("clientX");
String clientY = getTextFromElementOnceAvailable("clientY");
- assertThat(clientX, not(equalTo("0")));
- assertThat(clientY, not(equalTo("0")));
+ assertThat(clientX).isNotEqualTo("0");
+ assertThat(clientY).isNotEqualTo("0");
}
@Test
@@ -479,7 +468,7 @@ public void testClickEventsShouldBubble() {
driver.get(pages.clicksPage);
driver.findElement(By.id("bubblesFrom")).click();
boolean eventBubbled = (Boolean)((JavascriptExecutor)driver).executeScript("return !!window.bubbledClick;");
- assertTrue("Event didn't bubble up", eventBubbled);
+ assertThat(eventBubbled).as("Event bubbled").isTrue();
}
@Test
@@ -490,10 +479,8 @@ public void testClickOverlappingElements() {
assumeFalse(isOldIe(driver));
driver.get(appServer.whereIs("click_tests/overlapping_elements.html"));
WebElement element = driver.findElement(By.id("under"));
- Throwable t = catchThrowable(element::click);
- assertThat(t, instanceOf(WebDriverException.class));
- assertThat(t.getMessage(), anyOf(containsString("Other element would receive the click"),
- containsString("is not clickable at point")));
+ assertThatExceptionOfType(ElementClickInterceptedException.class)
+ .isThrownBy(element::click);
}
@Test
@@ -509,8 +496,8 @@ public void testClickPartiallyOverlappingElements() {
WebElement over = driver.findElement(By.id("over" + i));
((JavascriptExecutor) driver).executeScript("arguments[0].style.display = 'none'", over);
driver.findElement(By.id("under")).click();
- assertEquals(driver.findElement(By.id("log")).getText(),
- "Log:\n"
+ assertThat(driver.findElement(By.id("log")).getText())
+ .isEqualTo("Log:\n"
+ "mousedown in under (handled by under)\n"
+ "mousedown in under (handled by body)\n"
+ "mouseup in under (handled by under)\n"
@@ -531,8 +518,8 @@ public void testNativelyClickOverlappingElements() {
assumeFalse(isOldIe(driver));
driver.get(appServer.whereIs("click_tests/overlapping_elements.html"));
driver.findElement(By.id("under")).click();
- assertEquals(driver.findElement(By.id("log")).getText(),
- "Log:\n"
+ assertThat(driver.findElement(By.id("log")).getText())
+ .isEqualTo("Log:\n"
+ "mousedown in over (handled by over)\n"
+ "mousedown in over (handled by body)\n"
+ "mouseup in over (handled by over)\n"
@@ -548,12 +535,12 @@ public void testClickAnElementThatDisappear() {
assumeFalse(isOldIe(driver));
driver.get(appServer.whereIs("click_tests/disappearing_element.html"));
driver.findElement(By.id("over")).click();
- assertThat(driver.findElement(By.id("log")).getText(),
- startsWith("Log:\n"
- + "mousedown in over (handled by over)\n"
- + "mousedown in over (handled by body)\n"
- + "mouseup in under (handled by under)\n"
- + "mouseup in under (handled by body)"));
+ assertThat(driver.findElement(By.id("log")).getText())
+ .startsWith("Log:\n"
+ + "mousedown in over (handled by over)\n"
+ + "mousedown in over (handled by body)\n"
+ + "mouseup in under (handled by under)\n"
+ + "mouseup in under (handled by body)");
}
private static void clickOnElementWhichRecordsEvents(WebDriver driver) {
@@ -566,13 +553,13 @@ private static void assertEventFired(String eventName, WebDriver driver) {
String text = new WebDriverWait(driver, 10).until(elementTextToContain(result, eventName));
boolean conditionMet = text.contains(eventName);
- assertTrue("No " + eventName + " fired: " + text, conditionMet);
+ assertThat(conditionMet).as("%s fired with text %s", eventName, text).isTrue();
}
private static void assertEventNotFired(String eventName, WebDriver driver) {
WebElement result = driver.findElement(By.id("result"));
String text = result.getText();
- assertFalse(eventName + " fired: " + text, text.contains(eventName));
+ assertThat(text).as("%s fired with text %s").doesNotContain(eventName);
}
private static boolean browserNeedsFocusOnThisOs(WebDriver driver) {
diff --git a/java/client/test/org/openqa/selenium/CssValueTest.java b/java/client/test/org/openqa/selenium/CssValueTest.java
index 9346f330a89c5..72321183bc4d6 100644
--- a/java/client/test/org/openqa/selenium/CssValueTest.java
+++ b/java/client/test/org/openqa/selenium/CssValueTest.java
@@ -17,10 +17,7 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.anyOf;
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.openqa.selenium.support.Color;
@@ -35,12 +32,12 @@ public void testShouldPickUpStyleOfAnElement() {
WebElement element = driver.findElement(By.id("green-parent"));
Color backgroundColour = Color.fromString(element.getCssValue("background-color"));
- assertEquals(new Color(0, 128, 0, 1), backgroundColour);
+ assertThat(backgroundColour).isEqualTo(new Color(0, 128, 0, 1));
element = driver.findElement(By.id("red-item"));
backgroundColour = Color.fromString(element.getCssValue("background-color"));
- assertEquals(new Color(255, 0, 0, 1), backgroundColour);
+ assertThat(backgroundColour).isEqualTo(new Color(255, 0, 0, 1));
}
@Test
@@ -49,11 +46,11 @@ public void testGetCssValueShouldReturnStandardizedColour() {
WebElement element = driver.findElement(By.id("namedColor"));
Color backgroundColour = Color.fromString(element.getCssValue("background-color"));
- assertEquals(new Color(0, 128, 0, 1), backgroundColour);
+ assertThat(backgroundColour).isEqualTo(new Color(0, 128, 0, 1));
element = driver.findElement(By.id("rgb"));
backgroundColour = Color.fromString(element.getCssValue("background-color"));
- assertEquals(new Color(0, 128, 0, 1), backgroundColour);
+ assertThat(backgroundColour).isEqualTo(new Color(0, 128, 0, 1));
}
@Test
@@ -64,9 +61,7 @@ public void testShouldAllowInheritedStylesToBeUsed() {
String backgroundColour = element.getCssValue("background-color");
// TODO: How should this be standardized? Should it be standardized?
- assertThat(backgroundColour, anyOf(
- equalTo("transparent"),
- equalTo("rgba(0, 0, 0, 0)")));
+ assertThat(backgroundColour).isIn("transparent", "rgba(0, 0, 0, 0)");
}
}
diff --git a/java/client/test/org/openqa/selenium/DimensionTest.java b/java/client/test/org/openqa/selenium/DimensionTest.java
index b38448c9880c5..7bf49187d61f3 100644
--- a/java/client/test/org/openqa/selenium/DimensionTest.java
+++ b/java/client/test/org/openqa/selenium/DimensionTest.java
@@ -17,23 +17,19 @@
package org.openqa.selenium;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
+import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
/**
* Test WebDriver's Dimensions class.
*/
-@RunWith(JUnit4.class)
public class DimensionTest {
@Test
public void testSimpleAssignment() {
Dimension d1 = new Dimension(100, 200);
- assertEquals(200, d1.getHeight());
- assertEquals(100, d1.getWidth());
+ assertThat(d1.getHeight()).isEqualTo(200);
+ assertThat(d1.getWidth()).isEqualTo(100);
}
@Test
@@ -41,14 +37,14 @@ public void testEquality() {
Dimension d1 = new Dimension(100, 200);
Dimension d2 = new Dimension(200, 200);
- assertNotSame(d1, d2);
+ assertThat(d1).isNotSameAs(d2);
// Doesn't have to be different, but known to be different for this case.
- assertNotSame(d1.hashCode(), d2.hashCode());
+ assertThat(d1.hashCode()).isNotEqualTo(d2.hashCode());
Dimension d1copy = new Dimension(100, 200);
- assertEquals(d1, d1copy);
- assertEquals(d1.hashCode(), d1copy.hashCode());
+ assertThat(d1copy).isEqualTo(d1);
+ assertThat(d1copy.hashCode()).isEqualTo(d1.hashCode());
}
}
diff --git a/java/client/test/org/openqa/selenium/ElementAttributeTest.java b/java/client/test/org/openqa/selenium/ElementAttributeTest.java
index d177c727a7a5d..356959b6ba201 100644
--- a/java/client/test/org/openqa/selenium/ElementAttributeTest.java
+++ b/java/client/test/org/openqa/selenium/ElementAttributeTest.java
@@ -17,21 +17,10 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.anyOf;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assume.assumeFalse;
import static org.openqa.selenium.testing.Driver.SAFARI;
-import static org.openqa.selenium.testing.TestUtilities.catchThrowable;
import org.junit.Test;
import org.openqa.selenium.support.ui.ExpectedConditions;
@@ -48,7 +37,7 @@ public void testShouldReturnNullWhenGettingTheValueOfAnAttributeThatIsNotListed(
driver.get(pages.simpleTestPage);
WebElement head = driver.findElement(By.xpath("/html"));
String attribute = head.getAttribute("cheese");
- assertThat(attribute, is(nullValue()));
+ assertThat(attribute).isNull();
}
@Test
@@ -56,7 +45,7 @@ public void testShouldReturnNullWhenGettingSrcAttributeOfInvalidImgTag() {
driver.get(pages.simpleTestPage);
WebElement img = driver.findElement(By.id("invalidImgTag"));
String attribute = img.getAttribute("src");
- assertThat(attribute, is(nullValue()));
+ assertThat(attribute).isNull();
}
@Test
@@ -64,7 +53,7 @@ public void testShouldReturnAnAbsoluteUrlWhenGettingSrcAttributeOfAValidImgTag()
driver.get(pages.simpleTestPage);
WebElement img = driver.findElement(By.id("validImgTag"));
String attribute = img.getAttribute("src");
- assertThat(attribute, equalTo(appServer.whereIs("icon.gif")));
+ assertThat(attribute).isEqualTo(appServer.whereIs("icon.gif"));
}
@Test
@@ -72,26 +61,26 @@ public void testShouldReturnAnAbsoluteUrlWhenGettingHrefAttributeOfAValidAnchorT
driver.get(pages.simpleTestPage);
WebElement img = driver.findElement(By.id("validAnchorTag"));
String attribute = img.getAttribute("href");
- assertThat(attribute, equalTo(appServer.whereIs("icon.gif")));
+ assertThat(attribute).isEqualTo(appServer.whereIs("icon.gif"));
}
@Test
public void testShouldReturnEmptyAttributeValuesWhenPresentAndTheValueIsActuallyEmpty() {
driver.get(pages.simpleTestPage);
WebElement body = driver.findElement(By.xpath("//body"));
- assertThat(body.getAttribute("style"), equalTo(""));
+ assertThat(body.getAttribute("style")).isEqualTo("");
}
@Test
public void testShouldReturnTheValueOfTheDisabledAttributeAsNullIfNotSet() {
driver.get(pages.formPage);
WebElement inputElement = driver.findElement(By.xpath("//input[@id='working']"));
- assertThat(inputElement.getAttribute("disabled"), equalTo(null));
- assertThat(inputElement.isEnabled(), equalTo(true));
+ assertThat(inputElement.getAttribute("disabled")).isNull();
+ assertThat(inputElement.isEnabled()).isTrue();
WebElement pElement = driver.findElement(By.id("peas"));
- assertThat(pElement.getAttribute("disabled"), equalTo(null));
- assertThat(pElement.isEnabled(), equalTo(true));
+ assertThat(pElement.getAttribute("disabled")).isNull();
+ assertThat(pElement.isEnabled()).isTrue();
}
@Test
@@ -100,30 +89,30 @@ public void testShouldReturnTheValueOfTheIndexAttrbuteEvenIfItIsMissing() {
WebElement multiSelect = driver.findElement(By.id("multi"));
List options = multiSelect.findElements(By.tagName("option"));
- assertThat(options.get(1).getAttribute("index"), equalTo("1"));
+ assertThat(options.get(1).getAttribute("index")).isEqualTo("1");
}
@Test
public void testShouldIndicateTheElementsThatAreDisabledAreNotEnabled() {
driver.get(pages.formPage);
WebElement inputElement = driver.findElement(By.xpath("//input[@id='notWorking']"));
- assertThat(inputElement.isEnabled(), is(false));
+ assertThat(inputElement.isEnabled()).isFalse();
inputElement = driver.findElement(By.xpath("//input[@id='working']"));
- assertThat(inputElement.isEnabled(), is(true));
+ assertThat(inputElement.isEnabled()).isTrue();
}
@Test
public void testElementsShouldBeDisabledIfTheyAreDisabledUsingRandomDisabledStrings() {
driver.get(pages.formPage);
WebElement disabledTextElement1 = driver.findElement(By.id("disabledTextElement1"));
- assertThat(disabledTextElement1.isEnabled(), is(false));
+ assertThat(disabledTextElement1.isEnabled()).isFalse();
WebElement disabledTextElement2 = driver.findElement(By.id("disabledTextElement2"));
- assertThat(disabledTextElement2.isEnabled(), is(false));
+ assertThat(disabledTextElement2.isEnabled()).isFalse();
WebElement disabledSubmitElement = driver.findElement(By.id("disabledSubmitElement"));
- assertThat(disabledSubmitElement.isEnabled(), is(false));
+ assertThat(disabledSubmitElement.isEnabled()).isFalse();
}
@Test
@@ -131,21 +120,21 @@ public void testElementsShouldBeDisabledIfTheyAreDisabledUsingRandomDisabledStri
public void testShouldThrowExceptionIfSendingKeysToElementDisabledUsingRandomDisabledStrings() {
driver.get(pages.formPage);
WebElement disabledTextElement1 = driver.findElement(By.id("disabledTextElement1"));
- Throwable t = catchThrowable(() -> disabledTextElement1.sendKeys("foo"));
- assertThat(t, instanceOf(InvalidElementStateException.class));
- assertThat(disabledTextElement1.getText(), is(""));
+ assertThatExceptionOfType(InvalidElementStateException.class)
+ .isThrownBy(() -> disabledTextElement1.sendKeys("foo"));
+ assertThat(disabledTextElement1.getText()).isEqualTo("");
WebElement disabledTextElement2 = driver.findElement(By.id("disabledTextElement2"));
- Throwable t2 = catchThrowable(() -> disabledTextElement2.sendKeys("bar"));
- assertThat(t2, instanceOf(InvalidElementStateException.class));
- assertThat(disabledTextElement2.getText(), is(""));
+ assertThatExceptionOfType(InvalidElementStateException.class)
+ .isThrownBy(() -> disabledTextElement2.sendKeys("bar"));
+ assertThat(disabledTextElement2.getText()).isEqualTo("");
}
@Test
public void testShouldIndicateWhenATextAreaIsDisabled() {
driver.get(pages.formPage);
WebElement textArea = driver.findElement(By.xpath("//textarea[@id='notWorkingArea']"));
- assertThat(textArea.isEnabled(), is(false));
+ assertThat(textArea.isEnabled()).isFalse();
}
@Test
@@ -155,17 +144,17 @@ public void testShouldIndicateWhenASelectIsDisabled() {
WebElement enabled = driver.findElement(By.name("selectomatic"));
WebElement disabled = driver.findElement(By.name("no-select"));
- assertTrue(enabled.isEnabled());
- assertFalse(disabled.isEnabled());
+ assertThat(enabled.isEnabled()).isTrue();
+ assertThat(disabled.isEnabled()).isFalse();
}
@Test
public void testShouldReturnTheValueOfCheckedForACheckboxOnlyIfItIsChecked() {
driver.get(pages.formPage);
WebElement checkbox = driver.findElement(By.xpath("//input[@id='checky']"));
- assertThat(checkbox.getAttribute("checked"), equalTo(null));
+ assertThat(checkbox.getAttribute("checked")).isNull();
checkbox.click();
- assertThat(checkbox.getAttribute("checked"), equalTo("true"));
+ assertThat(checkbox.getAttribute("checked")).isEqualTo("true");
}
@Test
@@ -175,14 +164,14 @@ public void testShouldOnlyReturnTheValueOfSelectedForRadioButtonsIfItIsSet() {
WebElement initiallyNotSelected = driver.findElement(By.id("peas"));
WebElement initiallySelected = driver.findElement(By.id("cheese_and_peas"));
- assertThat(neverSelected.getAttribute("selected"), equalTo(null));
- assertThat(initiallyNotSelected.getAttribute("selected"), equalTo(null));
- assertThat(initiallySelected.getAttribute("selected"), equalTo("true"));
+ assertThat(neverSelected.getAttribute("selected")).isNull();
+ assertThat(initiallyNotSelected.getAttribute("selected")).isNull();
+ assertThat(initiallySelected.getAttribute("selected")).isEqualTo("true");
initiallyNotSelected.click();
- assertThat(neverSelected.getAttribute("selected"), equalTo(null));
- assertThat(initiallyNotSelected.getAttribute("selected"), equalTo("true"));
- assertThat(initiallySelected.getAttribute("selected"), equalTo(null));
+ assertThat(neverSelected.getAttribute("selected")).isNull();
+ assertThat(initiallyNotSelected.getAttribute("selected")).isEqualTo("true");
+ assertThat(initiallySelected.getAttribute("selected")).isNull();
}
@Test
@@ -192,10 +181,10 @@ public void testShouldReturnTheValueOfSelectedForOptionsOnlyIfTheyAreSelected()
List options = selectBox.findElements(By.tagName("option"));
WebElement one = options.get(0);
WebElement two = options.get(1);
- assertThat(one.isSelected(), is(true));
- assertThat(two.isSelected(), is(false));
- assertThat(one.getAttribute("selected"), equalTo("true"));
- assertThat(two.getAttribute("selected"), equalTo(null));
+ assertThat(one.isSelected()).isTrue();
+ assertThat(two.isSelected()).isFalse();
+ assertThat(one.getAttribute("selected")).isEqualTo("true");
+ assertThat(two.getAttribute("selected")).isNull();
}
@Test
@@ -205,7 +194,7 @@ public void testShouldReturnValueOfClassAttributeOfAnElement() {
WebElement heading = driver.findElement(By.xpath("//h1"));
String className = heading.getAttribute("class");
- assertThat(className, equalTo("header"));
+ assertThat(className).isEqualTo("header");
}
@Test
@@ -214,7 +203,7 @@ public void testShouldReturnTheContentsOfATextAreaAsItsValue() {
String value = driver.findElement(By.id("withText")).getAttribute("value");
- assertThat(value, equalTo("Example text"));
+ assertThat(value).isEqualTo("Example text");
}
@Test
@@ -223,7 +212,7 @@ public void testShouldReturnInnerHtml() {
driver.get(pages.simpleTestPage);
String html = driver.findElement(By.id("wrappingtext")).getAttribute("innerHTML");
- assertThat(html, containsString(""));
+ assertThat(html).contains("");
}
@Test
@@ -233,12 +222,12 @@ public void testShouldTreatReadonlyAsAValue() {
WebElement element = driver.findElement(By.name("readonly"));
String readonly = element.getAttribute("readonly");
- assertNotNull(readonly);
+ assertThat(readonly).isNotNull();
WebElement textInput = driver.findElement(By.name("x"));
String notReadonly = textInput.getAttribute("readonly");
- assertFalse(readonly.equals(notReadonly));
+ assertThat(readonly).isNotEqualTo(notReadonly);
}
@Test
@@ -250,14 +239,14 @@ public void testShouldReturnHiddenTextForTextContentAttribute() {
WebElement element = driver.findElement(By.id("hiddenline"));
String textContent = element.getAttribute("textContent");
- assertEquals(textContent, "A hidden line of text");
+ assertThat(textContent).isEqualTo("A hidden line of text");
}
@Test
public void testShouldGetNumericAtribute() {
driver.get(pages.formPage);
WebElement element = driver.findElement(By.id("withText"));
- assertThat(element.getAttribute("rows"), is("5"));
+ assertThat(element.getAttribute("rows")).isEqualTo("5");
}
@Test
@@ -266,7 +255,7 @@ public void testCanReturnATextApproximationOfTheStyleAttribute() {
String style = driver.findElement(By.id("red-item")).getAttribute("style");
- assertTrue(style.toLowerCase().contains("background-color"));
+ assertThat(style.toLowerCase().contains("background-color")).isTrue();
}
@Test
@@ -282,11 +271,11 @@ public void testShouldCorrectlyReportValueOfColspan() {
WebElement th1 = driver.findElement(By.id("th1"));
WebElement td2 = driver.findElement(By.id("td2"));
- assertEquals("th1 id", "th1", th1.getAttribute("id"));
- assertEquals("th1 colspan should be 3", "3", th1.getAttribute("colspan"));
+ assertThat(th1.getAttribute("id")).isEqualTo("th1");
+ assertThat(th1.getAttribute("colspan")).isEqualTo("3");
- assertEquals("td2 id", "td2", td2.getAttribute("id"));
- assertEquals("td2 colspan should be 2", "2", td2.getAttribute("colspan"));
+ assertThat(td2.getAttribute("id")).isEqualTo("td2");
+ assertThat(td2.getAttribute("colspan")).isEqualTo("2");
}
// This is a test-case re-creating issue 900.
@@ -299,13 +288,13 @@ public void testShouldReturnValueOfOnClickAttribute() {
String onClickValue = mouseclickDiv.getAttribute("onclick");
String expectedOnClickValue = "displayMessage('mouse click');";
- assertThat("Javascript code expected", onClickValue, anyOf(
- equalTo("javascript:" + expectedOnClickValue), // Non-IE
- equalTo("function anonymous()\n{\n" + expectedOnClickValue + "\n}"), // IE
- equalTo("function onclick()\n{\n" + expectedOnClickValue + "\n}"))); // IE
+ assertThat(onClickValue).as("Javascript code").isIn(
+ "javascript:" + expectedOnClickValue, // Non-IE
+ "function anonymous()\n{\n" + expectedOnClickValue + "\n}", // IE
+ "function onclick()\n{\n" + expectedOnClickValue + "\n}"); // IE
WebElement mousedownDiv = driver.findElement(By.id("mousedown"));
- assertEquals(null, mousedownDiv.getAttribute("onclick"));
+ assertThat(mousedownDiv.getAttribute("onclick")).isNull();
}
@Test
@@ -314,14 +303,14 @@ public void testGetAttributeDoesNotReturnAnObjectForSvgProperties() {
driver.get(pages.svgPage);
WebElement svgElement = driver.findElement(By.id("rotate"));
- assertEquals("rotate(30)", svgElement.getAttribute("transform"));
+ assertThat(svgElement.getAttribute("transform")).isEqualTo("rotate(30)");
}
@Test
public void testCanRetrieveTheCurrentValueOfATextFormField_textInput() {
driver.get(pages.formPage);
WebElement element = driver.findElement(By.id("working"));
- assertEquals("", element.getAttribute("value"));
+ assertThat(element.getAttribute("value")).isEqualTo("");
element.sendKeys("hello world");
shortWait.until(ExpectedConditions.attributeToBe(element, "value", "hello world"));
}
@@ -330,7 +319,7 @@ public void testCanRetrieveTheCurrentValueOfATextFormField_textInput() {
public void testCanRetrieveTheCurrentValueOfATextFormField_emailInput() {
driver.get(pages.formPage);
WebElement element = driver.findElement(By.id("email"));
- assertEquals("", element.getAttribute("value"));
+ assertThat(element.getAttribute("value")).isEqualTo("");
element.sendKeys("hello@example.com");
shortWait.until(ExpectedConditions.attributeToBe(element, "value", "hello@example.com"));
}
@@ -339,7 +328,7 @@ public void testCanRetrieveTheCurrentValueOfATextFormField_emailInput() {
public void testCanRetrieveTheCurrentValueOfATextFormField_textArea() {
driver.get(pages.formPage);
WebElement element = driver.findElement(By.id("emptyTextArea"));
- assertEquals("", element.getAttribute("value"));
+ assertThat(element.getAttribute("value")).isEqualTo("");
element.sendKeys("hello world");
shortWait.until(ExpectedConditions.attributeToBe(element, "value", "hello world"));
}
@@ -348,9 +337,9 @@ public void testCanRetrieveTheCurrentValueOfATextFormField_textArea() {
public void testShouldReturnNullForNonPresentBooleanAttributes() {
driver.get(pages.booleanAttributes);
WebElement element1 = driver.findElement(By.id("working"));
- assertNull(element1.getAttribute("required"));
+ assertThat(element1.getAttribute("required")).isNull();
WebElement element2 = driver.findElement(By.id("wallace"));
- assertNull(element2.getAttribute("nowrap"));
+ assertThat(element2.getAttribute("nowrap")).isNull();
}
@Test
@@ -358,56 +347,56 @@ public void testShouldReturnNullForNonPresentBooleanAttributes() {
public void testShouldReturnTrueForPresentBooleanAttributes() {
driver.get(pages.booleanAttributes);
WebElement element1 = driver.findElement(By.id("emailRequired"));
- assertEquals("true", element1.getAttribute("required"));
+ assertThat(element1.getAttribute("required")).isEqualTo("true");
WebElement element2 = driver.findElement(By.id("emptyTextAreaRequired"));
- assertEquals("true", element2.getAttribute("required"));
+ assertThat(element2.getAttribute("required")).isEqualTo("true");
WebElement element3 = driver.findElement(By.id("inputRequired"));
- assertEquals("true", element3.getAttribute("required"));
+ assertThat(element3.getAttribute("required")).isEqualTo("true");
WebElement element4 = driver.findElement(By.id("textAreaRequired"));
- assertEquals("true", element4.getAttribute("required"));
+ assertThat(element4.getAttribute("required")).isEqualTo("true");
WebElement element5 = driver.findElement(By.id("unwrappable"));
- assertEquals("true", element5.getAttribute("nowrap"));
+ assertThat(element5.getAttribute("nowrap")).isEqualTo("true");
}
@Test
public void testMultipleAttributeShouldBeNullWhenNotSet() {
driver.get(pages.selectPage);
WebElement element = driver.findElement(By.id("selectWithoutMultiple"));
- assertEquals(null, element.getAttribute("multiple"));
+ assertThat(element.getAttribute("multiple")).isNull();
}
@Test
public void testMultipleAttributeShouldBeTrueWhenSet() {
driver.get(pages.selectPage);
WebElement element = driver.findElement(By.id("selectWithMultipleEqualsMultiple"));
- assertEquals("true", element.getAttribute("multiple"));
+ assertThat(element.getAttribute("multiple")).isEqualTo("true");
}
@Test
public void testMultipleAttributeShouldBeTrueWhenSelectHasMultipleWithValueAsBlank() {
driver.get(pages.selectPage);
WebElement element = driver.findElement(By.id("selectWithEmptyStringMultiple"));
- assertEquals("true", element.getAttribute("multiple"));
+ assertThat(element.getAttribute("multiple")).isEqualTo("true");
}
@Test
public void testMultipleAttributeShouldBeTrueWhenSelectHasMultipleWithoutAValue() {
driver.get(pages.selectPage);
WebElement element = driver.findElement(By.id("selectWithMultipleWithoutValue"));
- assertEquals("true", element.getAttribute("multiple"));
+ assertThat(element.getAttribute("multiple")).isEqualTo("true");
}
@Test
public void testMultipleAttributeShouldBeTrueWhenSelectHasMultipleWithValueAsSomethingElse() {
driver.get(pages.selectPage);
WebElement element = driver.findElement(By.id("selectWithRandomMultipleValue"));
- assertEquals("true", element.getAttribute("multiple"));
+ assertThat(element.getAttribute("multiple")).isEqualTo("true");
}
@Test
public void testGetAttributeOfUserDefinedProperty() {
driver.get(pages.userDefinedProperty);
WebElement element = driver.findElement(By.id("d"));
- assertEquals("sampleValue", element.getAttribute("dynamicProperty"));
+ assertThat(element.getAttribute("dynamicProperty")).isEqualTo("sampleValue");
}
}
diff --git a/java/client/test/org/openqa/selenium/ElementEqualityTest.java b/java/client/test/org/openqa/selenium/ElementEqualityTest.java
index b5ec3148ec88e..a71e0197e2a58 100644
--- a/java/client/test/org/openqa/selenium/ElementEqualityTest.java
+++ b/java/client/test/org/openqa/selenium/ElementEqualityTest.java
@@ -17,8 +17,7 @@
package org.openqa.selenium;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.selenium.testing.Driver.SAFARI;
import org.junit.Test;
@@ -38,7 +37,7 @@ public void testSameElementLookedUpDifferentWaysShouldBeEqual() {
WebElement body = driver.findElement(By.tagName("body"));
WebElement xbody = driver.findElements(By.xpath("//body")).get(0);
- assertEquals(body, xbody);
+ assertThat(xbody).isEqualTo(body);
}
@Test
@@ -47,7 +46,7 @@ public void testDifferentElementsShouldNotBeEqual() {
List ps = driver.findElements(By.tagName("p"));
- assertFalse(ps.get(0).equals(ps.get(1)));
+ assertThat(ps.get(0).equals(ps.get(1))).isFalse();
}
@Test
@@ -56,7 +55,7 @@ public void testSameElementLookedUpDifferentWaysUsingFindElementShouldHaveSameHa
WebElement body = driver.findElement(By.tagName("body"));
WebElement xbody = driver.findElement(By.xpath("//body"));
- assertEquals(body.hashCode(), xbody.hashCode());
+ assertThat(xbody.hashCode()).isEqualTo(body.hashCode());
}
@Test
@@ -65,7 +64,7 @@ public void testSameElementLookedUpDifferentWaysUsingFindElementsShouldHaveSameH
List body = driver.findElements(By.tagName("body"));
List xbody = driver.findElements(By.xpath("//body"));
- assertEquals(body.get(0).hashCode(), xbody.get(0).hashCode());
+ assertThat(xbody.get(0).hashCode()).isEqualTo(body.get(0).hashCode());
}
@SwitchToTopAfterTest
@@ -93,7 +92,7 @@ private void checkIdEqualityIfRemote(WebElement first, WebElement second) {
String firstId = getId(unwrapIfNecessary(first));
String secondId = getId(unwrapIfNecessary(second));
- assertEquals(firstId, secondId);
+ assertThat(secondId).isEqualTo(firstId);
}
private String getId(WebElement element) {
diff --git a/java/client/test/org/openqa/selenium/ElementFindingTest.java b/java/client/test/org/openqa/selenium/ElementFindingTest.java
index 9438e123c79eb..2f7e80ff29ea6 100644
--- a/java/client/test/org/openqa/selenium/ElementFindingTest.java
+++ b/java/client/test/org/openqa/selenium/ElementFindingTest.java
@@ -17,19 +17,14 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assume.assumeFalse;
import static org.openqa.selenium.testing.Driver.CHROME;
import static org.openqa.selenium.testing.Driver.IE;
import static org.openqa.selenium.testing.Driver.MARIONETTE;
import static org.openqa.selenium.testing.Driver.SAFARI;
-import static org.openqa.selenium.testing.TestUtilities.catchThrowable;
+import static org.openqa.selenium.testing.TestUtilities.isIe6;
import static org.openqa.selenium.testing.TestUtilities.isOldIe;
import org.junit.Test;
@@ -38,7 +33,6 @@
import org.openqa.selenium.testing.NeedsFreshDriver;
import org.openqa.selenium.testing.NotYetImplemented;
import org.openqa.selenium.testing.SwitchToTopAfterTest;
-import org.openqa.selenium.testing.TestUtilities;
import java.util.List;
@@ -50,14 +44,14 @@ public class ElementFindingTest extends JUnit4TestBase {
public void testShouldBeAbleToFindASingleElementById() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.id("linkId"));
- assertThat(element.getAttribute("id"), is("linkId"));
+ assertThat(element.getAttribute("id")).isEqualTo("linkId");
}
@Test
public void testShouldBeAbleToFindASingleElementByNumericId() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.id("2"));
- assertThat(element.getAttribute("id"), is("2"));
+ assertThat(element.getAttribute("id")).isEqualTo("2");
}
@Test
@@ -67,23 +61,23 @@ public void testShouldBeAbleToFindASingleElementByNumericId() {
public void testShouldBeAbleToFindASingleElementByIdWithNonAlphanumericCharacters() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.id("white space"));
- assertThat(element.getText(), is("space"));
+ assertThat(element.getText()).isEqualTo("space");
WebElement element2 = driver.findElement(By.id("css#.chars"));
- assertThat(element2.getText(), is("css escapes"));
+ assertThat(element2.getText()).isEqualTo("css escapes");
}
@Test
public void testShouldBeAbleToFindMultipleElementsById() {
driver.get(pages.nestedPage);
List elements = driver.findElements(By.id("test_id"));
- assertThat(elements.size(), is(2));
+ assertThat(elements).hasSize(2);
}
@Test
public void testShouldBeAbleToFindMultipleElementsByNumericId() {
driver.get(pages.nestedPage);
List elements = driver.findElements(By.id("2"));
- assertThat(elements.size(), is(8));
+ assertThat(elements).hasSize(8);
}
@Test
@@ -93,9 +87,9 @@ public void testShouldBeAbleToFindMultipleElementsByNumericId() {
public void testShouldBeAbleToFindMultipleElementsByIdWithNonAlphanumericCharacters() {
driver.get(pages.nestedPage);
List elements = driver.findElements(By.id("white space"));
- assertThat(elements.size(), is(2));
+ assertThat(elements).hasSize(2);
List elements2 = driver.findElements(By.id("css#.chars"));
- assertThat(elements2.size(), is(2));
+ assertThat(elements2).hasSize(2);
}
// By.id negative
@@ -103,22 +97,22 @@ public void testShouldBeAbleToFindMultipleElementsByIdWithNonAlphanumericCharact
@Test
public void testShouldNotBeAbleToLocateByIdASingleElementThatDoesNotExist() {
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.id("nonExistentButton")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.id("nonExistentButton")));
}
@Test
public void testShouldNotBeAbleToLocateByIdMultipleElementsThatDoNotExist() {
driver.get(pages.formPage);
List elements = driver.findElements(By.id("nonExistentButton"));
- assertThat(elements.size(), is(0));
+ assertThat(elements.size()).isEqualTo(0);
}
@Test
public void testFindingASingleElementByEmptyIdShouldThrow() {
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.id("")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.id("")));
}
@Test
@@ -126,21 +120,21 @@ public void testFindingASingleElementByEmptyIdShouldThrow() {
public void testFindingMultipleElementsByEmptyIdShouldReturnEmptyList() {
driver.get(pages.formPage);
List elements = driver.findElements(By.id(""));
- assertThat(elements.size(), is(0));
+ assertThat(elements.size()).isEqualTo(0);
}
@Test
public void testFindingASingleElementByIdWithSpaceShouldThrow() {
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.id("nonexistent button")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.id("nonexistent button")));
}
@Test
public void testFindingMultipleElementsByIdWithSpaceShouldReturnEmptyList() {
driver.get(pages.formPage);
List elements = driver.findElements(By.id("nonexistent button"));
- assertThat(elements.size(), is(0));
+ assertThat(elements.size()).isEqualTo(0);
}
// By.name positive
@@ -149,21 +143,21 @@ public void testFindingMultipleElementsByIdWithSpaceShouldReturnEmptyList() {
public void testShouldBeAbleToFindASingleElementByName() {
driver.get(pages.formPage);
WebElement element = driver.findElement(By.name("checky"));
- assertThat(element.getAttribute("value"), is("furrfu"));
+ assertThat(element.getAttribute("value")).isEqualTo("furrfu");
}
@Test
public void testShouldBeAbleToFindMultipleElementsByName() {
driver.get(pages.nestedPage);
List elements = driver.findElements(By.name("checky"));
- assertThat(elements.size(), greaterThan(1));
+ assertThat(elements.size()).isGreaterThan(1);
}
@Test
public void testShouldBeAbleToFindAnElementThatDoesNotSupportTheNameProperty() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.name("div1"));
- assertThat(element.getAttribute("name"), is("div1"));
+ assertThat(element.getAttribute("name")).isEqualTo("div1");
}
// By.name negative
@@ -171,43 +165,43 @@ public void testShouldBeAbleToFindAnElementThatDoesNotSupportTheNameProperty() {
@Test
public void testShouldNotBeAbleToLocateByNameASingleElementThatDoesNotExist() {
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.name("nonExistentButton")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.name("nonExistentButton")));
}
@Test
public void testShouldNotBeAbleToLocateByNameMultipleElementsThatDoNotExist() {
driver.get(pages.formPage);
List elements = driver.findElements(By.name("nonExistentButton"));
- assertThat(elements.size(), is(0));
+ assertThat(elements).hasSize(0);
}
@Test
public void testFindingASingleElementByEmptyNameShouldThrow() {
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.name("")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.name("")));
}
@Test
public void testFindingMultipleElementsByEmptyNameShouldReturnEmptyList() {
driver.get(pages.formPage);
List elements = driver.findElements(By.name(""));
- assertThat(elements.size(), is(0));
+ assertThat(elements).hasSize(0);
}
@Test
public void testFindingASingleElementByNameWithSpaceShouldThrow() {
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.name("nonexistent button")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.name("nonexistent button")));
}
@Test
public void testFindingMultipleElementsByNameWithSpaceShouldReturnEmptyList() {
driver.get(pages.formPage);
List elements = driver.findElements(By.name("nonexistent button"));
- assertThat(elements.size(), is(0));
+ assertThat(elements).hasSize(0);
}
// By.tagName positive
@@ -216,14 +210,14 @@ public void testFindingMultipleElementsByNameWithSpaceShouldReturnEmptyList() {
public void testShouldBeAbleToFindASingleElementByTagName() {
driver.get(pages.formPage);
WebElement element = driver.findElement(By.tagName("input"));
- assertThat(element.getTagName().toLowerCase(), is("input"));
+ assertThat(element.getTagName().toLowerCase()).isEqualTo("input");
}
@Test
public void testShouldBeAbleToFindMultipleElementsByTagName() {
driver.get(pages.formPage);
List elements = driver.findElements(By.tagName("input"));
- assertThat(elements.size(), greaterThan(1));
+ assertThat(elements.size()).isGreaterThan(1);
}
// By.tagName negative
@@ -231,44 +225,44 @@ public void testShouldBeAbleToFindMultipleElementsByTagName() {
@Test
public void testShouldNotBeAbleToLocateByTagNameASingleElementThatDoesNotExist() {
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.tagName("nonExistentButton")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.tagName("nonExistentButton")));
}
@Test
public void testShouldNotBeAbleToLocateByTagNameMultipleElementsThatDoNotExist() {
driver.get(pages.formPage);
List elements = driver.findElements(By.tagName("nonExistentButton"));
- assertThat(elements.size(), is(0));
+ assertThat(elements).hasSize(0);
}
@Test
public void testFindingASingleElementByEmptyTagNameShouldThrow() {
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.tagName("")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.tagName("")));
}
@Test
@NotYetImplemented(SAFARI)
public void testFindingMultipleElementsByEmptyTagNameShouldThrow() {
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElements(By.tagName("")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElements(By.tagName("")));
}
@Test
public void testFindingASingleElementByTagNameWithSpaceShouldThrow() {
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.tagName("nonexistent button")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.tagName("nonexistent button")));
}
@Test
public void testFindingMultipleElementsByTagNameWithSpaceShouldReturnEmptyList() {
driver.get(pages.formPage);
List elements = driver.findElements(By.tagName("nonexistent button"));
- assertThat(elements.size(), is(0));
+ assertThat(elements).hasSize(0);
}
// By.className positive
@@ -277,50 +271,50 @@ public void testFindingMultipleElementsByTagNameWithSpaceShouldReturnEmptyList()
public void testShouldBeAbleToFindASingleElementByClass() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.className("extraDiv"));
- assertThat(element.getText(), startsWith("Another div starts here."));
+ assertThat(element.getText()).startsWith("Another div starts here.");
}
@Test
public void testShouldBeAbleToFindMultipleElementsByClassName() {
driver.get(pages.xhtmlTestPage);
List elements = driver.findElements(By.className("nameC"));
- assertThat(elements.size(), greaterThan(1));
+ assertThat(elements.size()).isGreaterThan(1);
}
@Test
public void testShouldFindElementByClassWhenItIsTheFirstNameAmongMany() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.className("nameA"));
- assertThat(element.getText(), is("An H2 title"));
+ assertThat(element.getText()).isEqualTo("An H2 title");
}
@Test
public void testShouldFindElementByClassWhenItIsTheLastNameAmongMany() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.className("nameC"));
- assertThat(element.getText(), is("An H2 title"));
+ assertThat(element.getText()).isEqualTo("An H2 title");
}
@Test
public void testShouldFindElementByClassWhenItIsInTheMiddleAmongMany() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.className("nameBnoise"));
- assertThat(element.getText(), is("An H2 title"));
+ assertThat(element.getText()).isEqualTo("An H2 title");
}
@Test
public void testShouldFindElementByClassWhenItsNameIsSurroundedByWhitespace() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.className("spaceAround"));
- assertThat(element.getText(), is("Spaced out"));
+ assertThat(element.getText()).isEqualTo("Spaced out");
}
@Test
public void testShouldFindElementsByClassWhenItsNameIsSurroundedByWhitespace() {
driver.get(pages.xhtmlTestPage);
List elements = driver.findElements(By.className("spaceAround"));
- assertThat(elements.size(), is(1));
- assertThat(elements.get(0).getText(), is("Spaced out"));
+ assertThat(elements).hasSize(1);
+ assertThat(elements.get(0).getText()).isEqualTo("Spaced out");
}
// By.className negative
@@ -328,30 +322,30 @@ public void testShouldFindElementsByClassWhenItsNameIsSurroundedByWhitespace() {
@Test
public void testShouldNotFindElementByClassWhenTheNameQueriedIsShorterThanCandidateName() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.className("nameB")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.className("nameB")));
}
@Test
public void testFindingASingleElementByEmptyClassNameShouldThrow() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.className("")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.className("")));
}
@Test
@NotYetImplemented(SAFARI)
public void testFindingMultipleElementsByEmptyClassNameShouldThrow() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElements(By.className("")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElements(By.className("")));
}
@Test
public void testFindingASingleElementByCompoundClassNameShouldThrow() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.className("a b")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.className("a b")));
}
@Test
@@ -359,15 +353,15 @@ public void testFindingASingleElementByCompoundClassNameShouldThrow() {
@NotYetImplemented(SAFARI)
public void testFindingMultipleElementsByCompoundClassNameShouldThrow() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElements(By.className("a b")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElements(By.className("a b")));
}
@Test
public void testFindingASingleElementByInvalidClassNameShouldThrow() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.className("!@#$%^&*")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.className("!@#$%^&*")));
}
@Test
@@ -375,8 +369,8 @@ public void testFindingASingleElementByInvalidClassNameShouldThrow() {
@NotYetImplemented(SAFARI)
public void testFindingMultipleElementsByInvalidClassNameShouldThrow() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElements(By.className("!@#$%^&*")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElements(By.className("!@#$%^&*")));
}
// By.xpath positive
@@ -385,31 +379,31 @@ public void testFindingMultipleElementsByInvalidClassNameShouldThrow() {
public void testShouldBeAbleToFindASingleElementByXPath() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.xpath("//h1"));
- assertThat(element.getText(), is("XHTML Might Be The Future"));
+ assertThat(element.getText()).isEqualTo("XHTML Might Be The Future");
}
@Test
public void testShouldBeAbleToFindMultipleElementsByXPath() {
driver.get(pages.xhtmlTestPage);
List elements = driver.findElements(By.xpath("//div"));
- assertThat(elements.size(), is(13));
+ assertThat(elements).hasSize(13);
}
@Test
public void testShouldBeAbleToFindManyElementsRepeatedlyByXPath() {
driver.get(pages.xhtmlTestPage);
String xpathString = "//node()[contains(@id,'id')]";
- assertThat(driver.findElements(By.xpath(xpathString)).size(), is(3));
+ assertThat(driver.findElements(By.xpath(xpathString))).hasSize(3);
xpathString = "//node()[contains(@id,'nope')]";
- assertThat(driver.findElements(By.xpath(xpathString)).size(), is(0));
+ assertThat(driver.findElements(By.xpath(xpathString))).hasSize(0);
}
@Test
public void testShouldBeAbleToIdentifyElementsByClass() {
driver.get(pages.xhtmlTestPage);
WebElement header = driver.findElement(By.xpath("//h1[@class='header']"));
- assertThat(header.getText(), is("XHTML Might Be The Future"));
+ assertThat(header.getText()).isEqualTo("XHTML Might Be The Future");
}
@Test
@@ -417,22 +411,22 @@ public void testShouldBeAbleToFindAnElementByXPathWithMultipleAttributes() {
driver.get(pages.formPage);
WebElement element = driver.findElement(
By.xpath("//form[@name='optional']/input[@type='submit' and @value='Click!']"));
- assertThat(element.getTagName().toLowerCase(), is("input"));
- assertThat(element.getAttribute("value"), is("Click!"));
+ assertThat(element.getTagName()).isEqualToIgnoringCase("input");
+ assertThat(element.getAttribute("value")).isEqualTo("Click!");
}
@Test
public void testFindingALinkByXpathShouldLocateAnElementWithTheGivenText() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.xpath("//a[text()='click me']"));
- assertThat(element.getText(), is("click me"));
+ assertThat(element.getText()).isEqualTo("click me");
}
@Test
public void testFindingALinkByXpathUsingContainsKeywordShouldWork() {
driver.get(pages.nestedPage);
WebElement element = driver.findElement(By.xpath("//a[contains(.,'hello world')]"));
- assertThat(element.getText(), containsString("hello world"));
+ assertThat(element.getText()).contains("hello world");
}
@Test
@@ -442,7 +436,7 @@ public void testFindingALinkByXpathUsingContainsKeywordShouldWork() {
public void testShouldBeAbleToFindElementByXPathWithNamespace() {
driver.get(pages.svgPage);
WebElement element = driver.findElement(By.xpath("//svg:svg//svg:text"));
- assertThat(element.getText(), is("Test Chart"));
+ assertThat(element.getText()).isEqualTo("Test Chart");
}
@Test
@@ -452,7 +446,7 @@ public void testShouldBeAbleToFindElementByXPathWithNamespace() {
public void testShouldBeAbleToFindElementByXPathInXmlDocument() {
driver.get(pages.simpleXmlDocument);
WebElement element = driver.findElement(By.xpath("//foo"));
- assertThat(element.getText(), is("baz"));
+ assertThat(element.getText()).isEqualTo("baz");
}
// By.xpath negative
@@ -460,26 +454,26 @@ public void testShouldBeAbleToFindElementByXPathInXmlDocument() {
@Test
public void testShouldThrowAnExceptionWhenThereIsNoLinkToClick() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.xpath("//a[@id='Not here']")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.xpath("//a[@id='Not here']")));
}
@Test
@NotYetImplemented(SAFARI)
public void testShouldThrowInvalidSelectorExceptionWhenXPathIsSyntacticallyInvalidInDriverFindElement() {
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.xpath("this][isnot][valid")));
- assertThat(t, instanceOf(InvalidSelectorException.class));
+ assertThatExceptionOfType(InvalidSelectorException.class)
+ .isThrownBy(() -> driver.findElement(By.xpath("this][isnot][valid")));
}
@Test
@NotYetImplemented(SAFARI)
public void testShouldThrowInvalidSelectorExceptionWhenXPathIsSyntacticallyInvalidInDriverFindElements() {
- assumeFalse("Ignoring xpath error test in IE6", TestUtilities.isIe6(driver));
+ assumeFalse("Ignoring xpath error test in IE6", isIe6(driver));
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElements(By.xpath("this][isnot][valid")));
- assertThat(t, instanceOf(InvalidSelectorException.class));
+ assertThatExceptionOfType(InvalidSelectorException.class)
+ .isThrownBy(() -> driver.findElements(By.xpath("this][isnot][valid")));
}
@Test
@@ -487,37 +481,37 @@ public void testShouldThrowInvalidSelectorExceptionWhenXPathIsSyntacticallyInval
public void testShouldThrowInvalidSelectorExceptionWhenXPathIsSyntacticallyInvalidInElementFindElement() {
driver.get(pages.formPage);
WebElement body = driver.findElement(By.tagName("body"));
- Throwable t = catchThrowable(() -> body.findElement(By.xpath("this][isnot][valid")));
- assertThat(t, instanceOf(InvalidSelectorException.class));
+ assertThatExceptionOfType(InvalidSelectorException.class)
+ .isThrownBy(() -> body.findElement(By.xpath("this][isnot][valid")));
}
@Test
@NotYetImplemented(SAFARI)
public void testShouldThrowInvalidSelectorExceptionWhenXPathIsSyntacticallyInvalidInElementFindElements() {
- assumeFalse("Ignoring xpath error test in IE6", TestUtilities.isIe6(driver));
+ assumeFalse("Ignoring xpath error test in IE6", isIe6(driver));
driver.get(pages.formPage);
WebElement body = driver.findElement(By.tagName("body"));
- Throwable t = catchThrowable(() -> body.findElements(By.xpath("this][isnot][valid")));
- assertThat(t, instanceOf(InvalidSelectorException.class));
+ assertThatExceptionOfType(InvalidSelectorException.class)
+ .isThrownBy(() -> body.findElements(By.xpath("this][isnot][valid")));
}
@Test
@NotYetImplemented(SAFARI)
public void testShouldThrowInvalidSelectorExceptionWhenXPathReturnsWrongTypeInDriverFindElement() {
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.xpath("count(//input)")));
- assertThat(t, instanceOf(InvalidSelectorException.class));
+ assertThatExceptionOfType(InvalidSelectorException.class)
+ .isThrownBy(() -> driver.findElement(By.xpath("count(//input)")));
}
@Test
@NotYetImplemented(SAFARI)
public void testShouldThrowInvalidSelectorExceptionWhenXPathReturnsWrongTypeInDriverFindElements() {
- assumeFalse("Ignoring xpath error test in IE6", TestUtilities.isIe6(driver));
+ assumeFalse("Ignoring xpath error test in IE6", isIe6(driver));
driver.get(pages.formPage);
- Throwable t = catchThrowable(() -> driver.findElements(By.xpath("count(//input)")));
- assertThat(t, instanceOf(InvalidSelectorException.class));
+ assertThatExceptionOfType(InvalidSelectorException.class)
+ .isThrownBy(() -> driver.findElements(By.xpath("count(//input)")));
}
@Test
@@ -526,19 +520,19 @@ public void testShouldThrowInvalidSelectorExceptionWhenXPathReturnsWrongTypeInEl
driver.get(pages.formPage);
WebElement body = driver.findElement(By.tagName("body"));
- Throwable t = catchThrowable(() -> body.findElement(By.xpath("count(//input)")));
- assertThat(t, instanceOf(InvalidSelectorException.class));
+ assertThatExceptionOfType(InvalidSelectorException.class)
+ .isThrownBy(() -> body.findElement(By.xpath("count(//input)")));
}
@Test
@NotYetImplemented(SAFARI)
public void testShouldThrowInvalidSelectorExceptionWhenXPathReturnsWrongTypeInElementFindElements() {
- assumeFalse("Ignoring xpath error test in IE6", TestUtilities.isIe6(driver));
+ assumeFalse("Ignoring xpath error test in IE6", isIe6(driver));
driver.get(pages.formPage);
WebElement body = driver.findElement(By.tagName("body"));
- Throwable t = catchThrowable(() -> body.findElements(By.xpath("count(//input)")));
- assertThat(t, instanceOf(InvalidSelectorException.class));
+ assertThatExceptionOfType(InvalidSelectorException.class)
+ .isThrownBy(() -> body.findElements(By.xpath("count(//input)")));
}
// By.cssSelector positive
@@ -547,32 +541,32 @@ public void testShouldThrowInvalidSelectorExceptionWhenXPathReturnsWrongTypeInEl
public void testShouldBeAbleToFindASingleElementByCssSelector() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.cssSelector("div.content"));
- assertThat(element.getTagName().toLowerCase(), is("div"));
- assertThat(element.getAttribute("class"), is("content"));
+ assertThat(element.getTagName()).isEqualToIgnoringCase("div");
+ assertThat(element.getAttribute("class")).isEqualTo("content");
}
@Test
public void testShouldBeAbleToFindMultipleElementsByCssSelector() {
driver.get(pages.xhtmlTestPage);
List elements = driver.findElements(By.cssSelector("p"));
- assertThat(elements.size(), greaterThan(1));
+ assertThat(elements.size()).isGreaterThan(1);
}
@Test
public void testShouldBeAbleToFindASingleElementByCompoundCssSelector() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.cssSelector("div.extraDiv, div.content"));
- assertThat(element.getTagName().toLowerCase(), is("div"));
- assertThat(element.getAttribute("class"), is("content"));
+ assertThat(element.getTagName()).isEqualToIgnoringCase("div");
+ assertThat(element.getAttribute("class")).isEqualTo("content");
}
@Test
public void testShouldBeAbleToFindMultipleElementsByCompoundCssSelector() {
driver.get(pages.xhtmlTestPage);
List elements = driver.findElements(By.cssSelector("div.extraDiv, div.content"));
- assertThat(elements.size(), greaterThan(1));
- assertThat(elements.get(0).getAttribute("class"), is("content"));
- assertThat(elements.get(1).getAttribute("class"), is("extraDiv"));
+ assertThat(elements.size()).isGreaterThan(1);
+ assertThat(elements.get(0).getAttribute("class")).isEqualTo("content");
+ assertThat(elements.get(1).getAttribute("class")).isEqualTo("extraDiv");
}
@Test
@@ -580,21 +574,21 @@ public void testShouldBeAbleToFindMultipleElementsByCompoundCssSelector() {
public void testShouldBeAbleToFindAnElementByBooleanAttributeUsingCssSelector() {
driver.get(appServer.whereIs("locators_tests/boolean_attribute_selected.html"));
WebElement element = driver.findElement(By.cssSelector("option[selected='selected']"));
- assertThat(element.getAttribute("value"), is("two"));
+ assertThat(element.getAttribute("value")).isEqualTo("two");
}
@Test
public void testShouldBeAbleToFindAnElementByBooleanAttributeUsingShortCssSelector() {
driver.get(appServer.whereIs("locators_tests/boolean_attribute_selected.html"));
WebElement element = driver.findElement(By.cssSelector("option[selected]"));
- assertThat(element.getAttribute("value"), is("two"));
+ assertThat(element.getAttribute("value")).isEqualTo("two");
}
@Test
public void testShouldBeAbleToFindAnElementByBooleanAttributeUsingShortCssSelectorOnHtml4Page() {
driver.get(appServer.whereIs("locators_tests/boolean_attribute_selected_html4.html"));
WebElement element = driver.findElement(By.cssSelector("option[selected]"));
- assertThat(element.getAttribute("value"), is("two"));
+ assertThat(element.getAttribute("value")).isEqualTo("two");
}
// By.cssSelector negative
@@ -602,48 +596,48 @@ public void testShouldBeAbleToFindAnElementByBooleanAttributeUsingShortCssSelect
@Test
public void testShouldNotFindElementByCssSelectorWhenThereIsNoSuchElement() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.cssSelector(".there-is-no-such-class")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.cssSelector(".there-is-no-such-class")));
}
@Test
public void testShouldNotFindElementsByCssSelectorWhenThereIsNoSuchElement() {
driver.get(pages.xhtmlTestPage);
List elements = driver.findElements(By.cssSelector(".there-is-no-such-class"));
- assertThat(elements.size(), is(0));
+ assertThat(elements).hasSize(0);
}
@Test
@NotYetImplemented(SAFARI)
public void testFindingASingleElementByEmptyCssSelectorShouldThrow() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.cssSelector("")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.cssSelector("")));
}
@Test
@NotYetImplemented(SAFARI)
public void testFindingMultipleElementsByEmptyCssSelectorShouldThrow() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElements(By.cssSelector("")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElements(By.cssSelector("")));
}
@Test
@NotYetImplemented(SAFARI)
public void testFindingASingleElementByInvalidCssSelectorShouldThrow() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.cssSelector("//a/b/c[@id='1']")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.cssSelector("//a/b/c[@id='1']")));
}
@Test
@NotYetImplemented(SAFARI)
public void testFindingMultipleElementsByInvalidCssSelectorShouldThrow() {
- assumeFalse("Ignoring test for lack of error in CSS in IE6", TestUtilities.isIe6(driver));
+ assumeFalse("Ignoring test for lack of error in CSS in IE6", isIe6(driver));
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElements(By.cssSelector("//a/b/c[@id='1']")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElements(By.cssSelector("//a/b/c[@id='1']")));
}
// By.linkText positive
@@ -652,29 +646,29 @@ public void testFindingMultipleElementsByInvalidCssSelectorShouldThrow() {
public void testShouldBeAbleToFindALinkByText() {
driver.get(pages.xhtmlTestPage);
WebElement link = driver.findElement(By.linkText("click me"));
- assertThat(link.getText(), is("click me"));
+ assertThat(link.getText()).isEqualTo("click me");
}
@Test
public void testShouldBeAbleToFindMultipleLinksByText() {
driver.get(pages.xhtmlTestPage);
List elements = driver.findElements(By.linkText("click me"));
- assertThat(elements.size(), is(2));
+ assertThat(elements).hasSize(2);
}
@Test
public void testShouldFindElementByLinkTextContainingEqualsSign() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.linkText("Link=equalssign"));
- assertThat(element.getAttribute("id"), is("linkWithEqualsSign"));
+ assertThat(element.getAttribute("id")).isEqualTo("linkWithEqualsSign");
}
@Test
public void testShouldFindMultipleElementsByLinkTextContainingEqualsSign() {
driver.get(pages.xhtmlTestPage);
List elements = driver.findElements(By.linkText("Link=equalssign"));
- assertEquals(1, elements.size());
- assertThat(elements.get(0).getAttribute("id"), is("linkWithEqualsSign"));
+ assertThat(elements).hasSize(1);
+ assertThat(elements.get(0).getAttribute("id")).isEqualTo("linkWithEqualsSign");
}
@Test
@@ -685,7 +679,7 @@ public void findsByLinkTextOnXhtmlPage() {
driver.get(appServer.whereIs("actualXhtmlPage.xhtml"));
String linkText = "Foo";
WebElement element = driver.findElement(By.linkText(linkText));
- assertThat(element.getText(), is(linkText));
+ assertThat(element.getText()).isEqualTo(linkText);
}
@Test
@@ -694,7 +688,7 @@ public void testLinkWithFormattingTags() {
WebElement elem = driver.findElement(By.id("links"));
WebElement res = elem.findElement(By.partialLinkText("link with formatting tags"));
- assertThat(res.getText(), is("link with formatting tags"));
+ assertThat(res.getText()).isEqualTo("link with formatting tags");
}
@Test
@@ -702,8 +696,8 @@ public void testLinkWithFormattingTags() {
public void testDriverCanGetLinkByLinkTestIgnoringTrailingWhitespace() {
driver.get(pages.simpleTestPage);
WebElement link = driver.findElement(By.linkText("link with trailing space"));
- assertThat(link.getAttribute("id"), is("linkWithTrailingSpace"));
- assertThat(link.getText(), is("link with trailing space"));
+ assertThat(link.getAttribute("id")).isEqualTo("linkWithTrailingSpace");
+ assertThat(link.getText()).isEqualTo("link with trailing space");
}
// By.linkText negative
@@ -711,15 +705,15 @@ public void testDriverCanGetLinkByLinkTestIgnoringTrailingWhitespace() {
@Test
public void testShouldNotBeAbleToLocateByLinkTextASingleElementThatDoesNotExist() {
driver.get(pages.xhtmlTestPage);
- Throwable t = catchThrowable(() -> driver.findElement(By.linkText("Not here either")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.linkText("Not here either")));
}
@Test
public void testShouldNotBeAbleToLocateByLinkTextMultipleElementsThatDoNotExist() {
driver.get(pages.xhtmlTestPage);
List elements = driver.findElements(By.linkText("Not here either"));
- assertThat(elements.size(), is(0));
+ assertThat(elements.size()).isEqualTo(0);
}
// By.partialLinkText positive
@@ -728,29 +722,29 @@ public void testShouldNotBeAbleToLocateByLinkTextMultipleElementsThatDoNotExist(
public void testShouldBeAbleToFindMultipleElementsByPartialLinkText() {
driver.get(pages.xhtmlTestPage);
List elements = driver.findElements(By.partialLinkText("ick me"));
- assertThat(elements.size(), is(2));
+ assertThat(elements.size()).isEqualTo(2);
}
@Test
public void testShouldBeAbleToFindASingleElementByPartialLinkText() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.partialLinkText("anon"));
- assertThat(element.getText(), containsString("anon"));
+ assertThat(element.getText()).contains("anon");
}
@Test
public void testShouldFindElementByPartialLinkTextContainingEqualsSign() {
driver.get(pages.xhtmlTestPage);
WebElement element = driver.findElement(By.partialLinkText("Link="));
- assertThat(element.getAttribute("id"), is("linkWithEqualsSign"));
+ assertThat(element.getAttribute("id")).isEqualTo("linkWithEqualsSign");
}
@Test
public void testShouldFindMultipleElementsByPartialLinkTextContainingEqualsSign() {
driver.get(pages.xhtmlTestPage);
List elements = driver.findElements(By.partialLinkText("Link="));
- assertThat(elements.size(), is(1));
- assertThat(elements.get(0).getAttribute("id"), is("linkWithEqualsSign"));
+ assertThat(elements).hasSize(1);
+ assertThat(elements.get(0).getAttribute("id")).isEqualTo("linkWithEqualsSign");
}
// Misc tests
@@ -760,7 +754,7 @@ public void testDriverShouldBeAbleToFindElementsAfterLoadingMoreThanOnePageAtATi
driver.get(pages.formPage);
driver.get(pages.xhtmlTestPage);
WebElement link = driver.findElement(By.linkText("click me"));
- assertThat(link.getText(), is("click me"));
+ assertThat(link.getText()).isEqualTo("click me");
}
// You don't want to ask why this is here
@@ -769,38 +763,38 @@ public void testWhenFindingByNameShouldNotReturnById() {
driver.get(pages.formPage);
WebElement element = driver.findElement(By.name("id-name1"));
- assertThat(element.getAttribute("value"), is("name"));
+ assertThat(element.getAttribute("value")).isEqualTo("name");
element = driver.findElement(By.id("id-name1"));
- assertThat(element.getAttribute("value"), is("id"));
+ assertThat(element.getAttribute("value")).isEqualTo("id");
element = driver.findElement(By.name("id-name2"));
- assertThat(element.getAttribute("value"), is("name"));
+ assertThat(element.getAttribute("value")).isEqualTo("name");
element = driver.findElement(By.id("id-name2"));
- assertThat(element.getAttribute("value"), is("id"));
+ assertThat(element.getAttribute("value")).isEqualTo("id");
}
@Test
public void testShouldBeAbleToFindAHiddenElementsByName() {
driver.get(pages.formPage);
WebElement element = driver.findElement(By.name("hidden"));
- assertThat(element.getAttribute("name"), is("hidden"));
+ assertThat(element.getAttribute("name")).isEqualTo("hidden");
}
@Test
public void testShouldNotBeAbleToFindAnElementOnABlankPage() {
driver.get("about:blank");
- Throwable t = catchThrowable(() -> driver.findElement(By.tagName("a")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.tagName("a")));
}
@NeedsFreshDriver
@Test
public void testShouldNotBeAbleToLocateASingleElementOnABlankPage() {
// Note we're on the default start page for the browser at this point.
- Throwable t = catchThrowable(() -> driver.findElement(By.id("nonExistantButton")));
- assertThat(t, instanceOf(NoSuchElementException.class));
+ assertThatExceptionOfType(NoSuchElementException.class)
+ .isThrownBy(() -> driver.findElement(By.id("nonExistantButton")));
}
@SwitchToTopAfterTest
@@ -810,8 +804,8 @@ public void testAnElementFoundInADifferentFrameIsStale() {
driver.switchTo().frame("inner");
WebElement element = driver.findElement(By.id("oneline"));
driver.switchTo().defaultContent();
- Throwable t = catchThrowable(element::getText);
- assertThat(t, instanceOf(StaleElementReferenceException.class));
+ assertThatExceptionOfType(StaleElementReferenceException.class)
+ .isThrownBy(element::getText);
}
@SwitchToTopAfterTest
@@ -832,8 +826,8 @@ public void testAnElementFoundInADifferentFrameViaJsCanBeUsed() {
WebElement second = driver.findElement(By.id("oneline"));
- assertEquals(first, element);
- assertEquals(second, element);
+ assertThat(element).isEqualTo(first);
+ assertThat(element).isEqualTo(second);
}
}
diff --git a/java/client/test/org/openqa/selenium/ElementSelectingTest.java b/java/client/test/org/openqa/selenium/ElementSelectingTest.java
index b5a1e74dacb49..274b6583c0a0b 100644
--- a/java/client/test/org/openqa/selenium/ElementSelectingTest.java
+++ b/java/client/test/org/openqa/selenium/ElementSelectingTest.java
@@ -17,10 +17,7 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.openqa.selenium.support.ui.ExpectedConditions;
@@ -98,11 +95,11 @@ public void testClickingOnASelectedRadioButtonShouldLeaveItSelected() {
driver.get(pages.formPage);
WebElement button = enabledSelectedRadioButton();
- assertTrue(button.isSelected());
+ assertThat(button.isSelected()).isTrue();
button.click();
- assertTrue(button.isSelected());
+ assertThat(button.isSelected()).isTrue();
}
@Test
@@ -174,16 +171,16 @@ private void assertSelected(WebElement element) {
private void assertSelected(WebElement element, boolean isSelected) {
wait.until(ExpectedConditions.elementSelectionStateToBe(element, isSelected));
- assertThat(
- String.format("Expected element %s to be %s but was %s",
- describe(element), selectedToString(isSelected), selectedToString(!isSelected)),
- element.isSelected(), is(isSelected));
+ assertThat(element.isSelected())
+ .describedAs("Expected element %s to be %s",
+ describe(element), selectedToString(isSelected), selectedToString(!isSelected))
+ .isEqualTo(isSelected);
}
private void assertCannotSelect(WebElement element) {
boolean previous = element.isSelected();
element.click();
- assertEquals(previous, element.isSelected());
+ assertThat(element.isSelected()).isEqualTo(previous);
}
private void assertCanSelect(WebElement element) {
@@ -219,12 +216,10 @@ private void assertCanToggle(WebElement element) {
private void assertTogglingSwapsSelectedStateFrom(WebElement element, boolean originalState) {
element.click();
boolean isNowSelected = element.isSelected();
- assertThat(
- String.format("Expected element %s to have been toggled to %s but was %s",
- describe(element),
- selectedToString(!originalState),
- selectedToString(originalState)),
- isNowSelected, is(!(originalState)));
+ assertThat(isNowSelected)
+ .describedAs("Expected element %s to have been toggled to %s",
+ describe(element), selectedToString(!originalState))
+ .isEqualTo(!(originalState));
assertSelected(element, !originalState);
}
diff --git a/java/client/test/org/openqa/selenium/ErrorsTest.java b/java/client/test/org/openqa/selenium/ErrorsTest.java
index c15787020043f..d5861f001be22 100644
--- a/java/client/test/org/openqa/selenium/ErrorsTest.java
+++ b/java/client/test/org/openqa/selenium/ErrorsTest.java
@@ -17,7 +17,7 @@
package org.openqa.selenium;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.selenium.testing.Driver.IE;
import org.junit.Test;
@@ -39,6 +39,6 @@ public void testShouldNotGenerateErrorsWhenOpeningANewPage() {
driver.get(pages.errorsPage);
Object result = ((JavascriptExecutor) driver).
executeScript("return window.ERRORS.join('\\n');");
- assertEquals("Should have no errors", "", result);
+ assertThat(result).isEqualTo("");
}
}
diff --git a/java/client/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java b/java/client/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java
index 302b506af1658..9ab288e6a85c1 100644
--- a/java/client/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java
+++ b/java/client/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java
@@ -17,25 +17,16 @@
package org.openqa.selenium;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static com.google.common.base.Throwables.getRootCause;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.junit.Assume.assumeTrue;
import static org.openqa.selenium.testing.Driver.CHROME;
import static org.openqa.selenium.testing.Driver.HTMLUNIT;
import static org.openqa.selenium.testing.Driver.IE;
import static org.openqa.selenium.testing.Driver.MARIONETTE;
import static org.openqa.selenium.testing.Driver.SAFARI;
-import static org.openqa.selenium.testing.TestUtilities.catchThrowable;
-
-import com.google.common.base.Throwables;
import org.junit.Before;
import org.junit.Test;
@@ -44,6 +35,7 @@
import org.openqa.selenium.testing.NeedsLocalEnvironment;
import org.openqa.selenium.testing.NotYetImplemented;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -63,25 +55,28 @@ public void setUp() {
public void shouldNotTimeoutIfCallbackInvokedImmediately() {
driver.get(pages.ajaxyPage);
Object result = executor.executeAsyncScript("arguments[arguments.length - 1](123);");
- assertThat(result, instanceOf(Number.class));
- assertEquals(123, ((Number) result).intValue());
+ assertThat(result).isInstanceOf(Number.class);
+ assertThat(((Number) result).intValue()).isEqualTo(123);
}
@Test
public void shouldBeAbleToReturnJavascriptPrimitivesFromAsyncScripts_NeitherNullNorUndefined() {
driver.get(pages.ajaxyPage);
- assertEquals(123, ((Number) executor.executeAsyncScript(
- "arguments[arguments.length - 1](123);")).longValue());
- assertEquals("abc", executor.executeAsyncScript("arguments[arguments.length - 1]('abc');"));
- assertFalse((Boolean) executor.executeAsyncScript("arguments[arguments.length - 1](false);"));
- assertTrue((Boolean) executor.executeAsyncScript("arguments[arguments.length - 1](true);"));
+ assertThat(((Number) executor.executeAsyncScript(
+ "arguments[arguments.length - 1](123);")).longValue()).isEqualTo(123);
+ assertThat(executor.executeAsyncScript("arguments[arguments.length - 1]('abc');"))
+ .isEqualTo("abc");
+ assertThat((Boolean) executor.executeAsyncScript("arguments[arguments.length - 1](false);"))
+ .isFalse();
+ assertThat((Boolean) executor.executeAsyncScript("arguments[arguments.length - 1](true);"))
+ .isTrue();
}
@Test
public void shouldBeAbleToReturnJavascriptPrimitivesFromAsyncScripts_NullAndUndefined() {
driver.get(pages.ajaxyPage);
- assertNull(executor.executeAsyncScript("arguments[arguments.length - 1](null)"));
- assertNull(executor.executeAsyncScript("arguments[arguments.length - 1]()"));
+ assertThat(executor.executeAsyncScript("arguments[arguments.length - 1](null)")).isNull();
+ assertThat(executor.executeAsyncScript("arguments[arguments.length - 1]()")).isNull();
}
@Test
@@ -89,9 +84,8 @@ public void shouldBeAbleToReturnAnArrayLiteralFromAnAsyncScript() {
driver.get(pages.ajaxyPage);
Object result = executor.executeAsyncScript("arguments[arguments.length - 1]([]);");
- assertNotNull("Expected not to be null!", result);
- assertThat(result, instanceOf(List.class));
- assertTrue(((List>) result).isEmpty());
+ assertThat(result).isNotNull().isInstanceOf(List.class);
+ assertThat(((List>) result)).isEmpty();
}
@Test
@@ -99,9 +93,8 @@ public void shouldBeAbleToReturnAnArrayObjectFromAnAsyncScript() {
driver.get(pages.ajaxyPage);
Object result = executor.executeAsyncScript("arguments[arguments.length - 1](new Array());");
- assertNotNull("Expected not to be null!", result);
- assertThat(result, instanceOf(List.class));
- assertTrue(((List>) result).isEmpty());
+ assertThat(result).isNotNull().isInstanceOf(List.class);
+ assertThat(((List>) result)).isEmpty();
}
@Test
@@ -111,16 +104,16 @@ public void shouldBeAbleToReturnArraysOfPrimitivesFromAsyncScripts() {
Object result = executor.executeAsyncScript(
"arguments[arguments.length - 1]([null, 123, 'abc', true, false]);");
- assertNotNull(result);
- assertThat(result, instanceOf(List.class));
+ assertThat(result).isNotNull();
+ assertThat(result).isInstanceOf(List.class);
Iterator> results = ((List>) result).iterator();
- assertNull(results.next());
- assertEquals(123, ((Number) results.next()).longValue());
- assertEquals("abc", results.next());
- assertTrue((Boolean) results.next());
- assertFalse((Boolean) results.next());
- assertFalse(results.hasNext());
+ assertThat(results.next()).isNull();
+ assertThat(((Number) results.next()).longValue()).isEqualTo(123);
+ assertThat(results.next()).isEqualTo("abc");
+ assertThat((Boolean) results.next()).isTrue();
+ assertThat((Boolean) results.next()).isFalse();
+ assertThat(results.hasNext()).isFalse();
}
@Test
@@ -128,8 +121,8 @@ public void shouldBeAbleToReturnWebElementsFromAsyncScripts() {
driver.get(pages.ajaxyPage);
Object result = executor.executeAsyncScript("arguments[arguments.length - 1](document.body);");
- assertThat(result, instanceOf(WebElement.class));
- assertEquals("body", ((WebElement) result).getTagName().toLowerCase());
+ assertThat(result).isInstanceOf(WebElement.class);
+ assertThat(((WebElement) result).getTagName()).isEqualToIgnoringCase("body");
}
@Test
@@ -138,31 +131,29 @@ public void shouldBeAbleToReturnArraysOfWebElementsFromAsyncScripts() {
Object result = executor.executeAsyncScript(
"arguments[arguments.length - 1]([document.body, document.body]);");
- assertNotNull(result);
- assertThat(result, instanceOf(List.class));
+ assertThat(result).isNotNull().isInstanceOf(List.class);
List> list = (List>) result;
- assertEquals(2, list.size());
- assertThat(list.get(0), instanceOf(WebElement.class));
- assertThat(list.get(1), instanceOf(WebElement.class));
- assertEquals("body", ((WebElement) list.get(0)).getTagName().toLowerCase());
- assertEquals(list.get(0), list.get(1));
+ assertThat(list).hasSize(2);
+ assertThat(list.get(0)).isInstanceOf(WebElement.class);
+ assertThat(list.get(1)).isInstanceOf(WebElement.class);
+ assertThat(((WebElement) list.get(0)).getTagName()).isEqualToIgnoringCase("body");
+ assertThat(list.get(1)).isEqualTo(list.get(0));
}
@Test
public void shouldTimeoutIfScriptDoesNotInvokeCallback() {
driver.get(pages.ajaxyPage);
// Script is expected to be async and explicitly callback, so this should timeout.
- Throwable t = catchThrowable(() -> executor.executeAsyncScript("return 1 + 2;"));
- assertThat(t, instanceOf(ScriptTimeoutException.class));
+ assertThatExceptionOfType(ScriptTimeoutException.class)
+ .isThrownBy(() -> executor.executeAsyncScript("return 1 + 2;"));
}
@Test
public void shouldTimeoutIfScriptDoesNotInvokeCallbackWithAZeroTimeout() {
driver.get(pages.ajaxyPage);
- Throwable t = catchThrowable(
- () -> executor.executeAsyncScript("window.setTimeout(function() {}, 0);"));
- assertThat(t, instanceOf(ScriptTimeoutException.class));
+ assertThatExceptionOfType(ScriptTimeoutException.class)
+ .isThrownBy(() -> executor.executeAsyncScript("window.setTimeout(function() {}, 0);"));
}
@Test
@@ -176,39 +167,39 @@ public void shouldNotTimeoutIfScriptCallsbackInsideAZeroTimeout() {
@Test
public void shouldTimeoutIfScriptDoesNotInvokeCallbackWithLongTimeout() {
- driver.manage().timeouts().setScriptTimeout(500, TimeUnit.MILLISECONDS);
+ driver.manage().timeouts().setScriptTimeout(500, MILLISECONDS);
driver.get(pages.ajaxyPage);
- Throwable t = catchThrowable(() -> executor.executeAsyncScript(
- "var callback = arguments[arguments.length - 1];" +
- "window.setTimeout(callback, 1500);"));
- assertThat(t, instanceOf(ScriptTimeoutException.class));
+ assertThatExceptionOfType(ScriptTimeoutException.class)
+ .isThrownBy(() -> executor.executeAsyncScript(
+ "var callback = arguments[arguments.length - 1];" +
+ "window.setTimeout(callback, 1500);"));
}
@Test
@Ignore(IE)
public void shouldDetectPageLoadsWhileWaitingOnAnAsyncScriptAndReturnAnError() {
driver.get(pages.ajaxyPage);
- driver.manage().timeouts().setScriptTimeout(100, TimeUnit.MILLISECONDS);
- Throwable t = catchThrowable(
+ driver.manage().timeouts().setScriptTimeout(100, MILLISECONDS);
+ assertThatExceptionOfType(WebDriverException.class).isThrownBy(
() -> executor.executeAsyncScript("window.location = '" + pages.dynamicPage + "';"));
- assertThat(t, instanceOf(WebDriverException.class));
}
@Test
public void shouldCatchErrorsWhenExecutingInitialScript() {
driver.get(pages.ajaxyPage);
- Throwable t = catchThrowable(
- () -> executor.executeAsyncScript("throw Error('you should catch this!');"));
- assertThat(t, instanceOf(WebDriverException.class));
+ assertThatExceptionOfType(WebDriverException.class)
+ .isThrownBy(() -> executor.executeAsyncScript("throw Error('you should catch this!');"));
}
@Test
public void shouldNotTimeoutWithMultipleCallsTheFirstOneBeingSynchronous() {
driver.get(pages.ajaxyPage);
driver.manage().timeouts().setScriptTimeout(10, TimeUnit.MILLISECONDS);
- assertTrue((Boolean) executor.executeAsyncScript("arguments[arguments.length - 1](true);"));
- assertTrue((Boolean) executor.executeAsyncScript(
- "var cb = arguments[arguments.length - 1]; window.setTimeout(function(){cb(true);}, 9);"));
+ assertThat((Boolean) executor.executeAsyncScript("arguments[arguments.length - 1](true);"))
+ .isTrue();
+ assertThat((Boolean) executor.executeAsyncScript(
+ "var cb = arguments[arguments.length - 1]; window.setTimeout(function(){cb(true);}, 9);"))
+ .isTrue();
}
@Test
@@ -220,23 +211,19 @@ public void shouldNotTimeoutWithMultipleCallsTheFirstOneBeingSynchronous() {
public void shouldCatchErrorsWithMessageAndStacktraceWhenExecutingInitialScript() {
driver.get(pages.ajaxyPage);
String js = "function functionB() { throw Error('errormessage'); };"
- + "function functionA() { functionB(); };"
- + "functionA();";
- Throwable t = catchThrowable(() -> executor.executeAsyncScript(js));
- assertThat(t, instanceOf(WebDriverException.class));
- assertThat(t.getMessage(), containsString("errormessage"));
-
- Throwable rootCause = Throwables.getRootCause(t);
- assertThat(rootCause.getMessage(), containsString("errormessage"));
-
- StackTraceElement [] st = rootCause.getStackTrace();
- boolean seen = false;
- for (StackTraceElement s: st) {
- if (s.getMethodName().equals("functionB")) {
- seen = true;
- }
- }
- assertTrue("Stacktrace has not js method info", seen);
+ + "function functionA() { functionB(); };"
+ + "functionA();";
+ assertThatExceptionOfType(WebDriverException.class)
+ .isThrownBy(() -> executor.executeAsyncScript(js))
+ .withMessageContaining("errormessage")
+ .satisfies(t -> {
+ Throwable rootCause = getRootCause(t);
+ assertThat(rootCause).hasMessageContaining("errormessage");
+ assertThat(Arrays.asList(rootCause.getStackTrace()))
+ .extracting(StackTraceElement::getMethodName)
+ .contains("functionB");
+ });
+
}
@Test
@@ -245,23 +232,25 @@ public void shouldBeAbleToExecuteAsynchronousScripts() {
WebElement typer = driver.findElement(By.name("typer"));
typer.sendKeys("bob");
- assertEquals("bob", typer.getAttribute("value"));
+ assertThat(typer.getAttribute("value")).isEqualTo("bob");
driver.findElement(By.id("red")).click();
driver.findElement(By.name("submit")).click();
- assertEquals("There should only be 1 DIV at this point, which is used for the butter message",
- 1, getNumDivElements());
+ assertThat(getNumDivElements())
+ .describedAs("There should only be 1 DIV at this point, which is used for the butter message")
+ .isEqualTo(1);
driver.manage().timeouts().setScriptTimeout(15, TimeUnit.SECONDS);
String text = (String) executor.executeAsyncScript(
"var callback = arguments[arguments.length - 1];"
+ "window.registerListener(arguments[arguments.length - 1]);");
- assertEquals("bob", text);
- assertEquals("", typer.getAttribute("value"));
+ assertThat(text).isEqualTo("bob");
+ assertThat(typer.getAttribute("value")).isEqualTo("");
- assertEquals("There should be 1 DIV (for the butter message) + 1 DIV (for the new label)",
- 2, getNumDivElements());
+ assertThat(getNumDivElements())
+ .describedAs("There should be 1 DIV (for the butter message) + 1 DIV (for the new label)")
+ .isEqualTo(2);
}
@Test
@@ -269,7 +258,7 @@ public void shouldBeAbleToPassMultipleArgumentsToAsyncScripts() {
driver.get(pages.ajaxyPage);
Number result = (Number) executor.executeAsyncScript(
"arguments[arguments.length - 1](arguments[0] + arguments[1]);", 1, 2);
- assertEquals(3, result.intValue());
+ assertThat(result.intValue()).isEqualTo(3);
}
@Test
@@ -301,8 +290,8 @@ public void shouldBeAbleToMakeXMLHttpRequestsAndWaitForTheResponse() {
driver.get(pages.ajaxyPage);
driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);
String response = (String) executor.executeAsyncScript(script, pages.sleepingPage + "?time=2");
- assertThat(response.trim(),
- equalTo("DoneSlept for 2s"));
+ assertThat(response.trim())
+ .isEqualTo("DoneSlept for 2s");
}
@Test
@@ -313,10 +302,10 @@ public void shouldBeAbleToMakeXMLHttpRequestsAndWaitForTheResponse() {
@NeedsLocalEnvironment(reason = "Relies on timing")
public void throwsIfScriptTriggersAlert() {
driver.get(pages.simpleTestPage);
- driver.manage().timeouts().setScriptTimeout(5000, TimeUnit.MILLISECONDS);
- Throwable t = catchThrowable(() -> executor.executeAsyncScript(
- "setTimeout(arguments[0], 200) ; setTimeout(function() { window.alert('Look! An alert!'); }, 50);"));
- assertThat(t, instanceOf(UnhandledAlertException.class));
+ driver.manage().timeouts().setScriptTimeout(5000, MILLISECONDS);
+ assertThatExceptionOfType(UnhandledAlertException.class)
+ .isThrownBy(() -> executor.executeAsyncScript(
+ "setTimeout(arguments[0], 200) ; setTimeout(function() { window.alert('Look! An alert!'); }, 50);"));
// Shouldn't throw
driver.getTitle();
}
@@ -329,9 +318,9 @@ public void throwsIfScriptTriggersAlert() {
@NeedsLocalEnvironment(reason = "Relies on timing")
public void throwsIfAlertHappensDuringScript() {
driver.get(pages.slowLoadingAlertPage);
- driver.manage().timeouts().setScriptTimeout(5000, TimeUnit.MILLISECONDS);
- Throwable t = catchThrowable(() -> executor.executeAsyncScript("setTimeout(arguments[0], 1000);"));
- assertThat(t, instanceOf(UnhandledAlertException.class));
+ driver.manage().timeouts().setScriptTimeout(5000, MILLISECONDS);
+ assertThatExceptionOfType(UnhandledAlertException.class)
+ .isThrownBy(() -> executor.executeAsyncScript("setTimeout(arguments[0], 1000);"));
// Shouldn't throw
driver.getTitle();
}
@@ -344,10 +333,10 @@ public void throwsIfAlertHappensDuringScript() {
@NeedsLocalEnvironment(reason = "Relies on timing")
public void throwsIfScriptTriggersAlertWhichTimesOut() {
driver.get(pages.simpleTestPage);
- driver.manage().timeouts().setScriptTimeout(5000, TimeUnit.MILLISECONDS);
- Throwable t = catchThrowable(() -> executor.executeAsyncScript(
- "setTimeout(function() { window.alert('Look! An alert!'); }, 50);"));
- assertThat(t, instanceOf(UnhandledAlertException.class));
+ driver.manage().timeouts().setScriptTimeout(5000, MILLISECONDS);
+ assertThatExceptionOfType(UnhandledAlertException.class)
+ .isThrownBy(() -> executor.executeAsyncScript(
+ "setTimeout(function() { window.alert('Look! An alert!'); }, 50);"));
// Shouldn't throw
driver.getTitle();
}
@@ -360,9 +349,9 @@ public void throwsIfScriptTriggersAlertWhichTimesOut() {
@NeedsLocalEnvironment(reason = "Relies on timing")
public void throwsIfAlertHappensDuringScriptWhichTimesOut() {
driver.get(pages.slowLoadingAlertPage);
- driver.manage().timeouts().setScriptTimeout(5000, TimeUnit.MILLISECONDS);
- Throwable t = catchThrowable(() -> executor.executeAsyncScript(""));
- assertThat(t, instanceOf(UnhandledAlertException.class));
+ driver.manage().timeouts().setScriptTimeout(5000, MILLISECONDS);
+ assertThatExceptionOfType(UnhandledAlertException.class)
+ .isThrownBy(() -> executor.executeAsyncScript(""));
// Shouldn't throw
driver.getTitle();
}
@@ -374,13 +363,13 @@ public void throwsIfAlertHappensDuringScriptWhichTimesOut() {
@Ignore(value = SAFARI, reason = "Does not support alerts yet")
@NeedsLocalEnvironment(reason = "Relies on timing")
public void includesAlertTextInUnhandledAlertException() {
- driver.manage().timeouts().setScriptTimeout(5000, TimeUnit.MILLISECONDS);
+ driver.manage().timeouts().setScriptTimeout(5000, MILLISECONDS);
String alertText = "Look! An alert!";
- Throwable t = catchThrowable(() -> executor.executeAsyncScript(
- "setTimeout(arguments[0], 200) ; setTimeout(function() { window.alert('" + alertText
- + "'); }, 50);"));
- assertThat(t, instanceOf(UnhandledAlertException.class));
- assertThat(((UnhandledAlertException) t).getAlertText(), is(alertText));
+ assertThatExceptionOfType(UnhandledAlertException.class)
+ .isThrownBy(() -> executor.executeAsyncScript(
+ "setTimeout(arguments[0], 200) ; setTimeout(function() { window.alert('" + alertText
+ + "'); }, 50);"))
+ .satisfies(t -> assertThat(t.getAlertText()).isEqualTo(alertText));
}
private long getNumDivElements() {
diff --git a/java/client/test/org/openqa/selenium/ExecutingJavascriptTest.java b/java/client/test/org/openqa/selenium/ExecutingJavascriptTest.java
index 572e58c62c2c0..be53482966a3c 100644
--- a/java/client/test/org/openqa/selenium/ExecutingJavascriptTest.java
+++ b/java/client/test/org/openqa/selenium/ExecutingJavascriptTest.java
@@ -17,28 +17,19 @@
package org.openqa.selenium;
+import static com.google.common.base.Throwables.getRootCause;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static java.nio.charset.StandardCharsets.US_ASCII;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
+import static org.openqa.selenium.By.id;
import static org.openqa.selenium.testing.Driver.CHROME;
import static org.openqa.selenium.testing.Driver.HTMLUNIT;
import static org.openqa.selenium.testing.Driver.IE;
import static org.openqa.selenium.testing.Driver.MARIONETTE;
import static org.openqa.selenium.testing.Driver.SAFARI;
-import static org.openqa.selenium.testing.TestUtilities.catchThrowable;
-import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -80,8 +71,7 @@ public void testShouldBeAbleToExecuteSimpleJavascriptAndReturnAString() {
Object result = executeScript("return document.title;");
- assertTrue(result instanceof String);
- assertEquals("XHTML Test Page", result);
+ assertThat(result).isInstanceOf(String.class).isEqualTo("XHTML Test Page");
}
@Test
@@ -90,8 +80,8 @@ public void testShouldBeAbleToExecuteSimpleJavascriptAndReturnALong() {
Object result = executeScript("return document.getElementsByName('checky').length;");
- assertTrue(result.getClass().getName(), result instanceof Long);
- assertTrue((Long) result > 1);
+ assertThat(result).isInstanceOf(Long.class);
+ assertThat((Long) result).isGreaterThan(1);
}
@Test
@@ -100,9 +90,8 @@ public void testShouldBeAbleToExecuteSimpleJavascriptAndReturnAWebElement() {
Object result = executeScript("return document.getElementById('id1');");
- assertNotNull(result);
- assertThat(result, instanceOf(WebElement.class));
- assertEquals("a", ((WebElement) result).getTagName().toLowerCase());
+ assertThat(result).isInstanceOf(WebElement.class);
+ assertThat(((WebElement) result).getTagName()).isEqualToIgnoringCase("a");
}
@Test
@@ -111,9 +100,8 @@ public void testShouldBeAbleToExecuteSimpleJavascriptAndReturnABoolean() {
Object result = executeScript("return true;");
- assertNotNull(result);
- assertTrue(result instanceof Boolean);
- assertTrue((Boolean) result);
+ assertThat(result).isInstanceOf(Boolean.class);
+ assertThat((Boolean) result).isTrue();
}
@SuppressWarnings("unchecked")
@@ -127,7 +115,8 @@ public void testShouldBeAbleToExecuteSimpleJavascriptAndReturnAStringsArray() {
Object result = ((JavascriptExecutor) driver).executeScript(
"return ['zero', 'one', 'two'];");
- ExecutingJavascriptTest.compareLists(expectedResult, (List