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
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/Architecture.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ public static Architecture extractFromSysProperty(String arch) {
}
}

throw new UnsupportedOperationException("Unknown architecture: " + arch);
throw new UnsupportedOperationException("Unknown architecture: \"" + arch + '"');
}
}
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/bidi/script/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ java_library(
"//java/src/org/openqa/selenium/json",
"//java/src/org/openqa/selenium/remote/http",
artifact("com.google.auto.service:auto-service-annotations"),
artifact("org.jspecify:jspecify"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public Map<String, Object> toJson() {

return unmodifiableMap(toReturn);
}

@Override
public String toString() {
return String.format("%s{type:%s, value:%s}", getClass().getSimpleName(), type, value);
}
}
27 changes: 24 additions & 3 deletions java/src/org/openqa/selenium/bidi/script/RegExpValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@
package org.openqa.selenium.bidi.script;

import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.json.JsonInput;

public class RegExpValue extends LocalValue {

private final String pattern;
private String flags;

@Nullable private final String flags;

public RegExpValue(String pattern) {
this.pattern = pattern;
this(pattern, null);
}

public RegExpValue(String pattern, String flags) {
public RegExpValue(String pattern, @Nullable String flags) {
this.pattern = pattern;
this.flags = flags;
}
Expand Down Expand Up @@ -78,7 +81,25 @@ public String getPattern() {
return pattern;
}

@Nullable
public String getFlags() {
return flags;
}

@Override
public boolean equals(Object object) {
if (!(object instanceof RegExpValue)) return false;
RegExpValue other = (RegExpValue) object;
return Objects.equals(pattern, other.pattern) && Objects.equals(flags, other.flags);
}

@Override
public int hashCode() {
return Objects.hash(pattern, flags);
}

@Override
public String toString() {
return String.format("%s{pattern:%s, flags:%s}", getClass().getSimpleName(), pattern, flags);
}
}
6 changes: 6 additions & 0 deletions java/src/org/openqa/selenium/bidi/script/RemoteValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,10 @@ private static Object deserializeValue(Object value, Type type) {

return finalValue;
}

@Override
public String toString() {
return String.format(
"%s{type:%s, value:%s}", getClass().getSimpleName(), type, value.orElse(null));
}
}
13 changes: 5 additions & 8 deletions java/src/org/openqa/selenium/print/PageMargin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.selenium.print;

import java.util.HashMap;
import java.util.Map;
import org.jspecify.annotations.NullMarked;

Expand Down Expand Up @@ -59,12 +58,10 @@ public double getRight() {
}

public Map<String, Object> toMap() {
final Map<String, Object> options = new HashMap<>(7);
options.put("top", getTop());
options.put("bottom", getBottom());
options.put("left", getLeft());
options.put("right", getRight());

return options;
return Map.of(
"top", getTop(),
"bottom", getBottom(),
"left", getLeft(),
"right", getRight());
}
}
6 changes: 3 additions & 3 deletions java/test/org/openqa/selenium/ArchitectureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ void determineArchARM() {
void determineArchEmpty() {
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> Architecture.extractFromSysProperty(""))
.withMessageContaining("Unknown architecture");
.withMessage("Unknown architecture: \"\"");
}

@Test
void determineArchBogus() {
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> Architecture.extractFromSysProperty("hoobaflooba"))
.withMessageContaining("Unknown architecture");
.withMessage("Unknown architecture: \"hoobaflooba\"");
}

