diff --git a/java/test/org/openqa/selenium/environment/BUILD.bazel b/java/test/org/openqa/selenium/environment/BUILD.bazel index 753930f4560bb..c6d67de7cdb63 100644 --- a/java/test/org/openqa/selenium/environment/BUILD.bazel +++ b/java/test/org/openqa/selenium/environment/BUILD.bazel @@ -116,6 +116,7 @@ java_test_suite( deps = [ ":environment", ":test-base", + artifact("org.assertj:assertj-core"), artifact("org.junit.jupiter:junit-jupiter-api"), artifact("org.jspecify:jspecify"), ] + firefox["deps"] + JUNIT5_DEPS, diff --git a/java/test/org/openqa/selenium/environment/webserver/Page.java b/java/test/org/openqa/selenium/environment/webserver/Page.java index ecbd8e99912a6..dc2f572ff9ec9 100644 --- a/java/test/org/openqa/selenium/environment/webserver/Page.java +++ b/java/test/org/openqa/selenium/environment/webserver/Page.java @@ -27,6 +27,7 @@ public class Page { private String[] bodyParts = {}; private @Nullable String onLoad; private @Nullable String onBeforeUnload; + private boolean doctype = false; public Page withTitle(String title) { this.title = title; @@ -58,7 +59,44 @@ public Page withOnBeforeUnload(String onBeforeUnload) { return this; } + /** + * Opt-in to a standards-mode document shape: a leading {@code } and the {@code + * ", + "", + "", + body, + String.join("\n", bodyParts), + "", + ""); + } + return String.join( "\n", "", @@ -71,10 +109,7 @@ public String toString() { "", - String.format( - "", - onLoad == null ? "" : String.format("onload='%s'", onLoad), - onBeforeUnload == null ? "" : String.format("onbeforeunload='%s'", onBeforeUnload)), + body, String.join("\n", bodyParts), "", ""); diff --git a/java/test/org/openqa/selenium/environment/webserver/PageTest.java b/java/test/org/openqa/selenium/environment/webserver/PageTest.java new file mode 100644 index 0000000000000..0b3977c927df3 --- /dev/null +++ b/java/test/org/openqa/selenium/environment/webserver/PageTest.java @@ -0,0 +1,65 @@ +// 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.environment.webserver; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class PageTest { + + @Test + void defaultToStringHasNoDoctypeAndMatchesLegacyShape() { + String page = + new Page().withTitle("Legacy").withScripts("var a = 1;").withStyles("body { }").toString(); + + // No doctype: default output stays in quirks mode for backward compatibility. + assertThat(page).doesNotContain("/")).isLessThan(page.indexOf("")); + assertThat(page.indexOf("")).isLessThan(page.indexOf("")); + } +} diff --git a/java/test/org/openqa/selenium/support/locators/RelativeLocatorTest.java b/java/test/org/openqa/selenium/support/locators/RelativeLocatorTest.java index edd383fa04555..2e72bcfdccc8f 100644 --- a/java/test/org/openqa/selenium/support/locators/RelativeLocatorTest.java +++ b/java/test/org/openqa/selenium/support/locators/RelativeLocatorTest.java @@ -367,4 +367,42 @@ void nearLocatorShouldNotFindFarElements() { .isThrownBy(() -> driver.findElement(with(By.id("rect4")).near(rect))) .withMessageContaining("Cannot locate an element using"); } + + @Test + void shouldFindCellThatSharesACollapsedBorderWithTheAnchorCell() { + String url = + appServer.create( + new Page() + .withDoctype() + .withTitle("Collapsed Borders") + .withStyles( + " table {\n" + + " border-collapse: collapse;\n" + + " table-layout: fixed;\n" + + " width: 450px;\n" + + " }\n" + + " td, th {\n" + + " border: 1px solid black;\n" + + " box-sizing: border-box;\n" + + " width: 150px;\n" + + " height: 40px;\n" + + " padding: 4px;\n" + + " }") + .withBody( + "\n" + + " Contact\n" + + " Maria Anders\n" + + " Francisco ChangMexico\n" + + "
CompanyCountry
Alfreds FutterkisteGermany
Centro comercial Moctezuma
")); + driver.get(url); + + WebElement cell = + driver.findElement(with(tagName("td")).toRightOf(By.id("alfreds")).below(By.id("contact"))); + + assertThat(cell.getAttribute("id")).isEqualTo("maria"); + } }