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: 4 additions & 0 deletions java/src/org/openqa/selenium/HasDownloads.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public String getName() {
return name;
}

public boolean hasExtension(String extension) {
return extension.startsWith(".") ? name.endsWith(extension) : name.endsWith('.' + extension);
}

public long getCreationTime() {
return creationTime;
}
Expand Down
24 changes: 15 additions & 9 deletions java/test/org/openqa/selenium/CookieImplementationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.openqa.selenium;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.openqa.selenium.testing.drivers.Browser.ALL;
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
Expand Down Expand Up @@ -311,9 +311,7 @@ public void testShouldWalkThePathToDeleteACookie() {
assertThat(driver.manage().getCookieNamed("rodent")).isNull();

Set<Cookie> cookies = driver.manage().getCookies();
assertThat(cookies).hasSize(2);
assertThat(cookies).contains(cookie1);
assertThat(cookies).contains(cookie3);
assertThat(cookies).containsExactlyInAnyOrder(cookie1, cookie3);

driver.manage().deleteAllCookies();
driver.get(domainHelper.getUrlForFirstValidHostname("child/grandchild/grandchildPage.html"));
Expand Down Expand Up @@ -485,14 +483,22 @@ public void testDeleteNotExistedCookie() {

@Test
public void testDeleteEmptyNamedCookie() {
assertThrows(IllegalArgumentException.class, () -> driver.manage().deleteCookieNamed(""));
assertThrows(IllegalArgumentException.class, () -> driver.manage().deleteCookieNamed(" "));
assertThatThrownBy(() -> driver.manage().deleteCookieNamed(""))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Cookie name cannot be empty");
assertThatThrownBy(() -> driver.manage().deleteCookieNamed(" "))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Cookie name cannot be empty");
}

@Test
public void testGetEmptyNamedCookie() {
assertThrows(IllegalArgumentException.class, () -> driver.manage().getCookieNamed(""));
assertThrows(IllegalArgumentException.class, () -> driver.manage().getCookieNamed(" "));
assertThatThrownBy(() -> driver.manage().getCookieNamed(""))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Cookie name cannot be empty");
assertThatThrownBy(() -> driver.manage().getCookieNamed(" "))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Cookie name cannot be empty");
}

@Test
Expand Down Expand Up @@ -554,7 +560,7 @@ private void assertCookieIsPresentWithName(final String key) {
String documentCookie = getDocumentCookieOrNull();
if (documentCookie != null) {
assertThat(documentCookie)
.as("Cookie was not present with name " + key + ", got: " + documentCookie)
.as(() -> "Cookie was not present with name " + key + ", got: " + documentCookie)
.contains(key + "=");
}
}
Expand Down
41 changes: 41 additions & 0 deletions java/test/org/openqa/selenium/DownloadedFileTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.openqa.selenium.HasDownloads.DownloadedFile;

class DownloadedFileTest {
@Test
void hasExtension() {
DownloadedFile file = new DownloadedFile("hello.pdf", 0, 0, 15);
assertThat(file.hasExtension("pdf")).isTrue();
assertThat(file.hasExtension(".pdf")).isTrue();

assertThat(file.hasExtension("df")).isFalse();
assertThat(file.hasExtension("f")).isFalse();
assertThat(file.hasExtension("p")).isFalse();
assertThat(file.hasExtension(".p")).isFalse();

assertThat(file.hasExtension(".txt")).isFalse();
assertThat(file.hasExtension("txt")).isFalse();
assertThat(file.hasExtension("")).isFalse();
}
}
71 changes: 36 additions & 35 deletions java/test/org/openqa/selenium/bidi/input/DefaultWheelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@

package org.openqa.selenium.bidi.input;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
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.FIREFOX;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.openqa.selenium.testing.drivers.Browser.*;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -65,11 +62,11 @@ void shouldScrollToElement() {
appServer.whereIs("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html"));
WebElement iframe = driver.findElement(By.tagName("iframe"));

assertFalse(inViewport(iframe));
assertThat(inViewport(iframe)).isFalse();

input.perform("iframe", getBuilder(driver).scrollToElement(iframe).getSequences());

assertTrue(inViewport(iframe));
assertThat(inViewport(iframe)).isTrue();
}

@Test
Expand All @@ -88,7 +85,7 @@ void shouldScrollFromElementByGivenAmount() {

driver.switchTo().frame(iframe);
WebElement checkbox = driver.findElement(By.name("scroll_checkbox"));
assertTrue(inViewport(checkbox));
assertThat(inViewport(checkbox)).isTrue();
driver.switchTo().window(windowHandle);
}

Expand All @@ -108,26 +105,28 @@ void shouldScrollFromElementByGivenAmountWithOffset() {
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement checkbox = driver.findElement(By.name("scroll_checkbox"));
assertTrue(inViewport(checkbox));
assertThat(inViewport(checkbox)).isTrue();
}

@Test
@NotYetImplemented(EDGE)
@NotYetImplemented(CHROME)
void throwErrorWhenElementOriginIsOutOfViewport() {
assertThrows(
BiDiException.class,
() -> {
driver.get(
appServer.whereIs(
"scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html"));
WebElement footer = driver.findElement(By.tagName("footer"));
WheelInput.ScrollOrigin scrollOrigin = WheelInput.ScrollOrigin.fromElement(footer, 0, 50);

input.perform(
windowHandle,
getBuilder(driver).scrollFromOrigin(scrollOrigin, 0, 200).getSequences());
});
assertThatThrownBy(
() -> {
driver.get(
appServer.whereIs(
"scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html"));
WebElement footer = driver.findElement(By.tagName("footer"));
WheelInput.ScrollOrigin scrollOrigin =
WheelInput.ScrollOrigin.fromElement(footer, 0, 50);

input.perform(
windowHandle,
getBuilder(driver).scrollFromOrigin(scrollOrigin, 0, 200).getSequences());
})
.isInstanceOf(BiDiException.class)
.hasMessageContaining("move target out of bounds");
}

@NeedsFreshDriver
Expand All @@ -148,7 +147,7 @@ void shouldScrollFromViewportByGivenAmount() {

wait.until(driver -> driver.findElement(By.name("nested_scrolling_frame")).isDisplayed());

assertTrue(inViewport(footer));
assertThat(inViewport(footer)).isTrue();
}

@NeedsFreshDriver
Expand All @@ -168,22 +167,24 @@ void shouldScrollFromViewportByGivenAmountFromOrigin() {
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement checkbox = driver.findElement(By.name("scroll_checkbox"));
assertTrue(inViewport(checkbox));
assertThat(inViewport(checkbox)).isTrue();
driver.switchTo().window(windowHandle);
}

@Test
void throwErrorWhenOriginOffsetIsOutOfViewport() {
assertThrows(
BiDiException.class,
() -> {
driver.get(appServer.whereIs("scrolling_tests/frame_with_nested_scrolling_frame.html"));
WheelInput.ScrollOrigin scrollOrigin = WheelInput.ScrollOrigin.fromViewport(-10, -10);

input.perform(
windowHandle,
getBuilder(driver).scrollFromOrigin(scrollOrigin, 0, 200).getSequences());
});
assertThatThrownBy(
() -> {
driver.get(
appServer.whereIs("scrolling_tests/frame_with_nested_scrolling_frame.html"));
WheelInput.ScrollOrigin scrollOrigin = WheelInput.ScrollOrigin.fromViewport(-10, -10);

input.perform(
windowHandle,
getBuilder(driver).scrollFromOrigin(scrollOrigin, 0, 200).getSequences());
})
.isInstanceOf(BiDiException.class)
.hasMessageContaining("move target out of bounds");
}

private boolean inViewport(WebElement element) {
Expand Down
5 changes: 2 additions & 3 deletions java/test/org/openqa/selenium/build/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// under the License.
package org.openqa.selenium.build;

import static org.junit.jupiter.api.Assertions.fail;
import static org.openqa.selenium.Platform.WINDOWS;
import static org.openqa.selenium.build.DevMode.isInDevMode;

Expand Down Expand Up @@ -57,7 +56,7 @@ public void go() {
executeBuild(builder);
} catch (Exception e) {
e.printStackTrace(System.err);
fail("Cannot build");
throw new AssertionError("Cannot build", e);
}
}

Expand All @@ -83,7 +82,7 @@ private void executeBuild(ProcessBuilder builder) throws Exception {
buildWatcher.start();
int exitValue = process.waitFor();
if (exitValue != 0) {
fail("Unable to build artifacts");
throw new AssertionError("Unable to build artifacts");
}
}

Expand Down
3 changes: 1 addition & 2 deletions java/test/org/openqa/selenium/chrome/ChromeOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static org.assertj.core.api.InstanceOfAssertFactories.LIST;
import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
import static org.assertj.core.api.InstanceOfAssertFactories.STRING;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.openqa.selenium.chromium.ChromiumDriverLogLevel.OFF;
import static org.openqa.selenium.chromium.ChromiumDriverLogLevel.SEVERE;
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;
Expand Down Expand Up @@ -397,6 +396,6 @@ void shouldBeAbleToMergeAnAndroidOption() {
var caps = new MutableCapabilities();
var merged = original.merge(caps);

assertEquals(original.asMap(), merged.asMap());
assertThat(merged.asMap()).isEqualTo(original.asMap());
}
}
10 changes: 5 additions & 5 deletions java/test/org/openqa/selenium/devtools/CdpVersionFinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ void shouldReturnAnExactMatchIfFound() {
CdpVersionFinder finder = new CdpVersionFinder(5, ImmutableList.of(v84, v85));

Optional<CdpInfo> info = finder.match(chrome85);
assertThat(info).isEqualTo(Optional.of(v85));
assertThat(info).contains(v85);

info = finder.match(edge84);
assertThat(info).isEqualTo(Optional.of(v84));
assertThat(info).contains(v84);
}

@Test
Expand All @@ -89,7 +89,7 @@ void shouldReturnThePreviousLowestMatchIfNoExactMatchFoundWithinFuzzFactor() {
CdpVersionFinder finder = new CdpVersionFinder(5, ImmutableList.of(v84));

Optional<CdpInfo> info = finder.match(chrome85);
assertThat(info).isEqualTo(Optional.of(v84));
assertThat(info).contains(v84);
}

@Test
Expand All @@ -112,9 +112,9 @@ void canUseBrowserVersionIfNecessary() {
CdpVersionFinder finder = new CdpVersionFinder(5, ImmutableList.of(v84, v85));

Optional<CdpInfo> info = finder.match(chromeVersion);
assertThat(info).isEqualTo(Optional.of(v85));
assertThat(info).contains(v85);

info = finder.match(edgeVersion);
assertThat(info).isEqualTo(Optional.of(v84));
assertThat(info).contains(v84);
}
}
Loading
Loading