Skip to content

Commit

Permalink
cherry-pick(release-1.9): rename with* to set* for java (#5739)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Mar 5, 2021
1 parent 097f7c3 commit 07438f6
Show file tree
Hide file tree
Showing 20 changed files with 341 additions and 124 deletions.
6 changes: 3 additions & 3 deletions docs/src/api/class-browsercontext.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType webkit = playwright.webkit()
Browser browser = webkit.launch(new BrowserType.LaunchOptions().withHeadless(false));
Browser browser = webkit.launch(new BrowserType.LaunchOptions().setHeadless(false));
BrowserContext context = browser.newContext();
context.exposeBinding("pageURL", (source, args) -> source.page().url());
Page page = context.newPage();
Expand Down Expand Up @@ -396,7 +396,7 @@ context.exposeBinding("clicked", (source, args) -> {
ElementHandle element = (ElementHandle) args[0];
System.out.println(element.textContent());
return null;
}, new BrowserContext.ExposeBindingOptions().withHandle(true));
}, new BrowserContext.ExposeBindingOptions().setHandle(true));
page.setContent("" +
"<script>\n" +
" document.addEventListener('click', event => window.clicked(event.target));\n" +
Expand Down Expand Up @@ -495,7 +495,7 @@ public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType webkit = playwright.webkit()
Browser browser = webkit.launch(new BrowserType.LaunchOptions().withHeadless(false));
Browser browser = webkit.launch(new BrowserType.LaunchOptions().setHeadless(false));
context.exposeFunction("sha1", args -> {
String text = (String) args[0];
MessageDigest crypto;
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/class-browsertype.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const browser = await chromium.launch({ // Or 'firefox' or 'webkit'.
```java
// Or "firefox" or "webkit".
Browser browser = chromium.launch(new BrowserType.LaunchOptions()
.withIgnoreDefaultArgs(Arrays.asList("--mute-audio")));
.setIgnoreDefaultArgs(Arrays.asList("--mute-audio")));
```

```python async
Expand Down
6 changes: 3 additions & 3 deletions docs/src/api/class-elementhandle.md
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ handle.selectOption(['red', 'green', 'blue']);
// single selection matching the value
handle.selectOption("blue");
// single selection matching the label
handle.selectOption(new SelectOption().withLabel("Blue"));
handle.selectOption(new SelectOption().setLabel("Blue"));
// multiple selection
handle.selectOption(new String[] {"red", "green", "blue"});
```
Expand Down Expand Up @@ -707,7 +707,7 @@ await elementHandle.type('World', {delay: 100}); // Types slower, like a user

```java
elementHandle.type("Hello"); // Types instantly
elementHandle.type("World", new ElementHandle.TypeOptions().withDelay(100)); // Types slower, like a user
elementHandle.type("World", new ElementHandle.TypeOptions().setDelay(100)); // Types slower, like a user
```

```python async
Expand Down Expand Up @@ -829,7 +829,7 @@ page.setContent("<div><span></span></div>");
ElementHandle div = page.querySelector("div");
// Waiting for the "span" selector relative to the div.
ElementHandle span = div.waitForSelector("span", new ElementHandle.WaitForSelectorOptions()
.withState(WaitForSelectorState.ATTACHED));
.setState(WaitForSelectorState.ATTACHED));
```

```python async
Expand Down
4 changes: 2 additions & 2 deletions docs/src/api/class-frame.md
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ frame.selectOption('select#colors', 'red', 'green', 'blue');
// single selection matching the value
frame.selectOption("select#colors", "blue");
// single selection matching both the value and the label
frame.selectOption("select#colors", new SelectOption().withLabel("Blue"));
frame.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
frame.selectOption("select#colors", new String[] {"red", "green", "blue"});
```
Expand Down Expand Up @@ -1047,7 +1047,7 @@ await frame.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a
// Types instantly
frame.type("#mytextarea", "Hello");
// Types slower, like a user
frame.type("#mytextarea", "World", new Frame.TypeOptions().withDelay(100));
frame.type("#mytextarea", "World", new Frame.TypeOptions().setDelay(100));
```

```python async
Expand Down
8 changes: 4 additions & 4 deletions docs/src/api/class-keyboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ await browser.close();
Page page = browser.newPage();
page.navigate("https://keycode.info");
page.keyboard().press("A");
page.screenshot(new Page.ScreenshotOptions().withPath(Paths.get("A.png"));
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("A.png"));
page.keyboard().press("ArrowLeft");
page.screenshot(new Page.ScreenshotOptions().withPath(Paths.get("ArrowLeft.png")));
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("ArrowLeft.png")));
page.keyboard().press("Shift+O");
page.screenshot(new Page.ScreenshotOptions().withPath(Paths.get("O.png")));
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("O.png")));
browser.close();
```

Expand Down Expand Up @@ -269,7 +269,7 @@ await page.keyboard.type('World', {delay: 100}); // Types slower, like a user
// Types instantly
page.keyboard().type("Hello");
// Types slower, like a user
page.keyboard().type("World", new Keyboard.TypeOptions().withDelay(100));
page.keyboard().type("World", new Keyboard.TypeOptions().setDelay(100));
```

```python async
Expand Down
22 changes: 11 additions & 11 deletions docs/src/api/class-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Example {
BrowserContext context = browser.newContext();
Page page = context.newPage();
page.navigate("https://example.com");
page.screenshot(new Page.ScreenshotOptions().withPath(Paths.get("screenshot.png")));
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot.png")));
browser.close();
}
}
Expand Down Expand Up @@ -744,7 +744,7 @@ page.evaluate("() => matchMedia('screen').matches");
page.evaluate("() => matchMedia('print').matches");
// → false

page.emulateMedia(new Page.EmulateMediaOptions().withMedia(Media.PRINT));
page.emulateMedia(new Page.EmulateMediaOptions().setMedia(Media.PRINT));
page.evaluate("() => matchMedia('screen').matches");
// → false
page.evaluate("() => matchMedia('print').matches");
Expand Down Expand Up @@ -806,7 +806,7 @@ await page.evaluate(() => matchMedia('(prefers-color-scheme: no-preference)').ma
```

```java
page.emulateMedia(new Page.EmulateMediaOptions().withColorScheme(ColorScheme.DARK));
page.emulateMedia(new Page.EmulateMediaOptions().setColorScheme(ColorScheme.DARK));
page.evaluate("() => matchMedia('(prefers-color-scheme: dark)').matches");
// → true
page.evaluate("() => matchMedia('(prefers-color-scheme: light)').matches");
Expand Down Expand Up @@ -1250,7 +1250,7 @@ page.exposeBinding("clicked", (source, args) -> {
ElementHandle element = (ElementHandle) args[0];
System.out.println(element.textContent());
return null;
}, new Page.ExposeBindingOptions().withHandle(true));
}, new Page.ExposeBindingOptions().setHandle(true));
page.setContent("" +
"<script>\n" +
" document.addEventListener('click', event => window.clicked(event.target));\n" +
Expand Down Expand Up @@ -1786,8 +1786,8 @@ await page.pdf({path: 'page.pdf'});
```java
// Generates a PDF with "screen" media type.
page.emulateMedia(new Page.EmulateMediaOptions().withMedia(Media.SCREEN));
page.pdf(new Page.PdfOptions().withPath(Paths.get("page.pdf")));
page.emulateMedia(new Page.EmulateMediaOptions().setMedia(Media.SCREEN));
page.pdf(new Page.PdfOptions().setPath(Paths.get("page.pdf")));
```
```python async
Expand Down Expand Up @@ -1975,11 +1975,11 @@ await browser.close();
Page page = browser.newPage();
page.navigate("https://keycode.info");
page.press("body", "A");
page.screenshot(new Page.ScreenshotOptions().withPath(Paths.get("A.png")));
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("A.png")));
page.press("body", "ArrowLeft");
page.screenshot(new Page.ScreenshotOptions().withPath(Paths.get("ArrowLeft.png" )));
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("ArrowLeft.png" )));
page.press("body", "Shift+O");
page.screenshot(new Page.ScreenshotOptions().withPath(Paths.get("O.png" )));
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("O.png" )));
```

```python async
Expand Down Expand Up @@ -2224,7 +2224,7 @@ page.selectOption('select#colors', ['red', 'green', 'blue']);
// single selection matching the value
page.selectOption("select#colors", "blue");
// single selection matching both the value and the label
page.selectOption("select#colors", new SelectOption().withLabel("Blue"));
page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
// multiple selection
page.selectOption("select#colors", new String[] {"red", "green", "blue"});
```
Expand Down Expand Up @@ -2444,7 +2444,7 @@ await page.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a u
// Types instantly
page.type("#mytextarea", "Hello");
// Types slower, like a user
page.type("#mytextarea", "World", new Page.TypeOptions().withDelay(100));
page.type("#mytextarea", "World", new Page.TypeOptions().setDelay(100));
```
```python async
Expand Down
10 changes: 5 additions & 5 deletions docs/src/api/class-route.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ page.route("**/*", route -> {
Map<String, String> headers = new HashMap<>(route.request().headers());
headers.put("foo", "bar"); // set "foo" header
headers.remove("origin"); // remove "origin" header
route.resume(new Route.ResumeOptions().withHeaders(headers));
route.resume(new Route.ResumeOptions().setHeaders(headers));
});
```