@Test
Expand All @@ -139,7 +139,7 @@ void determineArchMixedCasing() {
@Test
void dataModelIs32Or64BitOnCurrentArchitecture() {
int model = Architecture.getCurrent().getDataModel();
assertThat(model == 32 || model == 64).isTrue();
assertThat(model).isIn(32, 64);
}

@Test
Expand Down
8 changes: 3 additions & 5 deletions java/test/org/openqa/selenium/CookieImplementationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ public void testGetAllCookies() {
assertCookieIsNotPresentWithName(key1);
assertCookieIsNotPresentWithName(key2);

Set<Cookie> cookies = driver.manage().getCookies();
int countBefore = cookies.size();
int countBefore = driver.manage().getCookies().size();

Cookie one = new Cookie.Builder(key1, "value").build();
Cookie two = new Cookie.Builder(key2, "value").build();
Expand All @@ -118,11 +117,10 @@ public void testGetAllCookies() {
driver.manage().addCookie(two);

openAnotherPage();
cookies = driver.manage().getCookies();
Set<Cookie> cookies = driver.manage().getCookies();
assertThat(cookies).hasSize(countBefore + 2);

assertThat(cookies.contains(one)).isTrue();
assertThat(cookies.contains(two)).isTrue();
assertThat(cookies).contains(one, two);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/ElementAttributeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void testCanReturnATextApproximationOfTheStyleAttribute() {

String style = driver.findElement(By.id("red-item")).getAttribute("style");

assertThat(style.toLowerCase().contains("background-color")).isTrue();
assertThat(style).containsIgnoringCase("background-color");
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/ElementDomAttributeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void testCanReturnATextApproximationOfTheStyleAttribute() {

String style = driver.findElement(By.id("red-item")).getDomAttribute("style");

assertThat(style.toLowerCase().contains("background-color")).isTrue();
assertThat(style).containsIgnoringCase("background-color");
}

@Test
Expand Down
72 changes: 35 additions & 37 deletions java/test/org/openqa/selenium/ExecutingAsyncJavascriptTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
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 org.assertj.core.api.InstanceOfAssertFactories.LIST;
import static org.assertj.core.api.InstanceOfAssertFactories.type;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
import static org.openqa.selenium.testing.drivers.Browser.EDGE;
Expand All @@ -28,7 +30,6 @@
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;

import java.time.Duration;
import java.util.Iterator;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -53,28 +54,25 @@ public void setUp() {
@NotYetImplemented(value = FIREFOX, reason = "Default to 5s")
@NotYetImplemented(value = SAFARI, reason = "Default to 5s")
public void shouldSetAndGetScriptTimeout() {
Duration timeout = driver.manage().timeouts().getScriptTimeout();
assertThat(timeout).hasMillis(30000);
assertThat(driver.manage().timeouts().getScriptTimeout()).hasSeconds(30);

driver.manage().timeouts().scriptTimeout(Duration.ofMillis(3000));
Duration timeout2 = driver.manage().timeouts().getScriptTimeout();
assertThat(timeout2).hasMillis(3000);

assertThat(driver.manage().timeouts().getScriptTimeout()).hasSeconds(3);
}

@Test
void shouldNotTimeoutIfCallbackInvokedImmediately() {
driver.get(pages.ajaxyPage);
Object result = executor.executeAsyncScript("arguments[arguments.length - 1](123);");
assertThat(result).isInstanceOf(Number.class);
assertThat(((Number) result).intValue()).isEqualTo(123);
Object result = executor.executeAsyncScript("arguments[arguments.length - 1]('123');");
assertThat(result).isEqualTo("123");
}

@Test
void shouldBeAbleToReturnJavascriptPrimitivesFromAsyncScripts_NeitherNullNorUndefined() {
driver.get(pages.ajaxyPage);
assertThat(
((Number) executor.executeAsyncScript("arguments[arguments.length - 1](123);"))
.longValue())
.isEqualTo(123);
assertThat(executor.executeAsyncScript("arguments[arguments.length - 1](123456789012345);"))
.isEqualTo(123456789012345L);
assertThat(executor.executeAsyncScript("arguments[arguments.length - 1]('abc');"))
.isEqualTo("abc");
assertThat((Boolean) executor.executeAsyncScript("arguments[arguments.length - 1](false);"))
Expand All @@ -95,17 +93,15 @@ void shouldBeAbleToReturnAnArrayLiteralFromAnAsyncScript() {
driver.get(pages.ajaxyPage);

Object result = executor.executeAsyncScript("arguments[arguments.length - 1]([]);");
assertThat(result).isNotNull().isInstanceOf(List.class);
assertThat(((List<?>) result)).isEmpty();
assertThat(result).asInstanceOf(LIST).isEmpty();
}

@Test
void shouldBeAbleToReturnAnArrayObjectFromAnAsyncScript() {
driver.get(pages.ajaxyPage);

Object result = executor.executeAsyncScript("arguments[arguments.length - 1](new Array());");
assertThat(result).isNotNull().isInstanceOf(List.class);
assertThat(((List<?>) result)).isEmpty();
assertThat(result).asInstanceOf(LIST).isEmpty();
}

@Test
Expand All @@ -114,27 +110,21 @@ void shouldBeAbleToReturnArraysOfPrimitivesFromAsyncScripts() {

Object result =
executor.executeAsyncScript(
"arguments[arguments.length - 1]([null, 123, 'abc', true, false]);");

assertThat(result).isNotNull();
assertThat(result).isInstanceOf(List.class);

Iterator<?> results = ((List<?>) result).iterator();
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();
"arguments[arguments.length - 1]([null, 123456789012345, 'abc', true, false]);");

assertThat(result)
.asInstanceOf(LIST)
.containsExactly(null, 123456789012345L, "abc", true, false);
}

@Test
void shouldBeAbleToReturnWebElementsFromAsyncScripts() {
driver.get(pages.ajaxyPage);

Object result = executor.executeAsyncScript("arguments[arguments.length - 1](document.body);");
assertThat(result).isInstanceOf(WebElement.class);
assertThat(((WebElement) result).getTagName()).isEqualToIgnoringCase("body");
assertThat(result)
.asInstanceOf(type(WebElement.class))
.satisfies(webElement -> assertThat(webElement.getTagName()).isEqualToIgnoringCase("body"));
}

@Test
Expand All @@ -146,13 +136,21 @@ void shouldBeAbleToReturnArraysOfWebElementsFromAsyncScripts() {
executor.executeAsyncScript(
"arguments[arguments.length - 1]([document.body, document.body]);");
assertThat(result).isNotNull().isInstanceOf(List.class);

List<?> list = (List<?>) result;
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));
assertThat(result)
.asInstanceOf(LIST)
.hasSize(2)
.satisfies(
list -> {
assertThat(list.get(0))
.asInstanceOf(type(WebElement.class))
.satisfies(
element -> assertThat(element.getTagName()).isEqualToIgnoringCase("body"));
assertThat(list.get(1))
.asInstanceOf(type(WebElement.class))
.satisfies(
element -> assertThat(element.getTagName()).isEqualToIgnoringCase("body"));
assertThat(list.get(1)).isEqualTo(list.get(0));
});
}

@Test
Expand Down
3 changes: 1 addition & 2 deletions java/test/org/openqa/selenium/ExecutingJavascriptTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ void testShouldBeAbleToExecuteSimpleJavascriptAndReturnABoolean() {

Object result = executeScript("return true;");

assertThat(result).isInstanceOf(Boolean.class);
assertThat((Boolean) result).isTrue();
assertThat(result).isInstanceOf(Boolean.class).isEqualTo(true);
}

@SuppressWarnings("unchecked")
Expand Down
4 changes: 2 additions & 2 deletions java/test/org/openqa/selenium/FormHandlingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void testShouldBeAbleToAlterTheContentsOfAFileUploadInputElement() throws IOExce
uploadElement.sendKeys(file.getAbsolutePath());

String uploadPath = uploadElement.getAttribute("value");
assertThat(uploadPath.endsWith(file.getName())).isTrue();
assertThat(uploadPath).endsWith(file.getName());
}

@Test
Expand All @@ -169,7 +169,7 @@ void testShouldBeAbleToSendKeysToAFileUploadInputElementInAnXhtmlDocument() thro
uploadElement.sendKeys(file.getAbsolutePath());

String uploadPath = uploadElement.getAttribute("value");
assertThat(uploadPath.endsWith(file.getName())).isTrue();
assertThat(uploadPath).endsWith(file.getName());
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/OutputTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void testBytes() {
@Test
void testFiles() {
File tmpFile = OutputType.FILE.convertFromBase64Png(TEST_BASE64);
assertThat(tmpFile.exists()).isTrue();
assertThat(tmpFile).exists();
assertThat(tmpFile.length()).isEqualTo(TEST_BYTES.length);
assertThat(tmpFile.delete()).isTrue();
}
Expand Down
6 changes: 3 additions & 3 deletions java/test/org/openqa/selenium/PrintPageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void canPrintPage() {
PrintOptions printOptions = new PrintOptions();

Pdf pdf = printer.print(printOptions);
assertThat(pdf.getContent().contains(MAGIC_STRING)).isTrue();
assertThat(pdf.getContent()).contains(MAGIC_STRING);
}

// TODO: Skipped for Chrome because it needs to run headless, a workaround for this is needed.
Expand All @@ -57,7 +57,7 @@ public void canPrintTwoPages() {
printOptions.setPageRanges("1-2");

Pdf pdf = printer.print(printOptions);
assertThat(pdf.getContent().contains(MAGIC_STRING)).isTrue();
assertThat(pdf.getContent()).contains(MAGIC_STRING);
}

// TODO: Skipped for Chrome because it needs to run headless, a workaround for this is needed.
Expand All @@ -72,6 +72,6 @@ public void canPrintWithValidParams() {
printOptions.setPageSize(pageSize);

Pdf pdf = printer.print(printOptions);
assertThat(pdf.getContent().contains(MAGIC_STRING)).isTrue();
assertThat(pdf.getContent()).contains(MAGIC_STRING);
}
}
Loading
Loading