Skip to content

Commit 8c93ddf

Browse files
authored
feat: roll driver, deprecated channel enum (#468)
1 parent 502965f commit 8c93ddf

File tree

15 files changed

+265
-83
lines changed

15 files changed

+265
-83
lines changed

playwright/src/main/java/com/microsoft/playwright/Browser.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ class NewContextOptions {
142142
* be scaled down if necessary to fit the specified size.
143143
*/
144144
public RecordVideoSize recordVideoSize;
145+
/**
146+
* Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}. See {@link
147+
* Page#emulateMedia Page.emulateMedia()} for more details. Defaults to {@code "no-preference"}.
148+
*/
149+
public ReducedMotion reducedMotion;
145150
/**
146151
* Emulates consistent window screen size available inside web page via {@code window.screen}. Is only used when the {@code viewport}
147152
* is set.
@@ -261,6 +266,10 @@ public NewContextOptions setRecordVideoSize(RecordVideoSize recordVideoSize) {
261266
this.recordVideoSize = recordVideoSize;
262267
return this;
263268
}
269+
public NewContextOptions setReducedMotion(ReducedMotion reducedMotion) {
270+
this.reducedMotion = reducedMotion;
271+
return this;
272+
}
264273
public NewContextOptions setScreenSize(int width, int height) {
265274
return setScreenSize(new ScreenSize(width, height));
266275
}
@@ -379,6 +388,11 @@ class NewPageOptions {
379388
* be scaled down if necessary to fit the specified size.
380389
*/
381390
public RecordVideoSize recordVideoSize;
391+
/**
392+
* Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}. See {@link
393+
* Page#emulateMedia Page.emulateMedia()} for more details. Defaults to {@code "no-preference"}.
394+
*/
395+
public ReducedMotion reducedMotion;
382396
/**
383397
* Emulates consistent window screen size available inside web page via {@code window.screen}. Is only used when the {@code viewport}
384398
* is set.
@@ -498,6 +512,10 @@ public NewPageOptions setRecordVideoSize(RecordVideoSize recordVideoSize) {
498512
this.recordVideoSize = recordVideoSize;
499513
return this;
500514
}
515+
public NewPageOptions setReducedMotion(ReducedMotion reducedMotion) {
516+
this.reducedMotion = reducedMotion;
517+
return this;
518+
}
501519
public NewPageOptions setScreenSize(int width, int height) {
502520
return setScreenSize(new ScreenSize(width, height));
503521
}

playwright/src/main/java/com/microsoft/playwright/BrowserContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ default void exposeBinding(String name, BindingCallback callback) {
412412
*
413413
* <p> See {@link Page#exposeFunction Page.exposeFunction()} for page-only version.
414414
*
415-
* <p> An example of adding an {@code md5} function to all pages in the context:
415+
* <p> An example of adding a {@code sha256} function to all pages in the context:
416416
* <pre>{@code
417417
* import com.microsoft.playwright.*;
418418
*
@@ -426,11 +426,11 @@ default void exposeBinding(String name, BindingCallback callback) {
426426
* try (Playwright playwright = Playwright.create()) {
427427
* BrowserType webkit = playwright.webkit()
428428
* Browser browser = webkit.launch(new BrowserType.LaunchOptions().setHeadless(false));
429-
* context.exposeFunction("sha1", args -> {
429+
* context.exposeFunction("sha256", args -> {
430430
* String text = (String) args[0];
431431
* MessageDigest crypto;
432432
* try {
433-
* crypto = MessageDigest.getInstance("SHA-1");
433+
* crypto = MessageDigest.getInstance("SHA-256");
434434
* } catch (NoSuchAlgorithmException e) {
435435
* return null;
436436
* }
@@ -440,7 +440,7 @@ default void exposeBinding(String name, BindingCallback callback) {
440440
* Page page = context.newPage();
441441
* page.setContent("<script>\n" +
442442
* " async function onClick() {\n" +
443-
* " document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');\n" +
443+
* " document.querySelector('div').textContent = await window.sha256('PLAYWRIGHT');\n" +
444444
* " }\n" +
445445
* "</script>\n" +
446446
* "<button onclick=\"onClick()\">Click me</button>\n" +

playwright/src/main/java/com/microsoft/playwright/BrowserType.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ class LaunchOptions {
106106
*/
107107
public List<String> args;
108108
/**
109-
* Browser distribution channel. Read more about using <a
109+
* Browser distribution channel. Supported values are "chrome", "chrome-beta", "chrome-dev", "chrome-canary", "msedge",
110+
* "msedge-beta", "msedge-dev", "msedge-canary". Read more about using <a
110111
* href="https://playwright.dev/java/docs/browsers/#google-chrome--microsoft-edge">Google Chrome and Microsoft Edge</a>.
111112
*/
112-
public BrowserChannel channel;
113+
public Object channel;
113114
/**
114115
* Enable Chromium sandboxing. Defaults to {@code false}.
115116
*/
@@ -184,16 +185,21 @@ class LaunchOptions {
184185
/**
185186
* If specified, traces are saved into this directory.
186187
*/
187-
public Path traceDir;
188+
public Path tracesDir;
188189

189190
public LaunchOptions setArgs(List<String> args) {
190191
this.args = args;
191192
return this;
192193
}
194+
@Deprecated
193195
public LaunchOptions setChannel(BrowserChannel channel) {
194196
this.channel = channel;
195197
return this;
196198
}
199+
public LaunchOptions setChannel(String channel) {
200+
this.channel = channel;
201+
return this;
202+
}
197203
public LaunchOptions setChromiumSandbox(boolean chromiumSandbox) {
198204
this.chromiumSandbox = chromiumSandbox;
199205
return this;
@@ -257,8 +263,8 @@ public LaunchOptions setTimeout(double timeout) {
257263
this.timeout = timeout;
258264
return this;
259265
}
260-
public LaunchOptions setTraceDir(Path traceDir) {
261-
this.traceDir = traceDir;
266+
public LaunchOptions setTracesDir(Path tracesDir) {
267+
this.tracesDir = tracesDir;
262268
return this;
263269
}
264270
}
@@ -277,10 +283,11 @@ class LaunchPersistentContextOptions {
277283
*/
278284
public Boolean bypassCSP;
279285
/**
280-
* Browser distribution channel. Read more about using <a
286+
* Browser distribution channel. Supported values are "chrome", "chrome-beta", "chrome-dev", "chrome-canary", "msedge",
287+
* "msedge-beta", "msedge-dev", "msedge-canary". Read more about using <a
281288
* href="https://playwright.dev/java/docs/browsers/#google-chrome--microsoft-edge">Google Chrome and Microsoft Edge</a>.
282289
*/
283-
public BrowserChannel channel;
290+
public Object channel;
284291
/**
285292
* Enable Chromium sandboxing. Defaults to {@code false}.
286293
*/
@@ -408,6 +415,11 @@ class LaunchPersistentContextOptions {
408415
* be scaled down if necessary to fit the specified size.
409416
*/
410417
public RecordVideoSize recordVideoSize;
418+
/**
419+
* Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}. See {@link
420+
* Page#emulateMedia Page.emulateMedia()} for more details. Defaults to {@code "no-preference"}.
421+
*/
422+
public ReducedMotion reducedMotion;
411423
/**
412424
* Emulates consistent window screen size available inside web page via {@code window.screen}. Is only used when the {@code viewport}
413425
* is set.
@@ -431,7 +443,7 @@ class LaunchPersistentContextOptions {
431443
/**
432444
* If specified, traces are saved into this directory.
433445
*/
434-
public Path traceDir;
446+
public Path tracesDir;
435447
/**
436448
* Specific user agent to use in this context.
437449
*/
@@ -453,10 +465,15 @@ public LaunchPersistentContextOptions setBypassCSP(boolean bypassCSP) {
453465
this.bypassCSP = bypassCSP;
454466
return this;
455467
}
468+
@Deprecated
456469
public LaunchPersistentContextOptions setChannel(BrowserChannel channel) {
457470
this.channel = channel;
458471
return this;
459472
}
473+
public LaunchPersistentContextOptions setChannel(String channel) {
474+
this.channel = channel;
475+
return this;
476+
}
460477
public LaunchPersistentContextOptions setChromiumSandbox(boolean chromiumSandbox) {
461478
this.chromiumSandbox = chromiumSandbox;
462479
return this;
@@ -581,6 +598,10 @@ public LaunchPersistentContextOptions setRecordVideoSize(RecordVideoSize recordV
581598
this.recordVideoSize = recordVideoSize;
582599
return this;
583600
}
601+
public LaunchPersistentContextOptions setReducedMotion(ReducedMotion reducedMotion) {
602+
this.reducedMotion = reducedMotion;
603+
return this;
604+
}
584605
public LaunchPersistentContextOptions setScreenSize(int width, int height) {
585606
return setScreenSize(new ScreenSize(width, height));
586607
}
@@ -600,8 +621,8 @@ public LaunchPersistentContextOptions setTimezoneId(String timezoneId) {
600621
this.timezoneId = timezoneId;
601622
return this;
602623
}
603-
public LaunchPersistentContextOptions setTraceDir(Path traceDir) {
604-
this.traceDir = traceDir;
624+
public LaunchPersistentContextOptions setTracesDir(Path tracesDir) {
625+
this.tracesDir = tracesDir;
605626
return this;
606627
}
607628
public LaunchPersistentContextOptions setUserAgent(String userAgent) {

playwright/src/main/java/com/microsoft/playwright/Page.java

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ public interface Page extends AutoCloseable {
258258
*
259259
* <p> <strong>NOTE:</strong> HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete
260260
* with {@link Page#onRequestFinished Page.onRequestFinished()} event and not with {@link Page#onRequestFailed
261-
* Page.onRequestFailed()}.
261+
* Page.onRequestFailed()}. A request will only be considered failed when the client cannot get an HTTP response from the
262+
* server, e.g. due to network error net::ERR_FAILED.
262263
*/
263264
void onRequestFailed(Consumer<Request> handler);
264265
/**
@@ -626,6 +627,11 @@ class EmulateMediaOptions {
626627
* disables CSS media emulation.
627628
*/
628629
public Optional<Media> media;
630+
/**
631+
* Emulates {@code "prefers-reduced-motion"} media feature, supported values are {@code "reduce"}, {@code "no-preference"}. Passing {@code null}
632+
* disables reduced motion emulation.
633+
*/
634+
public Optional<ReducedMotion> reducedMotion;
629635

630636
public EmulateMediaOptions setColorScheme(ColorScheme colorScheme) {
631637
this.colorScheme = Optional.ofNullable(colorScheme);
@@ -635,6 +641,10 @@ public EmulateMediaOptions setMedia(Media media) {
635641
this.media = Optional.ofNullable(media);
636642
return this;
637643
}
644+
public EmulateMediaOptions setReducedMotion(ReducedMotion reducedMotion) {
645+
this.reducedMotion = Optional.ofNullable(reducedMotion);
646+
return this;
647+
}
638648
}
639649
class ExposeBindingOptions {
640650
/**
@@ -1603,6 +1613,26 @@ public WaitForRequestOptions setTimeout(double timeout) {
16031613
return this;
16041614
}
16051615
}
1616+
class WaitForRequestFinishedOptions {
1617+
/**
1618+
* Receives the {@code Request} object and resolves to truthy value when the waiting should resolve.
1619+
*/
1620+
public Predicate<Request> predicate;
1621+
/**
1622+
* Maximum time to wait for in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
1623+
* value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()}.
1624+
*/
1625+
public Double timeout;
1626+
1627+
public WaitForRequestFinishedOptions setPredicate(Predicate<Request> predicate) {
1628+
this.predicate = predicate;
1629+
return this;
1630+
}
1631+
public WaitForRequestFinishedOptions setTimeout(double timeout) {
1632+
this.timeout = timeout;
1633+
return this;
1634+
}
1635+
}
16061636
class WaitForResponseOptions {
16071637
/**
16081638
* Maximum wait time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable the timeout. The default value can be
@@ -2508,7 +2538,7 @@ default void exposeBinding(String name, BindingCallback callback) {
25082538
*
25092539
* <p> <strong>NOTE:</strong> Functions installed via {@link Page#exposeFunction Page.exposeFunction()} survive navigations.
25102540
*
2511-
* <p> An example of adding an {@code sha1} function to the page:
2541+
* <p> An example of adding a {@code sha256} function to the page:
25122542
* <pre>{@code
25132543
* import com.microsoft.playwright.*;
25142544
*
@@ -2523,11 +2553,11 @@ default void exposeBinding(String name, BindingCallback callback) {
25232553
* BrowserType webkit = playwright.webkit();
25242554
* Browser browser = webkit.launch({ headless: false });
25252555
* Page page = browser.newPage();
2526-
* page.exposeFunction("sha1", args -> {
2556+
* page.exposeFunction("sha256", args -> {
25272557
* String text = (String) args[0];
25282558
* MessageDigest crypto;
25292559
* try {
2530-
* crypto = MessageDigest.getInstance("SHA-1");
2560+
* crypto = MessageDigest.getInstance("SHA-256");
25312561
* } catch (NoSuchAlgorithmException e) {
25322562
* return null;
25332563
* }
@@ -2536,7 +2566,7 @@ default void exposeBinding(String name, BindingCallback callback) {
25362566
* });
25372567
* page.setContent("<script>\n" +
25382568
* " async function onClick() {\n" +
2539-
* " document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');\n" +
2569+
* " document.querySelector('div').textContent = await window.sha256('PLAYWRIGHT');\n" +
25402570
* " }\n" +
25412571
* "</script>\n" +
25422572
* "<button onclick=\"onClick()\">Click me</button>\n" +
@@ -4095,7 +4125,7 @@ default Page waitForClose(Runnable callback) {
40954125
/**
40964126
* Performs action and waits for a {@code ConsoleMessage} to be logged by in the page. If predicate is provided, it passes
40974127
* {@code ConsoleMessage} value into the {@code predicate} function and waits for {@code predicate(message)} to return a truthy value. Will
4098-
* throw an error if the page is closed before the console event is fired.
4128+
* throw an error if the page is closed before the {@link Page#onConsole Page.onConsole()} event is fired.
40994129
*
41004130
* @param callback Callback that performs the action triggering the event.
41014131
*/
@@ -4105,7 +4135,7 @@ default ConsoleMessage waitForConsoleMessage(Runnable callback) {
41054135
/**
41064136
* Performs action and waits for a {@code ConsoleMessage} to be logged by in the page. If predicate is provided, it passes
41074137
* {@code ConsoleMessage} value into the {@code predicate} function and waits for {@code predicate(message)} to return a truthy value. Will
4108-
* throw an error if the page is closed before the console event is fired.
4138+
* throw an error if the page is closed before the {@link Page#onConsole Page.onConsole()} event is fired.
41094139
*
41104140
* @param callback Callback that performs the action triggering the event.
41114141
*/
@@ -4401,7 +4431,7 @@ default Page waitForPopup(Runnable callback) {
44014431
* Waits for the matching request and returns it. See <a
44024432
* href="https://playwright.dev/java/docs/events/#waiting-for-event">waiting for event</a> for more details about events.
44034433
* <pre>{@code
4404-
* // Waits for the next response with the specified url
4434+
* // Waits for the next request with the specified url
44054435
* Request request = page.waitForRequest("https://example.com/resource", () -> {
44064436
* // Triggers the request
44074437
* page.click("button.triggers-request");
@@ -4424,7 +4454,7 @@ default Request waitForRequest(String urlOrPredicate, Runnable callback) {
44244454
* Waits for the matching request and returns it. See <a
44254455
* href="https://playwright.dev/java/docs/events/#waiting-for-event">waiting for event</a> for more details about events.
44264456
* <pre>{@code
4427-
* // Waits for the next response with the specified url
4457+
* // Waits for the next request with the specified url
44284458
* Request request = page.waitForRequest("https://example.com/resource", () -> {
44294459
* // Triggers the request
44304460
* page.click("button.triggers-request");
@@ -4445,7 +4475,7 @@ default Request waitForRequest(String urlOrPredicate, Runnable callback) {
44454475
* Waits for the matching request and returns it. See <a
44464476
* href="https://playwright.dev/java/docs/events/#waiting-for-event">waiting for event</a> for more details about events.
44474477
* <pre>{@code
4448-
* // Waits for the next response with the specified url
4478+
* // Waits for the next request with the specified url
44494479
* Request request = page.waitForRequest("https://example.com/resource", () -> {
44504480
* // Triggers the request
44514481
* page.click("button.triggers-request");
@@ -4468,7 +4498,7 @@ default Request waitForRequest(Pattern urlOrPredicate, Runnable callback) {
44684498
* Waits for the matching request and returns it. See <a
44694499
* href="https://playwright.dev/java/docs/events/#waiting-for-event">waiting for event</a> for more details about events.
44704500
* <pre>{@code
4471-
* // Waits for the next response with the specified url
4501+
* // Waits for the next request with the specified url
44724502
* Request request = page.waitForRequest("https://example.com/resource", () -> {
44734503
* // Triggers the request
44744504
* page.click("button.triggers-request");
@@ -4489,7 +4519,7 @@ default Request waitForRequest(Pattern urlOrPredicate, Runnable callback) {
44894519
* Waits for the matching request and returns it. See <a
44904520
* href="https://playwright.dev/java/docs/events/#waiting-for-event">waiting for event</a> for more details about events.
44914521
* <pre>{@code
4492-
* // Waits for the next response with the specified url
4522+
* // Waits for the next request with the specified url
44934523
* Request request = page.waitForRequest("https://example.com/resource", () -> {
44944524
* // Triggers the request
44954525
* page.click("button.triggers-request");
@@ -4512,7 +4542,7 @@ default Request waitForRequest(Predicate<Request> urlOrPredicate, Runnable callb
45124542
* Waits for the matching request and returns it. See <a
45134543
* href="https://playwright.dev/java/docs/events/#waiting-for-event">waiting for event</a> for more details about events.
45144544
* <pre>{@code
4515-
* // Waits for the next response with the specified url
4545+
* // Waits for the next request with the specified url
45164546
* Request request = page.waitForRequest("https://example.com/resource", () -> {
45174547
* // Triggers the request
45184548
* page.click("button.triggers-request");
@@ -4529,6 +4559,24 @@ default Request waitForRequest(Predicate<Request> urlOrPredicate, Runnable callb
45294559
* @param callback Callback that performs the action triggering the event.
45304560
*/
45314561
Request waitForRequest(Predicate<Request> urlOrPredicate, WaitForRequestOptions options, Runnable callback);
4562+
/**
4563+
* Performs action and waits for a {@code Request} to finish loading. If predicate is provided, it passes {@code Request} value into
4564+
* the {@code predicate} function and waits for {@code predicate(request)} to return a truthy value. Will throw an error if the page is
4565+
* closed before the {@link Page#onRequestFinished Page.onRequestFinished()} event is fired.
4566+
*
4567+
* @param callback Callback that performs the action triggering the event.
4568+
*/
4569+
default Request waitForRequestFinished(Runnable callback) {
4570+
return waitForRequestFinished(null, callback);
4571+
}
4572+
/**
4573+
* Performs action and waits for a {@code Request} to finish loading. If predicate is provided, it passes {@code Request} value into
4574+
* the {@code predicate} function and waits for {@code predicate(request)} to return a truthy value. Will throw an error if the page is
4575+
* closed before the {@link Page#onRequestFinished Page.onRequestFinished()} event is fired.
4576+
*
4577+
* @param callback Callback that performs the action triggering the event.
4578+
*/
4579+
Request waitForRequestFinished(WaitForRequestFinishedOptions options, Runnable callback);
45324580
/**
45334581
* Returns the matched response. See <a href="https://playwright.dev/java/docs/events/#waiting-for-event">waiting for
45344582
* event</a> for more details about events.

0 commit comments

Comments
 (0)