Skip to content

Commit 3ab3531

Browse files
authored
Merge branch 'trunk' into pinned-browser-updates
2 parents f0ac000 + 4a0d05e commit 3ab3531

21 files changed

+232
-334
lines changed

java/src/org/openqa/selenium/By.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public static By cssSelector(String cssSelector) {
121121
public WebElement findElement(SearchContext context) {
122122
List<WebElement> allElements = findElements(context);
123123
if (allElements == null || allElements.isEmpty()) {
124-
throw new NoSuchElementException("Cannot locate an element using " + toString());
124+
throw new NoSuchElementException("Cannot locate an element using " + this);
125125
}
126126
return allElements.get(0);
127127
}

java/src/org/openqa/selenium/JavascriptExecutor.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.openqa.selenium;
1919

20-
import java.util.Collections;
2120
import java.util.Set;
2221
import java.util.stream.Collectors;
2322
import org.jspecify.annotations.NullMarked;
@@ -177,10 +176,9 @@ default void unpin(ScriptKey key) {
177176
* @return The {@link ScriptKey}s of all currently pinned scripts.
178177
*/
179178
default Set<ScriptKey> getPinnedScripts() {
180-
return Collections.unmodifiableSet(
181-
UnpinnedScriptKey.getPinnedScripts(this).stream()
182-
.map(key -> (ScriptKey) key)
183-
.collect(Collectors.toSet()));
179+
return UnpinnedScriptKey.getPinnedScripts(this).stream()
180+
.map(key -> (ScriptKey) key)
181+
.collect(Collectors.toUnmodifiableSet());
184182
}
185183

186184
/**

java/src/org/openqa/selenium/WebElement.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ public interface WebElement extends SearchContext, TakesScreenshot {
165165
*
166166
* @param name The name of the attribute.
167167
* @return The attribute/property's current value or null if the value is not set.
168+
* @deprecated This method is deprecated. Use {@link #getDomProperty(String)} or {@link
169+
* #getDomAttribute(String)} for more precise attribute retrieval.
168170
*/
171+
@Deprecated
169172
@Nullable String getAttribute(String name);
170173

171174
/**

java/src/org/openqa/selenium/support/pagefactory/ByAll.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public WebElement findElement(SearchContext context) {
5454
return elements.get(0);
5555
}
5656
}
57-
throw new NoSuchElementException("Cannot locate an element using " + toString());
57+
throw new NoSuchElementException("Cannot locate an element using " + this);
5858
}
5959

6060
@Override

java/src/org/openqa/selenium/support/pagefactory/ByChained.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public ByChained(By... bys) {
5252
public WebElement findElement(SearchContext context) {
5353
List<WebElement> elements = findElements(context);
5454
if (elements.isEmpty())
55-
throw new NoSuchElementException("Cannot locate an element using " + toString());
55+
throw new NoSuchElementException("Cannot locate an element using " + this);
5656
return elements.get(0);
5757
}
5858

java/test/org/openqa/selenium/bidi/BiDiTest.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@
1818
package org.openqa.selenium.bidi;
1919

2020
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
21-
import static org.openqa.selenium.testing.Safely.safelyCall;
2221
import static org.openqa.selenium.testing.drivers.Browser.EDGE;
2322

2423
import java.util.concurrent.CompletableFuture;
2524
import java.util.concurrent.ExecutionException;
2625
import java.util.concurrent.TimeUnit;
2726
import java.util.concurrent.TimeoutException;
28-
import org.junit.jupiter.api.AfterEach;
29-
import org.junit.jupiter.api.BeforeEach;
3027
import org.junit.jupiter.api.Test;
3128
import org.openqa.selenium.By;
3229
import org.openqa.selenium.bidi.browsingcontext.BrowsingContext;
@@ -35,24 +32,17 @@
3532
import org.openqa.selenium.bidi.log.JavascriptLogEntry;
3633
import org.openqa.selenium.bidi.log.LogLevel;
3734
import org.openqa.selenium.bidi.module.LogInspector;
38-
import org.openqa.selenium.environment.webserver.AppServer;
39-
import org.openqa.selenium.environment.webserver.NettyAppServer;
4035
import org.openqa.selenium.testing.JupiterTestBase;
36+
import org.openqa.selenium.testing.NeedsFreshDriver;
4137
import org.openqa.selenium.testing.NotYetImplemented;
4238

4339
class BiDiTest extends JupiterTestBase {
4440

4541
String page;
46-
private AppServer server;
47-
48-
@BeforeEach
49-
public void setUp() {
50-
server = new NettyAppServer();
51-
server.start();
52-
}
5342

5443
@Test
5544
@NotYetImplemented(EDGE)
45+
@NeedsFreshDriver
5646
void canNavigateAndListenToErrors()
5747
throws ExecutionException, InterruptedException, TimeoutException {
5848
try (org.openqa.selenium.bidi.module.LogInspector logInspector = new LogInspector(driver)) {
@@ -61,7 +51,7 @@ void canNavigateAndListenToErrors()
6151

6252
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
6353

64-
page = server.whereIs("/bidi/logEntryAdded.html");
54+
page = appServer.whereIs("/bidi/logEntryAdded.html");
6555
NavigationResult info = browsingContext.navigate(page, ReadinessState.COMPLETE);
6656

6757
// If navigation was successful, we expect both the url and navigation id to be set
@@ -78,12 +68,4 @@ void canNavigateAndListenToErrors()
7868
assertThat(logEntry.getLevel()).isEqualTo(LogLevel.ERROR);
7969
}
8070
}
81-
82-
@AfterEach
83-
public void quitDriver() {
84-
if (driver != null) {
85-
driver.quit();
86-
}
87-
safelyCall(server::stop);
88-
}
8971
}

java/test/org/openqa/selenium/bidi/browser/BrowserCommandsTest.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,25 @@
1818
package org.openqa.selenium.bidi.browser;
1919

2020
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
21-
import static org.openqa.selenium.testing.Safely.safelyCall;
22-
import static org.openqa.selenium.testing.drivers.Browser.*;
2321

2422
import java.util.List;
25-
import org.junit.jupiter.api.AfterEach;
2623
import org.junit.jupiter.api.BeforeEach;
2724
import org.junit.jupiter.api.Test;
2825
import org.openqa.selenium.bidi.module.Browser;
29-
import org.openqa.selenium.environment.webserver.AppServer;
30-
import org.openqa.selenium.environment.webserver.NettyAppServer;
3126
import org.openqa.selenium.testing.JupiterTestBase;
27+
import org.openqa.selenium.testing.NeedsFreshDriver;
3228

3329
class BrowserCommandsTest extends JupiterTestBase {
3430

35-
private AppServer server;
3631
private Browser browser;
3732

3833
@BeforeEach
3934
public void setUp() {
40-
server = new NettyAppServer();
41-
server.start();
4235
browser = new Browser(driver);
4336
}
4437

4538
@Test
39+
@NeedsFreshDriver
4640
void canCreateAUserContext() {
4741
String userContext = browser.createUserContext();
4842

@@ -52,6 +46,7 @@ void canCreateAUserContext() {
5246
}
5347

5448
@Test
49+
@NeedsFreshDriver
5550
void canGetUserContexts() {
5651
String userContext1 = browser.createUserContext();
5752
String userContext2 = browser.createUserContext();
@@ -64,6 +59,7 @@ void canGetUserContexts() {
6459
}
6560

6661
@Test
62+
@NeedsFreshDriver
6763
void canRemoveUserContext() {
6864
String userContext1 = browser.createUserContext();
6965
String userContext2 = browser.createUserContext();
@@ -79,12 +75,4 @@ void canRemoveUserContext() {
7975

8076
browser.removeUserContext(userContext1);
8177
}
82-
83-
@AfterEach
84-
public void quitDriver() {
85-
if (driver != null) {
86-
driver.quit();
87-
}
88-
safelyCall(server::stop);
89-
}
9078
}

java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInspectorTest.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,22 @@
1818
package org.openqa.selenium.bidi.browsingcontext;
1919

2020
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
21-
import static org.openqa.selenium.testing.Safely.safelyCall;
22-
import static org.openqa.selenium.testing.drivers.Browser.*;
2321

2422
import java.util.concurrent.CompletableFuture;
2523
import java.util.concurrent.ExecutionException;
2624
import java.util.concurrent.TimeUnit;
2725
import java.util.concurrent.TimeoutException;
28-
import org.junit.jupiter.api.AfterEach;
29-
import org.junit.jupiter.api.BeforeEach;
3026
import org.junit.jupiter.api.Test;
3127
import org.openqa.selenium.By;
3228
import org.openqa.selenium.WindowType;
3329
import org.openqa.selenium.bidi.module.BrowsingContextInspector;
34-
import org.openqa.selenium.environment.webserver.AppServer;
35-
import org.openqa.selenium.environment.webserver.NettyAppServer;
3630
import org.openqa.selenium.testing.JupiterTestBase;
31+
import org.openqa.selenium.testing.NeedsFreshDriver;
3732

3833
class BrowsingContextInspectorTest extends JupiterTestBase {
3934

40-
private AppServer server;
41-
42-
@BeforeEach
43-
public void setUp() {
44-
server = new NettyAppServer();
45-
server.start();
46-
}
47-
4835
@Test
36+
@NeedsFreshDriver
4937
void canListenToWindowBrowsingContextCreatedEvent()
5038
throws ExecutionException, InterruptedException, TimeoutException {
5139
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
@@ -66,6 +54,7 @@ void canListenToWindowBrowsingContextCreatedEvent()
6654
}
6755

6856
@Test
57+
@NeedsFreshDriver
6958
void canListenToBrowsingContextDestroyedEvent()
7059
throws ExecutionException, InterruptedException, TimeoutException {
7160
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
@@ -87,6 +76,7 @@ void canListenToBrowsingContextDestroyedEvent()
8776
}
8877

8978
@Test
79+
@NeedsFreshDriver
9080
void canListenToTabBrowsingContextCreatedEvent()
9181
throws ExecutionException, InterruptedException, TimeoutException {
9282
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
@@ -106,14 +96,15 @@ void canListenToTabBrowsingContextCreatedEvent()
10696
}
10797

10898
@Test
99+
@NeedsFreshDriver
109100
void canListenToDomContentLoadedEvent()
110101
throws ExecutionException, InterruptedException, TimeoutException {
111102
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
112103
CompletableFuture<NavigationInfo> future = new CompletableFuture<>();
113104
inspector.onDomContentLoaded(future::complete);
114105

115106
BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle());
116-
context.navigate(server.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);
107+
context.navigate(appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);
117108

118109
NavigationInfo navigationInfo = future.get(5, TimeUnit.SECONDS);
119110
assertThat(navigationInfo.getBrowsingContextId()).isEqualTo(context.getId());
@@ -122,14 +113,15 @@ void canListenToDomContentLoadedEvent()
122113
}
123114

124115
@Test
116+
@NeedsFreshDriver
125117
void canListenToBrowsingContextLoadedEvent()
126118
throws ExecutionException, InterruptedException, TimeoutException {
127119
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
128120
CompletableFuture<NavigationInfo> future = new CompletableFuture<>();
129121
inspector.onBrowsingContextLoaded(future::complete);
130122

131123
BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle());
132-
context.navigate(server.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);
124+
context.navigate(appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);
133125

134126
NavigationInfo navigationInfo = future.get(5, TimeUnit.SECONDS);
135127
assertThat(navigationInfo.getBrowsingContextId()).isEqualTo(context.getId());
@@ -138,14 +130,15 @@ void canListenToBrowsingContextLoadedEvent()
138130
}
139131

140132
@Test
133+
@NeedsFreshDriver
141134
void canListenToNavigationStartedEvent()
142135
throws ExecutionException, InterruptedException, TimeoutException {
143136
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
144137
CompletableFuture<NavigationInfo> future = new CompletableFuture<>();
145138
inspector.onNavigationStarted(future::complete);
146139

147140
BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle());
148-
context.navigate(server.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);
141+
context.navigate(appServer.whereIs("/bidi/logEntryAdded.html"), ReadinessState.COMPLETE);
149142

150143
NavigationInfo navigationInfo = future.get(5, TimeUnit.SECONDS);
151144
assertThat(navigationInfo.getBrowsingContextId()).isEqualTo(context.getId());
@@ -154,18 +147,19 @@ void canListenToNavigationStartedEvent()
154147
}
155148

156149
@Test
150+
@NeedsFreshDriver
157151
void canListenToFragmentNavigatedEvent()
158152
throws ExecutionException, InterruptedException, TimeoutException {
159153
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
160154
CompletableFuture<NavigationInfo> future = new CompletableFuture<>();
161155

162156
BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle());
163-
context.navigate(server.whereIs("/linked_image.html"), ReadinessState.COMPLETE);
157+
context.navigate(appServer.whereIs("/linked_image.html"), ReadinessState.COMPLETE);
164158

165159
inspector.onFragmentNavigated(future::complete);
166160

167161
context.navigate(
168-
server.whereIs("/linked_image.html#linkToAnchorOnThisPage"), ReadinessState.COMPLETE);
162+
appServer.whereIs("/linked_image.html#linkToAnchorOnThisPage"), ReadinessState.COMPLETE);
169163

170164
NavigationInfo navigationInfo = future.get(5, TimeUnit.SECONDS);
171165
assertThat(navigationInfo.getBrowsingContextId()).isEqualTo(context.getId());
@@ -174,6 +168,7 @@ void canListenToFragmentNavigatedEvent()
174168
}
175169

176170
@Test
171+
@NeedsFreshDriver
177172
void canListenToUserPromptOpenedEvent()
178173
throws ExecutionException, InterruptedException, TimeoutException {
179174
try (BrowsingContextInspector inspector = new BrowsingContextInspector(driver)) {
@@ -182,7 +177,7 @@ void canListenToUserPromptOpenedEvent()
182177
BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle());
183178
inspector.onUserPromptOpened(future::complete);
184179

185-
driver.get(server.whereIs("/alerts.html"));
180+
driver.get(appServer.whereIs("/alerts.html"));
186181

187182
driver.findElement(By.id("alert")).click();
188183

@@ -193,6 +188,7 @@ void canListenToUserPromptOpenedEvent()
193188
}
194189

195190
@Test
191+
@NeedsFreshDriver
196192
// TODO: This test is flaky for comparing the browsing context id for Chrome and Edge. Fix flaky
197193
// test.
198194
void canListenToUserPromptClosedEvent()
@@ -203,7 +199,7 @@ void canListenToUserPromptClosedEvent()
203199
BrowsingContext context = new BrowsingContext(driver, driver.getWindowHandle());
204200
inspector.onUserPromptClosed(future::complete);
205201

206-
driver.get(server.whereIs("/alerts.html"));
202+
driver.get(appServer.whereIs("/alerts.html"));
207203

208204
driver.findElement(By.id("prompt")).click();
209205

@@ -216,12 +212,4 @@ void canListenToUserPromptClosedEvent()
216212
assertThat(userPromptClosed.getAccepted()).isTrue();
217213
}
218214
}
219-
220-
@AfterEach
221-
public void quitDriver() {
222-
if (driver != null) {
223-
driver.quit();
224-
}
225-
safelyCall(server::stop);
226-
}
227215
}

0 commit comments

Comments
 (0)