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
4 changes: 2 additions & 2 deletions java/test/org/openqa/selenium/ProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

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.openqa.selenium.Proxy.ProxyType.AUTODETECT;
import static org.openqa.selenium.Proxy.ProxyType.DIRECT;
import static org.openqa.selenium.Proxy.ProxyType.MANUAL;
Expand All @@ -28,7 +29,6 @@
import static org.openqa.selenium.remote.CapabilityType.PROXY;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -235,7 +235,7 @@ void manualProxyToJson() {
assertThat(json.get("socksVersion")).isEqualTo(5);
assertThat(json.get("socksUsername")).isEqualTo("test1");
assertThat(json.get("socksPassword")).isEqualTo("test2");
assertThat(json.get("noProxy")).isEqualTo(List.of("localhost", "127.0.0.*"));
assertThat(json.get("noProxy")).asInstanceOf(LIST).containsExactly("localhost", "127.0.0.*");
assertThat(json.entrySet()).hasSize(9);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

package org.openqa.selenium.bidi.browsingcontext;

import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;

import java.util.Base64;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
Expand Down Expand Up @@ -511,8 +513,12 @@ void canPrintPage() {
// Comparing expected PDF is a hard problem.
// As long as we are sending the parameters correctly it should be fine.
// Trusting the browsers to do the right thing.
// Hence, just checking if the response is base64 encoded string.
// Hence, just checking if the response is base64 encoded string looking like PDF.
assertThat(printPage).contains("JVBER");
byte[] pdf = Base64.getDecoder().decode(printPage);
assertThat(pdf)
.containsSequence("%PDF-".getBytes(US_ASCII))
.containsSequence("%%EOF".getBytes(US_ASCII));
}

@Test
Expand Down
37 changes: 18 additions & 19 deletions java/test/org/openqa/selenium/chrome/ChromeOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.io.File;
import java.time.Duration;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -50,6 +49,7 @@
class ChromeOptionsTest {

@Test
@SuppressWarnings("unchecked")
void optionsAsMapShouldBeImmutable() {
Map<String, Object> options = new ChromeOptions().asMap();
assertThatExceptionOfType(UnsupportedOperationException.class)
Expand Down Expand Up @@ -99,12 +99,13 @@ void canAddW3CCompliantOptions() {
assertThat(mappedOptions.get("strictFileInteractability")).isEqualTo(true);
assertThat(mappedOptions.get(ENABLE_DOWNLOADS)).isEqualTo(true);

Map<String, Long> expectedTimeouts = new HashMap<>();
expectedTimeouts.put("implicit", 1000L);
expectedTimeouts.put("pageLoad", 2000L);
expectedTimeouts.put("script", 3000L);

assertThat(expectedTimeouts).isEqualTo(mappedOptions.get("timeouts"));
assertThat(mappedOptions.get("timeouts"))
.asInstanceOf(MAP)
.containsExactlyInAnyOrderEntriesOf(
Map.of(
"implicit", 1000L,
"pageLoad", 2000L,
"script", 3000L));
}

@Test
Expand All @@ -113,15 +114,15 @@ void canAddSequentialTimeouts() {
chromeOptions.setImplicitWaitTimeout(Duration.ofSeconds(1));

Map<String, Object> mappedOptions = chromeOptions.asMap();
Map<String, Long> expectedTimeouts = new HashMap<>();

expectedTimeouts.put("implicit", 1000L);
assertThat(expectedTimeouts).isEqualTo(mappedOptions.get("timeouts"));
assertThat(mappedOptions.get("timeouts"))
.asInstanceOf(MAP)
.containsExactlyInAnyOrderEntriesOf(Map.of("implicit", 1000L));

chromeOptions.setPageLoadTimeout(Duration.ofSeconds(2));
expectedTimeouts.put("pageLoad", 2000L);
Map<String, Object> mappedOptions2 = chromeOptions.asMap();
assertThat(expectedTimeouts).isEqualTo(mappedOptions2.get("timeouts"));
assertThat(mappedOptions2.get("timeouts"))
.asInstanceOf(MAP)
.containsExactlyInAnyOrderEntriesOf(Map.of("implicit", 1000L, "pageLoad", 2000L));
}

@Test
Expand All @@ -130,11 +131,9 @@ void mixAddingTimeoutsCapsAndSetter() {
chromeOptions.setCapability(TIMEOUTS, Map.of("implicit", 1000));
chromeOptions.setPageLoadTimeout(Duration.ofSeconds(2));

Map<String, Number> expectedTimeouts = new HashMap<>();
expectedTimeouts.put("implicit", 1000);
expectedTimeouts.put("pageLoad", 2000L);

assertThat(chromeOptions.asMap().get("timeouts")).isEqualTo(expectedTimeouts);
assertThat(chromeOptions.asMap().get("timeouts"))
.asInstanceOf(MAP)
.containsExactlyInAnyOrderEntriesOf(Map.of("implicit", 1000, "pageLoad", 2000L));
}

@Test
Expand Down Expand Up @@ -395,6 +394,6 @@ void shouldBeAbleToMergeAnAndroidOption() {
var caps = new MutableCapabilities();
var merged = original.merge(caps);

assertThat(merged.asMap()).isEqualTo(original.asMap());
assertThat(merged.asMap()).containsExactlyInAnyOrderEntriesOf(original.asMap());
}
}
16 changes: 9 additions & 7 deletions java/test/org/openqa/selenium/firefox/FirefoxProfileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void convertingToJsonShouldNotPolluteTempDir() throws IOException {
Arrays.stream(sysTemp.list())
.filter(f -> f.endsWith("webdriver-profile"))
.collect(Collectors.toSet());
assertThat(after).isEqualTo(before);
assertThat(after).containsExactlyInAnyOrderElementsOf(before);
}

@Test
Expand All @@ -184,14 +184,16 @@ void shouldConvertItselfIntoAMeaningfulRepresentation() throws IOException {

File dir = Zip.unzipToTempDir(json, "webdriver", "duplicated");

File prefs = new File(dir, "user.js");
assertThat(prefs).exists();
try {
File prefs = new File(dir, "user.js");
assertThat(prefs).exists();

try (Stream<String> lines = Files.lines(prefs.toPath())) {
assertThat(lines).anyMatch(s -> s.contains("i.like.cheese"));
try (Stream<String> lines = Files.lines(prefs.toPath())) {
assertThat(lines).anyMatch(s -> s.contains("i.like.cheese"));
}
} finally {
FileHandler.delete(dir);
}

FileHandler.delete(dir);
}

private List<String> readGeneratedProperties(FirefoxProfile profile) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import java.io.File;
import java.time.Duration;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand All @@ -34,18 +33,23 @@
class GeckoDriverServiceTest {

@Test
void builderPassesTimeoutToDriverService() {
File exe = new File("someFile");
void builderUsesDefaultTimeoutForDriverService() {
Duration defaultTimeout = Duration.ofSeconds(20);
Duration customTimeout = Duration.ofSeconds(60);

GeckoDriverService.Builder builderMock = spy(GeckoDriverService.Builder.class);
builderMock.build();

verify(builderMock).createDriverService(any(), anyInt(), eq(defaultTimeout), any(), any());
}

@Test
void builderPassesTimeoutToDriverService() {
Duration customTimeout = Duration.ofSeconds(60);
GeckoDriverService.Builder builderMock =
spy(GeckoDriverService.Builder.class).withTimeout(customTimeout);

builderMock.withTimeout(customTimeout);
builderMock.build();

verify(builderMock).createDriverService(any(), anyInt(), eq(customTimeout), any(), any());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.Test;

class ConcatenatingConfigTest {
Expand All @@ -38,7 +37,7 @@ void shouldReturnSectionNames() {
"FOO_", "should not show up",
"BAR_FOOD_IS", "cheese sticks"));

assertThat(config.getSectionNames()).isEqualTo(Set.of("cheese", "vegetables"));
assertThat(config.getSectionNames()).containsExactlyInAnyOrder("cheese", "vegetables");
}

@Test
Expand All @@ -54,6 +53,6 @@ void shouldReturnOptionNamesInSection() {
"FOO_", "should not show up",
"BAR_FOOD_IS", "cheese sticks"));

assertThat(config.getOptions("cheese")).isEqualTo(Set.of("current", "selected"));
assertThat(config.getOptions("cheese")).containsExactlyInAnyOrder("current", "selected");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ void shouldSurviveASerializationRoundTrip() {

@Test
void shouldSetIeOptionsCapabilityWhenConstructedFromExistingCapabilities() {
InternetExplorerOptions expected = new InternetExplorerOptions();
expected.setCapability("requireWindowFocus", true);

DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setPlatform(Platform.WINDOWS);
InternetExplorerOptions seen = new InternetExplorerOptions(desiredCapabilities);
seen.setCapability("requireWindowFocus", true);

assertThat(seen.getCapability(IE_OPTIONS)).isEqualTo(expected.getCapability(IE_OPTIONS));
assertThat(seen.getCapability(IE_OPTIONS))
.asInstanceOf(MAP)
.containsExactlyInAnyOrderEntriesOf(Map.of("requireWindowFocus", true));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ void encodesWrappedElementInMoveOrigin() {
new Json().toType(rawJson, ActionSequenceJson.class, PropertySetting.BY_FIELD);

assertThat(json.actions).hasSize(1);
ActionJson firstAction = json.actions.get(0);
assertThat(firstAction.origin).containsEntry(W3C.getEncodedElementKey(), "12345");
assertThat(json.actions.get(0).origin)
.containsExactlyInAnyOrderEntriesOf(Map.of(W3C.getEncodedElementKey(), "12345"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void shouldEncodeWrappedElementInScrollOrigin() {
new Json().toType(rawJson, ActionSequenceJson.class, PropertySetting.BY_FIELD);

assertThat(json.actions).hasSize(1);
ActionJson firstAction = json.actions.get(0);
assertThat(firstAction.origin).containsEntry(W3C.getEncodedElementKey(), "12345");
assertThat(json.actions.get(0).origin)
.containsExactlyInAnyOrderEntriesOf(Map.of(W3C.getEncodedElementKey(), "12345"));
}

@Test
Expand Down
Loading
Loading