Skip to content

Commit c255e20

Browse files
authored
Update to Selenium 4.39.0 +semver:feature (#156)
* Update to Selenium 4.39.0 +semver:feature Update DevTools references to use V143 in tests * Update tests, update w3c schools locators for multiselect form, update geolocation override test Update DevTools references to use V143 in the library and V142 in tests Update commons-lang3 reference
1 parent d71d3aa commit c255e20

12 files changed

Lines changed: 140 additions & 47 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@
7070
<dependency>
7171
<groupId>com.github.aquality-automation</groupId>
7272
<artifactId>aquality-selenium-core</artifactId>
73-
<version>4.10.0</version>
73+
<version>4.11.1</version>
7474
</dependency>
7575
<dependency>
7676
<groupId>org.apache.commons</groupId>
7777
<artifactId>commons-lang3</artifactId>
78-
<version>3.18.0</version>
78+
<version>3.20.0</version>
7979
</dependency>
8080
<dependency>
8181
<groupId>com.fasterxml.jackson.core</groupId>

src/main/java/aquality/selenium/browser/devtools/DevToolsHandling.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import org.openqa.selenium.devtools.DevTools;
1010
import org.openqa.selenium.devtools.Event;
1111
import org.openqa.selenium.devtools.HasDevTools;
12-
import org.openqa.selenium.devtools.v142.performance.Performance;
13-
import org.openqa.selenium.devtools.v142.performance.model.Metric;
12+
import org.openqa.selenium.devtools.v143.performance.Performance;
13+
import org.openqa.selenium.devtools.v143.performance.model.Metric;
1414

1515
import java.util.List;
1616
import java.util.Map;

src/main/java/aquality/selenium/browser/devtools/EmulationHandling.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import org.apache.commons.lang3.StringUtils;
44
import org.openqa.selenium.devtools.Command;
5-
import org.openqa.selenium.devtools.v142.dom.model.RGBA;
6-
import org.openqa.selenium.devtools.v142.emulation.Emulation;
7-
import org.openqa.selenium.devtools.v142.emulation.model.MediaFeature;
8-
import org.openqa.selenium.devtools.v142.emulation.model.ScreenOrientation;
5+
import org.openqa.selenium.devtools.v143.dom.model.RGBA;
6+
import org.openqa.selenium.devtools.v143.emulation.Emulation;
7+
import org.openqa.selenium.devtools.v143.emulation.model.MediaFeature;
8+
import org.openqa.selenium.devtools.v143.emulation.model.ScreenOrientation;
99

1010
import java.util.Collections;
1111
import java.util.List;

src/main/java/aquality/selenium/browser/devtools/JavaScriptHandling.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import org.openqa.selenium.devtools.idealized.Javascript;
1313
import org.openqa.selenium.devtools.idealized.ScriptId;
1414
import org.openqa.selenium.devtools.idealized.target.model.SessionID;
15-
import org.openqa.selenium.devtools.v142.page.Page;
16-
import org.openqa.selenium.devtools.v142.page.model.ScriptIdentifier;
17-
import org.openqa.selenium.devtools.v142.runtime.Runtime;
15+
import org.openqa.selenium.devtools.v143.page.Page;
16+
import org.openqa.selenium.devtools.v143.page.model.ScriptIdentifier;
17+
import org.openqa.selenium.devtools.v143.runtime.Runtime;
1818
import org.openqa.selenium.logging.EventType;
1919
import org.openqa.selenium.logging.HasLogEvents;
2020
import org.openqa.selenium.remote.Augmenter;

src/main/java/aquality/selenium/browser/devtools/NetworkHandling.java

Lines changed: 82 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.openqa.selenium.UsernameAndPassword;
99
import org.openqa.selenium.devtools.NetworkInterceptor;
1010
import org.openqa.selenium.devtools.idealized.Network;
11-
import org.openqa.selenium.devtools.v142.network.model.*;
11+
import org.openqa.selenium.devtools.v143.network.model.*;
1212
import org.openqa.selenium.remote.http.*;
1313

1414
import java.net.URI;
@@ -22,11 +22,11 @@
2222

2323
import static aquality.selenium.browser.AqualityServices.getBrowser;
2424
import static aquality.selenium.logging.LocalizedLoggerUtility.logByLevel;
25-
import static org.openqa.selenium.devtools.v142.network.Network.*;
25+
import static org.openqa.selenium.devtools.v143.network.Network.*;
2626

2727
/**
2828
* DevTools commands for version-independent network interception.
29-
* For more information, see {@link org.openqa.selenium.devtools.v142.network.Network} and {@link Network}.
29+
* For more information, see {@link org.openqa.selenium.devtools.v143.network.Network} and {@link Network}.
3030
*/
3131
public class NetworkHandling {
3232
public static final String LOC_NETWORK_INTERCEPTOR_START = "loc.browser.network.interceptor.start";
@@ -62,6 +62,7 @@ public void stopMonitoring() {
6262

6363
/**
6464
* Overrides the values of user agent.
65+
*
6566
* @param userAgent User agent to use.
6667
*/
6768
public void setUserAgent(String userAgent) {
@@ -71,6 +72,7 @@ public void setUserAgent(String userAgent) {
7172

7273
/**
7374
* Overrides the values of user agent.
75+
*
7476
* @param userAgent User agent to use.
7577
*/
7678
public void setUserAgent(Network.UserAgent userAgent) {
@@ -80,7 +82,8 @@ public void setUserAgent(Network.UserAgent userAgent) {
8082

8183
/**
8284
* Add basic authentication handler.
83-
* @param whenThisMatches URI matcher.
85+
*
86+
* @param whenThisMatches URI matcher.
8487
* @param useTheseCredentials parameters, such as URI matcher and credentials.
8588
*/
8689
public void addAuthHandler(Predicate<URI> whenThisMatches, Supplier<Credentials> useTheseCredentials) {
@@ -90,6 +93,7 @@ public void addAuthHandler(Predicate<URI> whenThisMatches, Supplier<Credentials>
9093

9194
/**
9295
* Add basic authentication handler.
96+
*
9397
* @param hostPart part of the host name for URI matcher.
9498
* @param username authentication username.
9599
* @param password authentication password.
@@ -117,6 +121,7 @@ public void resetNetworkFilter() {
117121

118122
/**
119123
* Starts traffic interception with specified filter.
124+
*
120125
* @param filter HTTP filter.
121126
*/
122127
public void interceptTrafficWith(Filter filter) {
@@ -126,6 +131,7 @@ public void interceptTrafficWith(Filter filter) {
126131

127132
/**
128133
* Adds listener to network request sent event.
134+
*
129135
* @param listener a listener to add.
130136
*/
131137
public void addRequestListener(Consumer<RequestWillBeSent> listener) {
@@ -136,6 +142,7 @@ public void addRequestListener(Consumer<RequestWillBeSent> listener) {
136142

137143
/**
138144
* Adds listener to network response received event.
145+
*
139146
* @param listener a listener to add.
140147
*/
141148
public void addResponseListener(Consumer<ResponseReceived> listener) {
@@ -200,7 +207,7 @@ private Consumer<ResponseReceived> getResponseLogger(HttpExchangeLoggingOptions
200207
formatHeaders(response.getHeaders()));
201208
}
202209
if (loggingOptions.getResponseBody().isEnabled()) {
203-
String responseBody = tools.sendCommand(org.openqa.selenium.devtools.v142.network.Network.getResponseBody(requestId)).getBody();
210+
String responseBody = tools.sendCommand(getResponseBody(requestId)).getBody();
204211
if (StringUtils.isNotEmpty(responseBody)) {
205212
logByLevel(loggingOptions.getResponseBody().getLogLevel(),
206213
"loc.browser.network.event.responsereceived.log.body",
@@ -212,6 +219,7 @@ private Consumer<ResponseReceived> getResponseLogger(HttpExchangeLoggingOptions
212219

213220
/**
214221
* Enables HTTP Request/Response logging.
222+
*
215223
* @param loggingOptions logging parameters {@link HttpExchangeLoggingOptions}.
216224
*/
217225
public void enableHttpExchangeLogging(HttpExchangeLoggingOptions loggingOptions) {
@@ -221,6 +229,7 @@ public void enableHttpExchangeLogging(HttpExchangeLoggingOptions loggingOptions)
221229

222230
/**
223231
* Starts network interceptor.
232+
*
224233
* @param httpHandler HTTP handler.
225234
* @return an instance of {@link NetworkInterceptor}.
226235
*/
@@ -231,6 +240,7 @@ public NetworkInterceptor startNetworkInterceptor(HttpHandler httpHandler) {
231240

232241
/**
233242
* Starts network interceptor.
243+
*
234244
* @param filter network filter.
235245
* @return an instance of {@link NetworkInterceptor}.
236246
*/
@@ -241,6 +251,7 @@ public NetworkInterceptor startNetworkInterceptor(Filter filter) {
241251

242252
/**
243253
* Starts network interceptor.
254+
*
244255
* @param routable a filter with matcher.
245256
* @return an instance of {@link NetworkInterceptor}.
246257
*/
@@ -251,8 +262,9 @@ public NetworkInterceptor startNetworkInterceptor(Routable routable) {
251262

252263
/**
253264
* Starts network interceptor.
265+
*
254266
* @param requestMatcher predicate to match the request.
255-
* @param handler handler for matched requests.
267+
* @param handler handler for matched requests.
256268
* @return an instance of {@link NetworkInterceptor}.
257269
*/
258270
public NetworkInterceptor startNetworkInterceptor(Predicate<HttpRequest> requestMatcher, Supplier<HttpHandler> handler) {
@@ -261,6 +273,7 @@ public NetworkInterceptor startNetworkInterceptor(Predicate<HttpRequest> request
261273

262274
/**
263275
* Intercepts any request with predefined response.
276+
*
264277
* @param response HTTP response.
265278
* @return an instance of {@link NetworkInterceptor}.
266279
*/
@@ -270,7 +283,8 @@ public NetworkInterceptor interceptAllRequests(HttpResponse response) {
270283

271284
/**
272285
* Adds request transformer.
273-
* @param requestMatcher predicate to match the request.
286+
*
287+
* @param requestMatcher predicate to match the request.
274288
* @param requestTransformer function to transform the request.
275289
* @return an instance of {@link NetworkInterceptor}.
276290
*/
@@ -281,6 +295,7 @@ public NetworkInterceptor addRequestTransformer(Predicate<HttpRequest> requestMa
281295

282296
/**
283297
* Adds request handler.
298+
*
284299
* @param requestMatcher predicate to match the request.
285300
* @param requestHandler handler for matched requests.
286301
* @return an instance of {@link NetworkInterceptor}.
@@ -292,7 +307,8 @@ public NetworkInterceptor addRequestHandler(Predicate<HttpRequest> requestMatche
292307

293308
/**
294309
* Adds response handler.
295-
* @param responseMatcher predicate to match the response.
310+
*
311+
* @param responseMatcher predicate to match the response.
296312
* @param responseTransformer function to transform the response.
297313
* @return an instance of {@link NetworkInterceptor}.
298314
*/
@@ -309,35 +325,83 @@ public NetworkInterceptor addResponseHandler(Predicate<HttpResponse> responseMat
309325
* Currently, Selenium supports only a single network interceptor. Any new Network interceptor will override the previous one.
310326
* And on {@link NetworkInterceptor#close()} the NetworkInterceptor class just calls the {@link Network#resetNetworkFilter()}, so it's enough to call it.
311327
* If multiple network interceptors at the same time would be allowed, we may want to store all
312-
* {@link NetworkInterceptor} classes to call {@link NetworkInterceptor#close()} for each.
328+
* {@link NetworkInterceptor} classes to call {@link NetworkInterceptor#close()} for each.
313329
*/
314330
public void clearNetworkInterceptor() {
315331
resetNetworkFilter();
316332
}
317333

318334
/**
319335
* Activates emulation of network conditions.
320-
* @param offline True to emulate internet disconnection.
321-
* @param latency Minimum latency from request sent to response headers received (ms).
336+
*
337+
* @param offline True to emulate internet disconnection.
338+
* @param latency Minimum latency from request sent to response headers received (ms).
322339
* @param downloadThroughput Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.
323-
* @param uploadThroughput Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.
340+
* @param uploadThroughput Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.
341+
* @deprecated This command is deprecated in favor of the {@link #emulateConditionsByRule(Boolean, List)}
342+
* and {@link #overrideState} commands, which can be used together to the same effect.
324343
*/
344+
@Deprecated
325345
public void emulateConditions(Boolean offline, Number latency, Number downloadThroughput, Number uploadThroughput) {
326346
tools.sendCommand(enable(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
327347
tools.sendCommand(emulateNetworkConditions(offline, latency, downloadThroughput, uploadThroughput, Optional.empty(),
328348
Optional.empty(), Optional.empty(), Optional.empty()));
329349
}
330350

351+
/**
352+
* Activates emulation of network conditions for individual requests using URL match patterns.
353+
* Unlike the deprecated Network.emulateNetworkConditions this method does not affect `navigator` state.
354+
* Use Network.overrideNetworkState to explicitly modify `navigator` behavior.
355+
*
356+
* @param offline True to emulate internet disconnection.
357+
* @param matchedNetworkConditions List of network conditions to apply.
358+
*/
359+
public void emulateConditionsByRule(Boolean offline, List<NetworkConditions> matchedNetworkConditions) {
360+
tools.sendCommand(enable(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
361+
tools.sendCommand(emulateNetworkConditionsByRule(offline, matchedNetworkConditions));
362+
}
363+
364+
/**
365+
* Override the state of navigator.onLine and navigator.connection.
366+
*
367+
* @param offline True to emulate internet disconnection.
368+
* @param latency Minimum latency from request sent to response headers received (ms).
369+
* @param downloadThroughput Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.
370+
* @param uploadThroughput Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.
371+
*/
372+
public void overrideState(Boolean offline, Number latency, Number downloadThroughput, Number uploadThroughput) {
373+
tools.sendCommand(enable(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
374+
tools.sendCommand(overrideNetworkState(offline, latency, downloadThroughput, uploadThroughput, Optional.empty()));
375+
}
376+
377+
/**
378+
* Override the state of navigator.onLine and navigator.connection.
379+
*
380+
* @param offline True to emulate internet disconnection.
381+
* @param latency Minimum latency from request sent to response headers received (ms).
382+
* @param downloadThroughput Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.
383+
* @param uploadThroughput Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.
384+
* @param connectionType Connection type if known.
385+
*/
386+
public void overrideState(Boolean offline, Number latency, Number downloadThroughput, Number uploadThroughput, ConnectionType connectionType) {
387+
tools.sendCommand(enable(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
388+
tools.sendCommand(overrideNetworkState(offline, latency, downloadThroughput, uploadThroughput, Optional.of(connectionType)));
389+
}
390+
331391
/**
332392
* Activates emulation of network conditions.
333-
* @param offline True to emulate internet disconnection.
334-
* @param latency Minimum latency from request sent to response headers received (ms).
393+
*
394+
* @param offline True to emulate internet disconnection.
395+
* @param latency Minimum latency from request sent to response headers received (ms).
335396
* @param downloadThroughput Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.
336-
* @param uploadThroughput Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.
337-
* @param connectionType Connection type if known.
338-
* Possible values: "none", "cellular2g", "cellular3g", "cellular4g", "bluetooth", "ethernet",
339-
* "wifi", "wimax", "other".
397+
* @param uploadThroughput Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.
398+
* @param connectionType Connection type if known.
399+
* Possible values: "none", "cellular2g", "cellular3g", "cellular4g", "bluetooth", "ethernet",
400+
* "wifi", "wimax", "other".
401+
* @deprecated This command is deprecated in favor of the {@link #emulateConditionsByRule(Boolean, List)}
402+
* and {@link #overrideState} commands, which can be used together to the same effect.
340403
*/
404+
@Deprecated
341405
public void emulateConditions(Boolean offline, Number latency, Number downloadThroughput, Number uploadThroughput, String connectionType) {
342406
tools.sendCommand(enable(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
343407
tools.sendCommand(emulateNetworkConditions(offline, latency, downloadThroughput, uploadThroughput,

src/test/java/automationpractice/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ private Constants(){
55
}
66

77
public static final String URL_AUTOMATIONPRACTICE = "http://automationpractice.com/index.php";
8-
public static final String URL_MYLOCATIONORG = "https://my-location.org";
8+
public static final String URL_MYLOCATIONORG = "https://whereamirightnow.org";
99
}

src/test/java/forms/MyLocationForm.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
public class MyLocationForm extends Form {
99

10-
private final ILabel lblLatitude = getElementFactory().getLabel(By.id("latitude"), "Latitude");
11-
private final ILabel lblLongitude = getElementFactory().getLabel(By.id("longitude"), "Longitude");
12-
private final IButton btnConsent = getElementFactory().getButton(By.xpath("//button[@aria-label='Consent']"), "Consent");
10+
private final ILabel lblLatitude = getElementFactory().getLabel(By.xpath("//*[@id='latitude'] | (//td[contains(text(), 'Latitude')]/following-sibling::td)[1]"), "Latitude");
11+
private final ILabel lblLongitude = getElementFactory().getLabel(By.xpath("//*[@id='longitude'] | (//td[contains(text(), 'Longitude')]/following-sibling::td)[1]"), "Longitude");
12+
private final IButton btnConsent = getElementFactory().getButton(By.xpath("//button[@aria-label='Consent' or contains(@class,'fc-cta-consent')]"), "Consent");
1313

1414
public MyLocationForm() {
15-
super(By.xpath("//h1[contains(text(),'My Location')]"), "My Location");
15+
super(By.xpath("//*[contains(text(),'Location')]"), "My Location");
1616
}
1717

1818
public double getLatitude() {

src/test/java/tests/usecases/devtools/DeviceEmulationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import aquality.selenium.browser.AqualityServices;
44
import aquality.selenium.browser.devtools.EmulationHandling;
55
import com.google.common.collect.ImmutableMap;
6-
import org.openqa.selenium.devtools.v141.emulation.Emulation;
7-
import org.openqa.selenium.devtools.v141.emulation.model.DisplayFeature;
6+
import org.openqa.selenium.devtools.v142.emulation.Emulation;
7+
import org.openqa.selenium.devtools.v142.emulation.model.DisplayFeature;
88
import org.testng.Assert;
99
import org.testng.annotations.BeforeMethod;
1010
import org.testng.annotations.Test;

0 commit comments

Comments
 (0)