Expand Down Expand Up @@ -123,9 +123,9 @@ await page.route('**/*', route => {
```java
page.route("**/*", route -> {
route.fulfill(new Route.FulfillOptions()
.withStatus(404)
.withContentType("text/plain")
.withBody("Not Found!"));
.setStatus(404)
.setContentType("text/plain")
.setBody("Not Found!"));
});
```

Expand All @@ -151,7 +151,7 @@ await page.route('**/xhr_endpoint', route => route.fulfill({ path: 'mock_data.js

```java
page.route("**/xhr_endpoint", route -> route.fulfill(
new Route.FulfillOptions().withPath(Paths.get("mock_data.json")));
new Route.FulfillOptions().setPath(Paths.get("mock_data.json")));
```

```python async
Expand Down
4 changes: 2 additions & 2 deletions docs/src/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ System.getenv().put("STORAGE", storage);

// Create a new context with the saved storage state
BrowserContext context = browser.newContext(
new Browser.NewContextOptions().withStorageState(storage));
new Browser.NewContextOptions().setStorageState(storage));
```

```python async
Expand Down Expand Up @@ -261,7 +261,7 @@ public class Example {
BrowserType chromium = playwright.chromium();
Path userDataDir = Paths.get("/path/to/directory");
BrowserContext context = chromium.launchPersistentContext(userDataDir,
new BrowserType.LaunchPersistentContextOptions().withHeadless(false));
new BrowserType.LaunchPersistentContextOptions().setHeadless(false));
// Execute login steps manually in the browser window
}
}
Expand Down
6 changes: 3 additions & 3 deletions docs/src/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Suggested configuration

```java
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions()
.withArgs(Arrays.asList("--disable-dev-shm-usage")));
.setArgs(Arrays.asList("--disable-dev-shm-usage")));
```

```python async
Expand Down Expand Up @@ -245,7 +245,7 @@ public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType chromium = playwright.chromium();
Browser browser = chromium.launch(new BrowserType.LaunchOptions().withChromiumSandbox(false));
Browser browser = chromium.launch(new BrowserType.LaunchOptions().setChromiumSandbox(false));
}
}
}
Expand Down Expand Up @@ -345,7 +345,7 @@ public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType chromium = playwright.chromium();
Browser browser = chromium.launch(new BrowserType.LaunchOptions().withHeadless(false));
Browser browser = chromium.launch(new BrowserType.LaunchOptions().setHeadless(false));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class Example {
try (Playwright playwright = Playwright.create()) {
BrowserType chromium = playwright.chromium();
// Make sure to run headed.
Browser browser = chromium.launch(new BrowserType.LaunchOptions().withHeadless(false));
Browser browser = chromium.launch(new BrowserType.LaunchOptions().setHeadless(false));
// Setup context however you like.
BrowserContext context = browser.newContext(/* pass any options */);
context.route("**/*", route -> route.resume());
Expand Down
26 changes: 13 additions & 13 deletions docs/src/core-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Example {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType chromium = playwright.chromium();
Browser browser = chromium.launch(new BrowserType.LaunchOptions().withHeadless(false));
Browser browser = chromium.launch(new BrowserType.LaunchOptions().setHeadless(false));
browser.close();
}
}
Expand Down Expand Up @@ -123,15 +123,15 @@ public class Example {
try (Playwright playwright = Playwright.create()) {
BrowserType devices = playwright.devices();
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
.withUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1")
.withViewportSize(375, 812)
.withDeviceScaleFactor(3)
.withIsMobile(true)
.withHasTouch(true)
.withPermissions(Arrays.asList("geolocation"))
.withGeolocation(52.52, 13.39)
.withColorScheme(ColorScheme.DARK)
.withLocale("de-DE"));
.setUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Mobile/15E148 Safari/604.1")
.setViewportSize(375, 812)
.setDeviceScaleFactor(3)
.setIsMobile(true)
.setHasTouch(true)
.setPermissions(Arrays.asList("geolocation"))
.setGeolocation(52.52, 13.39)
.setColorScheme(ColorScheme.DARK)
.setLocale("de-DE"));
}
}
}
Expand Down Expand Up @@ -564,7 +564,7 @@ await page.waitForSelector('#promo');
```java
// Wait for #search to appear in the DOM.
page.waitForSelector("#search", new Page.WaitForSelectorOptions()
.withState(WaitForSelectorState.ATTACHED));
.setState(WaitForSelectorState.ATTACHED));
// Wait for #promo to become visible, for example with "visibility:visible".
page.waitForSelector("#promo");
```
Expand Down Expand Up @@ -595,10 +595,10 @@ await page.waitForSelector('#promo', { state: 'detached' });
```java
// Wait for #details to become hidden, for example with "display:none".
page.waitForSelector("#details", new Page.WaitForSelectorOptions()
.withState(WaitForSelectorState.HIDDEN));
.setState(WaitForSelectorState.HIDDEN));
// Wait for #promo to be removed from the DOM.
page.waitForSelector("#promo", new Page.WaitForSelectorOptions()
.withState(WaitForSelectorState.DETACHED));
.setState(WaitForSelectorState.DETACHED));
```

```python async
Expand Down
6 changes: 3 additions & 3 deletions docs/src/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ await chromium.launch({ headless: false, slowMo: 100 }); // or firefox, webkit

```java
chromium.launch(new BrowserType.LaunchOptions() // or firefox, webkit
.withHeadless(false)
.withSlowMo(100));
.setHeadless(false)
.setSlowMo(100));
```

```python async
Expand Down Expand Up @@ -82,7 +82,7 @@ await chromium.launch({ devtools: true });
```

```java
chromium.launch(new BrowserType.LaunchOptions().withDevtools(true));
chromium.launch(new BrowserType.LaunchOptions().setDevtools(true));
```

```python async
Expand Down
2 changes: 1 addition & 1 deletion docs/src/dialogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ page.onDialog(dialog -> {
assertEquals("beforeunload", dialog.type());
dialog.dismiss();
});
page.close(new Page.CloseOptions().withRunBeforeUnload(true));
page.close(new Page.CloseOptions().setRunBeforeUnload(true));
```

```python async
Expand Down
Loading

0 comments on commit 07438f6

Please sign in to comment.