Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public Session get(SessionId id) throws NoSuchSessionException {
try (ResultSet sessions = statement.executeQuery()) {
if (!sessions.next()) {
NoSuchSessionException exception =
new NoSuchSessionException("Unable to find session.");
new NoSuchSessionException("Unable to find session with id: " + id);
span.setAttribute("error", true);
span.setStatus(Status.NOT_FOUND);
EXCEPTION.accept(attributeMap, exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ public URI getUri(SessionId id) throws NoSuchSessionException {
attributeMap.put(REDIS_URI_KEY, uriKey);

if (rawUri == null) {
NoSuchSessionException exception = new NoSuchSessionException("Unable to find session.");
NoSuchSessionException exception =
new NoSuchSessionException("Unable to find session with id: " + id);
span.setAttribute("error", true);
span.setStatus(Status.NOT_FOUND);
EXCEPTION.accept(attributeMap, exception);
Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/ChildrenFindingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void testFindingElementsOnElementByXPathShouldFindTopLevelElements() {
WebElement parent = driver.findElement(By.id("multiline"));
List<WebElement> allPs = driver.findElements(By.xpath("//p"));
List<WebElement> children = parent.findElements(By.xpath("//p"));
assertThat(allPs.size()).isEqualTo(children.size());
assertThat(allPs).hasSize(children.size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void testGetAllCookies() {

openAnotherPage();
cookies = driver.manage().getCookies();
assertThat(cookies.size()).isEqualTo(countBefore + 2);
assertThat(cookies).hasSize(countBefore + 2);

assertThat(cookies.contains(one)).isTrue();
assertThat(cookies.contains(two)).isTrue();
Expand Down
18 changes: 7 additions & 11 deletions java/test/org/openqa/selenium/CorrectEventFiringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

package org.openqa.selenium;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.fail;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.openqa.selenium.WaitingConditions.elementTextToContain;
import static org.openqa.selenium.WaitingConditions.elementTextToEqual;
Expand Down Expand Up @@ -180,11 +178,9 @@ public void testShouldFireMouseMoveEventWhenClicking() {
void testShouldNotThrowIfEventHandlerThrows() {
driver.get(pages.javascriptPage);

try {
driver.findElement(By.id("throwing-mouseover")).click();
} catch (WebDriverException e) {
fail("Error in event handler should not have propagated: " + e);
}
assertThatCode(() -> driver.findElement(By.id("throwing-mouseover")).click())
.as("Error in event handler should not have propagated")
.doesNotThrowAnyException();
}

@Test
Expand Down Expand Up @@ -410,9 +406,9 @@ public void testSendingKeysToAFocusedElementShouldNotBlurThatElement() {
throw new RuntimeException(e);
}
}
if (!focused) {
fail("Clicking on element didn't focus it in time - can't proceed so failing");
}
assertThat(focused)
.as("If clicking on element didn't focus it in time, we can't proceed with the test")
.isTrue();

element.sendKeys("a");
assertEventNotFired("blur", driver);
Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/ElementFindingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ void testShouldNotBeAbleToLocateByLinkTextMultipleElementsThatDoNotExist() {
void testShouldBeAbleToFindMultipleElementsByPartialLinkText() {
driver.get(pages.xhtmlTestPage);
List<WebElement> elements = driver.findElements(By.partialLinkText("ick me"));
assertThat(elements.size()).isEqualTo(2);
assertThat(elements).hasSize(2);
}

@Test
Expand Down
67 changes: 27 additions & 40 deletions java/test/org/openqa/selenium/PageLoadTimeOutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@

package org.openqa.selenium;

import static java.lang.System.currentTimeMillis;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.openqa.selenium.WaitingConditions.elementTextToEqual;
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
import static org.openqa.selenium.testing.drivers.Browser.EDGE;
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
import static org.openqa.selenium.testing.drivers.Browser.*;

import java.time.Duration;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -72,22 +71,16 @@ void testShouldTimeoutIfAPageTakesTooLongToLoad() {
@Ignore(value = SAFARI, reason = "Flaky")
public void testShouldTimeoutIfAPageTakesTooLongToLoadAfterClick() {
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(2));

driver.get(appServer.whereIs("page_with_link_to_slow_loading_page.html"));
WebElement link = wait.until(visibilityOfElementLocated(By.id("link-to-slow-loading-page")));

long start = System.currentTimeMillis();
try {
link.click();
fail("I should have timed out");
} catch (RuntimeException e) {
long end = System.currentTimeMillis();
driver.get(appServer.whereIs("page_with_link_to_slow_loading_page.html"));
WebElement link = wait.until(visibilityOfElementLocated(By.id("link-to-slow-loading-page")));

assertThat(e).isInstanceOf(TimeoutException.class);
long start = currentTimeMillis();

int duration = (int) (end - start);
assertThat(duration).isGreaterThan(2000);
assertThat(duration).isLessThan(5000);
assertThatThrownBy(() -> link.click()).isInstanceOf(TimeoutException.class);

long duration = currentTimeMillis() - start;
assertThat(duration).isBetween(2000L, 5000L);
} finally {
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(300));
}
Expand All @@ -109,18 +102,13 @@ public void testShouldTimeoutIfAPageTakesTooLongToRefresh() {

driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(2));

long start = System.currentTimeMillis();
try {
driver.navigate().refresh();
fail("I should have timed out");
} catch (RuntimeException e) {
long end = System.currentTimeMillis();
long start = currentTimeMillis();

assertThat(e).isInstanceOf(TimeoutException.class);
assertThatThrownBy(() -> driver.navigate().refresh()).isInstanceOf(TimeoutException.class);

int duration = (int) (end - start);
assertThat(duration).isGreaterThanOrEqualTo(2000);
assertThat(duration).isLessThan(4000);
long duration = currentTimeMillis() - start;
assertThat(duration).isBetween(2000L, 4000L);
} finally {
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(300));
}
Expand Down Expand Up @@ -163,19 +151,18 @@ private void testPageLoadTimeoutIsEnforced(long webDriverPageLoadTimeout) {

private void assertPageLoadTimeoutIsEnforced(
long webDriverPageLoadTimeout, long pageLoadTimeBuffer) {
long start = System.currentTimeMillis();
try {
driver.get(
appServer.whereIs("sleep?time=" + (webDriverPageLoadTimeout + pageLoadTimeBuffer)));
fail("I should have timed out after " + webDriverPageLoadTimeout + " seconds");
} catch (RuntimeException e) {
long end = System.currentTimeMillis();

assertThat(e).isInstanceOf(TimeoutException.class);

long duration = end - start;
assertThat(duration).isGreaterThanOrEqualTo(webDriverPageLoadTimeout * 1000);
assertThat(duration).isLessThan((webDriverPageLoadTimeout + pageLoadTimeBuffer) * 1000);
}
long start = currentTimeMillis();
assertThatThrownBy(
() -> {
driver.get(
appServer.whereIs(
"sleep?time=" + (webDriverPageLoadTimeout + pageLoadTimeBuffer)));
})
.as("Should have timed out after " + webDriverPageLoadTimeout + " seconds")
.isInstanceOf(TimeoutException.class);

long duration = currentTimeMillis() - start;
assertThat(duration).isGreaterThanOrEqualTo(webDriverPageLoadTimeout * 1000);
assertThat(duration).isLessThan((webDriverPageLoadTimeout + pageLoadTimeBuffer) * 1000);
}
}
Loading