Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d61ceec50 | |||
| e376ce7fd1 | |||
| cc2d4fa707 | |||
| 077e8f6daa | |||
| 190bcbdd78 | |||
| 7e3e1c0bc7 | |||
| 80d92cbc48 | |||
| 7c07387121 | |||
| 4303a7e963 | |||
| bc82e739f2 | |||
| d7fee058b7 | |||
| 569259d3df | |||
| ef6adb8123 | |||
| ec86901e97 | |||
| 64d9c82f71 | |||
| 0f130d4358 | |||
| fc0c183eec | |||
| 259f2481bd | |||
| 96fa086667 | |||
| f073a75bbe | |||
| 8c9a2a824a | |||
| 7625aa5c62 | |||
| d9534cdda7 | |||
| 08e860e457 |
@@ -1,31 +1,30 @@
|
||||
name: Publish
|
||||
on:
|
||||
release:
|
||||
types: [ published ]
|
||||
|
||||
workflow_dispatch
|
||||
jobs:
|
||||
build:
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
runs-on: ${{ matrix.os }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: microsoft/playwright-github-action@v1
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
server-username: MAVEN_USERNAME # env variable for username in deploy
|
||||
server-password: MAVEN_PASSWORD # env variable for token in deploy
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||
- name: Download drivers
|
||||
shell: bash
|
||||
run: scripts/download_driver_for_all_platforms.sh
|
||||
- name: Publish to Maven Central
|
||||
run: mvn deploy --batch-mode -D skipTests --activate-profiles release --no-transfer-progress
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
|
||||
- uses: actions/checkout@v2
|
||||
- uses: microsoft/playwright-github-action@v1
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
server-username: MAVEN_USERNAME # env variable for username in deploy
|
||||
server-password: MAVEN_PASSWORD # env variable for token in deploy
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||
- name: Download drivers
|
||||
shell: bash
|
||||
run: scripts/download_driver_for_all_platforms.sh
|
||||
- name: Publish to Maven Central
|
||||
run: mvn deploy --batch-mode -D skipTests --activate-profiles release --no-transfer-progress
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ git clone https://github.com/microsoft/playwright-java
|
||||
cd playwright-java
|
||||
```
|
||||
|
||||
2. Run the following script to download playwright-cli binaries for all platforms into `driver-bundle/src/main/resources/driver/` directory. It will also install Playwright and download browser binaries for Chromium, Firefox and WebKit.
|
||||
2. Run the following script to download playwright-cli binaries for all platforms into `driver-bundle/src/main/resources/driver/` directory (browser binaries for Chromium, Firefox and WebKit will be automatically downloaded later on first Playwright run).
|
||||
|
||||
```bash
|
||||
scripts/download_driver_for_all_platforms.sh
|
||||
|
||||
@@ -1,30 +1,41 @@
|
||||
# 🎭 [Playwright](https://github.com/microsoft/playwright) for Java
|
||||
# 🎭 [Playwright](https://playwright.dev) for Java
|
||||
|
||||
[](https://search.maven.org/search?q=com.microsoft.playwright) [](https://join.slack.com/t/playwright/shared_invite/enQtOTEyMTUxMzgxMjIwLThjMDUxZmIyNTRiMTJjNjIyMzdmZDA3MTQxZWUwZTFjZjQwNGYxZGM5MzRmNzZlMWI5ZWUyOTkzMjE5Njg1NDg)
|
||||
|
||||
### _The project is in early development phase, the APIs match those in typescript version of Playwright but are subject to change._
|
||||
#### [Website](https://playwright.dev/) | [API reference](https://www.javadoc.io/doc/com.microsoft.playwright/playwright/latest/index.html)
|
||||
|
||||
Playwright is a Java library to automate [Chromium](https://www.chromium.org/Home), [Firefox](https://www.mozilla.org/en-US/firefox/new/) and [WebKit](https://webkit.org/) with a single API. Playwright is built to enable cross-browser web automation that is **ever-green**, **capable**, **reliable** and **fast**.
|
||||
|
||||
| | Linux | macOS | Windows |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| Chromium <!-- GEN:chromium-version -->89.0.4344.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->14.1<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->84.0b9<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
|
||||
Headless execution is supported for all the browsers on all platforms. Check out [system requirements](https://playwright.dev/#?path=docs/intro.md&q=system-requirements) for details.
|
||||
|
||||
## Usage
|
||||
|
||||
Playwright supports Java 8 and above.
|
||||
|
||||
#### Add Maven dependency
|
||||
|
||||
To run Playwright simply add 2 modules to your Maven project:
|
||||
Playwright is distributed as a set of [Maven](https://maven.apache.org/what-is-maven.html) modules. The easiest way to use it is to add a couple of dependencies to your Maven `pom.xml` file as described below. If you're not familiar with Maven please refer to its [documentation](https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html).
|
||||
|
||||
To run Playwright simply add following dependency to your Maven project:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>playwright</artifactId>
|
||||
<version>0.170.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>driver-bundle</artifactId>
|
||||
<version>0.170.0</version>
|
||||
<version>0.170.3</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
You can find Maven project with the examples [here](./examples).
|
||||
|
||||
#### Page screenshot
|
||||
|
||||
This code snippet navigates to whatsmyuseragent.org in Chromium, Firefox and WebKit, and saves 3 screenshots.
|
||||
@@ -71,14 +82,10 @@ public class MobileAndGeolocation {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Playwright playwright = Playwright.create();
|
||||
BrowserType browserType = playwright.chromium();
|
||||
Browser browser = browserType.launch();
|
||||
Browser browser = browserType.launch(new BrowserType.LaunchOptions().withHeadless(false));
|
||||
DeviceDescriptor pixel2 = playwright.devices().get("Pixel 2");
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.withViewport(pixel2.viewport().width(), pixel2.viewport().height())
|
||||
.withUserAgent(pixel2.userAgent())
|
||||
.withDeviceScaleFactor(pixel2.deviceScaleFactor())
|
||||
.withIsMobile(pixel2.isMobile())
|
||||
.withHasTouch(pixel2.hasTouch())
|
||||
.withDevice(pixel2)
|
||||
.withLocale("en-US")
|
||||
.withGeolocation(new Geolocation(41.889938, 12.492507))
|
||||
.withPermissions(asList("geolocation")));
|
||||
@@ -146,9 +153,16 @@ public class InterceptNetworkRequests {
|
||||
}
|
||||
```
|
||||
|
||||
## Notes
|
||||
## Documentation
|
||||
|
||||
Follow [the instructions](https://github.com/microsoft/playwright-java/blob/master/CONTRIBUTING.md#getting-code) to build the project from source and install driver.
|
||||
We are in the process of converting our documentation from the Node.js form to [Javadocs](https://www.javadoc.io/doc/com.microsoft.playwright/playwright/latest/index.html). You can go ahead and use the Node.js [documentation](https://playwright.dev/) since the API is pretty much the same.
|
||||
|
||||
Original Playwright [documentation](https://playwright.dev/). We are converting it to javadoc.
|
||||
## Contributing
|
||||
|
||||
Follow [the instructions](https://github.com/microsoft/playwright-java/blob/master/CONTRIBUTING.md#getting-code) to build the project from source and install the driver.
|
||||
|
||||
## Is Playwright for Java ready?
|
||||
|
||||
Yes, Playwright for Java is ready. We are still not at the version v1.0, so breaking API changes could potentially happen. But a) this is unlikely and b) we will only do that if we know it improves your experience with the new library. We'd like to collect your feedback before we freeze the API for v1.0.
|
||||
|
||||
> Note: We don't yet support some of the edge-cases of the vendor-specific APIs such as collecting Chromium trace, coverage report, etc.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>0.170.1</version>
|
||||
<version>0.171.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>driver-bundle</artifactId>
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>0.170.1</version>
|
||||
<version>0.171.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>driver</artifactId>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
This directory contains sample [`pom.xml`](./pom.xml) and source code for the Playwright examples.
|
||||
|
||||
You can run them in terminal like this:
|
||||
|
||||
```sh
|
||||
mvn compile exec:java -Dexec.mainClass=org.example.PageScreenshot
|
||||
```
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>examples</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>Playwright Client Examples</name>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>playwright</artifactId>
|
||||
<version>0.170.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed 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.example;
|
||||
|
||||
import com.microsoft.playwright.*;
|
||||
|
||||
public class EvaluateInBrowserContext {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Playwright playwright = Playwright.create();
|
||||
BrowserType browserType = playwright.firefox();
|
||||
Browser browser = browserType.launch();
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
page.navigate("https://www.example.com/");
|
||||
Object dimensions = page.evaluate("() => {\n" +
|
||||
" return {\n" +
|
||||
" width: document.documentElement.clientWidth,\n" +
|
||||
" height: document.documentElement.clientHeight,\n" +
|
||||
" deviceScaleFactor: window.devicePixelRatio\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
System.out.println(dimensions);
|
||||
browser.close();
|
||||
playwright.close();
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -13,23 +13,23 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.microsoft.playwright.example;
|
||||
|
||||
package org.example;
|
||||
|
||||
import com.microsoft.playwright.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class Main {
|
||||
public class InterceptNetworkRequests {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Playwright playwright = Playwright.create();
|
||||
Browser browser = playwright.chromium().launch();
|
||||
BrowserContext context = browser.newContext(
|
||||
new Browser.NewContextOptions().withViewport(800, 600));
|
||||
BrowserType browserType = playwright.webkit();
|
||||
Browser browser = browserType.launch();
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
page.navigate("https://webkit.org");
|
||||
page.click("text=check feature status");
|
||||
page.screenshot(new Page.ScreenshotOptions().withPath(Paths.get("s.png")));
|
||||
page.route("**", route -> {
|
||||
System.out.println(route.request().url());
|
||||
route.continue_();
|
||||
});
|
||||
page.navigate("http://todomvc.com");
|
||||
browser.close();
|
||||
playwright.close();
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed 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.example;
|
||||
|
||||
import com.microsoft.playwright.*;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class MobileAndGeolocation {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Playwright playwright = Playwright.create();
|
||||
BrowserType browserType = playwright.chromium();
|
||||
Browser browser = browserType.launch(new BrowserType.LaunchOptions().withHeadless(false));
|
||||
DeviceDescriptor pixel2 = playwright.devices().get("Pixel 2");
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.withDevice(pixel2)
|
||||
.withLocale("en-US")
|
||||
.withGeolocation(new Geolocation(41.889938, 12.492507))
|
||||
.withPermissions(asList("geolocation")));
|
||||
Page page = context.newPage();
|
||||
page.navigate("https://www.openstreetmap.org/");
|
||||
page.click("a[data-original-title=\"Show My Location\"]");
|
||||
page.screenshot(new Page.ScreenshotOptions().withPath(Paths.get("colosseum-pixel2.png")));
|
||||
browser.close();
|
||||
playwright.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed 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.example;
|
||||
|
||||
import com.microsoft.playwright.*;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PageScreenshot {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Playwright playwright = Playwright.create();
|
||||
List<BrowserType> browserTypes = Arrays.asList(
|
||||
playwright.chromium(),
|
||||
playwright.webkit(),
|
||||
playwright.firefox()
|
||||
);
|
||||
for (BrowserType browserType : browserTypes) {
|
||||
Browser browser = browserType.launch();
|
||||
BrowserContext context = browser.newContext(
|
||||
new Browser.NewContextOptions().withViewport(800, 600));
|
||||
Page page = context.newPage();
|
||||
page.navigate("http://whatsmyuseragent.org/");
|
||||
page.screenshot(new Page.ScreenshotOptions().withPath(Paths.get("screenshot-" + browserType.name() + ".png")));
|
||||
browser.close();
|
||||
}
|
||||
playwright.close();
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>0.170.1</version>
|
||||
<version>0.171.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>playwright</artifactId>
|
||||
@@ -72,7 +72,6 @@
|
||||
<dependency>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>driver-bundle</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.java-websocket</groupId>
|
||||
|
||||
@@ -326,6 +326,14 @@ public interface Browser {
|
||||
this.storageStatePath = storageStatePath;
|
||||
return this;
|
||||
}
|
||||
public NewContextOptions withDevice(DeviceDescriptor device) {
|
||||
withViewport(device.viewport().width(), device.viewport().height());
|
||||
withUserAgent(device.userAgent());
|
||||
withDeviceScaleFactor(device.deviceScaleFactor());
|
||||
withIsMobile(device.isMobile());
|
||||
withHasTouch(device.hasTouch());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class NewPageOptions {
|
||||
public class RecordHar {
|
||||
@@ -600,6 +608,14 @@ public interface Browser {
|
||||
this.storageStatePath = storageStatePath;
|
||||
return this;
|
||||
}
|
||||
public NewPageOptions withDevice(DeviceDescriptor device) {
|
||||
withViewport(device.viewport().width(), device.viewport().height());
|
||||
withUserAgent(device.userAgent());
|
||||
withDeviceScaleFactor(device.deviceScaleFactor());
|
||||
withIsMobile(device.isMobile());
|
||||
withHasTouch(device.hasTouch());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* In case this browser is obtained using browserType.launch([options]), closes the browser and all of its pages (if any were
|
||||
|
||||
@@ -55,6 +55,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
browserContext = (BrowserContextImpl) parent;
|
||||
mainFrame = connection.getExistingObject(initializer.getAsJsonObject("mainFrame").get("guid").getAsString());
|
||||
mainFrame.page = this;
|
||||
isClosed = initializer.get("isClosed").getAsBoolean();
|
||||
keyboard = new KeyboardImpl(this);
|
||||
mouse = new MouseImpl(this);
|
||||
touchscreen = new TouchscreenImpl(this);
|
||||
@@ -212,6 +213,9 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public void close(CloseOptions options) {
|
||||
if (isClosed) {
|
||||
return;
|
||||
}
|
||||
JsonObject params = options == null ? new JsonObject() : gson().toJsonTree(options).getAsJsonObject();
|
||||
try {
|
||||
sendMessage("close", params);
|
||||
|
||||
@@ -37,8 +37,7 @@ public class Transport {
|
||||
DataInputStream in = new DataInputStream(new BufferedInputStream(input));
|
||||
readerThread = new ReaderThread(in, incoming);
|
||||
readerThread.start();
|
||||
DataOutputStream out = new DataOutputStream(output);
|
||||
writerThread = new WriterThread(out, outgoing);
|
||||
writerThread = new WriterThread(output, outgoing);
|
||||
writerThread.start();
|
||||
}
|
||||
|
||||
@@ -125,17 +124,17 @@ class ReaderThread extends Thread {
|
||||
}
|
||||
|
||||
class WriterThread extends Thread {
|
||||
final DataOutputStream out;
|
||||
final OutputStream out;
|
||||
private final BlockingQueue<String> queue;
|
||||
|
||||
private static void writeIntLE(DataOutputStream out, int v) throws IOException {
|
||||
private static void writeIntLE(OutputStream out, int v) throws IOException {
|
||||
out.write(v >>> 0 & 255);
|
||||
out.write(v >>> 8 & 255);
|
||||
out.write(v >>> 16 & 255);
|
||||
out.write(v >>> 24 & 255);
|
||||
}
|
||||
|
||||
WriterThread(DataOutputStream out, BlockingQueue<String> queue) {
|
||||
WriterThread(OutputStream out, BlockingQueue<String> queue) {
|
||||
this.out = out;
|
||||
this.queue = queue;
|
||||
}
|
||||
@@ -158,8 +157,8 @@ class WriterThread extends Thread {
|
||||
}
|
||||
|
||||
private void sendMessage(String message) throws IOException {
|
||||
int len = message.length();
|
||||
writeIntLE(out, len);
|
||||
out.writeBytes(message);
|
||||
byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
|
||||
writeIntLE(out, bytes.length);
|
||||
out.write(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed 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 com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
import static com.microsoft.playwright.BrowserContext.EventType.PAGE;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestBrowserContextBasic extends TestBase {
|
||||
@Test
|
||||
void shouldNotReportFramelessPagesOnError() {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
server.setRoute("/empty.html", exchange -> {
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
try (OutputStreamWriter writer = new OutputStreamWriter(exchange.getResponseBody())) {
|
||||
writer.write("<a href='" + server.EMPTY_PAGE + "' target='_blank'>Click me</a>");
|
||||
}
|
||||
});
|
||||
Page[] popup = {null};
|
||||
context.addListener(PAGE, event -> popup[0] = (Page) event.data());
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.click("'Click me'");
|
||||
context.close();
|
||||
if (popup[0] != null) {
|
||||
// This races on Firefox :/
|
||||
assertTrue(popup[0].isClosed());
|
||||
assertNotNull(popup[0].mainFrame());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -511,6 +511,13 @@ public class TestClick extends TestBase {
|
||||
assertEquals(true, page.evaluate("__CLICKED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithUnicodeSelectors() {
|
||||
page.setContent("<button onclick='javascript:window.__CLICKED=true;'><label style='pointer-events:none'>Найти</label></button>");
|
||||
page.click("text=Найти");
|
||||
assertEquals(true, page.evaluate("__CLICKED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldClimbUpTo_roleButton_() {
|
||||
page.setContent("<div role=button onclick='javascript:window.__CLICKED=true;'><div style='pointer-events:none'><span><div>Click target</div></span></div>");
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>0.170.1</version>
|
||||
<version>0.171.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Playwright Parent Project</name>
|
||||
<description>Java library to automate Chromium, Firefox and WebKit with a single API.
|
||||
@@ -36,7 +36,6 @@
|
||||
</scm>
|
||||
|
||||
<modules>
|
||||
<module>api-generator</module>
|
||||
<module>driver</module>
|
||||
<module>driver-bundle</module>
|
||||
<module>playwright</module>
|
||||
@@ -44,9 +43,10 @@
|
||||
|
||||
<properties>
|
||||
<compiler.version>1.8</compiler.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<gson.version>2.8.6</gson.version>
|
||||
<junit.version>5.7.0</junit.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<websocket.version>1.5.1</websocket.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -61,7 +61,6 @@
|
||||
<artifactId>driver-bundle</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
@@ -76,7 +75,7 @@
|
||||
<dependency>
|
||||
<groupId>org.java-websocket</groupId>
|
||||
<artifactId>Java-WebSocket</artifactId>
|
||||
<version>1.5.1</version>
|
||||
<version>${websocket.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
0.170.0
|
||||
0.171.0
|
||||
|
||||
@@ -31,10 +31,12 @@ do
|
||||
echo "Downloading driver for $PLATFORM to $(pwd)"
|
||||
|
||||
URL=https://playwright.azureedge.net/builds/cli
|
||||
if [[ $CLI_VERSION == *"next"* ]]; then
|
||||
if ! [[ $CLI_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
URL=$URL/next
|
||||
fi
|
||||
curl -O $URL/$FILE_NAME
|
||||
URL=$URL/$FILE_NAME
|
||||
echo "Using url: $URL"
|
||||
curl -O $URL
|
||||
unzip $FILE_NAME -d .
|
||||
rm $FILE_NAME
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ cd "$(dirname $0)/.."
|
||||
PLAYWRIGHT_CLI=./driver-bundle/src/main/resources/driver/linux/playwright-cli
|
||||
echo "Updating api.json from $($PLAYWRIGHT_CLI --version)"
|
||||
|
||||
$PLAYWRIGHT_CLI print-api-json > ./api-generator/src/main/resources/api.json
|
||||
$PLAYWRIGHT_CLI print-api-json > ./tools/api-generator/src/main/resources/api.json
|
||||
|
||||
mvn compile -projects api-generator --no-transfer-progress
|
||||
mvn compile -f ./tools/api-generator --no-transfer-progress
|
||||
|
||||
echo "Regenerating Java interfaces"
|
||||
mvn exec:java --projects api-generator -Dexec.mainClass=com.microsoft.playwright.tools.ApiGenerator
|
||||
mvn exec:java --f ./tools/api-generator -Dexec.mainClass=com.microsoft.playwright.tools.ApiGenerator
|
||||
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set +x
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
echo "Missing version parameter."
|
||||
echo "Usage:"
|
||||
echo " $(basename $0) 0.170.3-SNAPSHOT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
trap "cd $(pwd -P)" EXIT
|
||||
cd "$(dirname $0)/.."
|
||||
|
||||
VERSION=$1
|
||||
|
||||
mvn versions:set -DnewVersion=$VERSION
|
||||
|
||||
cd tools/api-generator
|
||||
mvn versions:set -DnewVersion=$VERSION
|
||||
|
||||
cd -
|
||||
cd tools/update-docs-version
|
||||
mvn versions:set -DnewVersion=$VERSION
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set +x
|
||||
|
||||
trap "cd $(pwd -P)" EXIT
|
||||
|
||||
cd "$(dirname $0)/.."
|
||||
|
||||
./scripts/generate_api.sh
|
||||
|
||||
# Built from source and do local install.
|
||||
mvn clean install --no-transfer-progress -DskipTests
|
||||
|
||||
echo "Updating browser versions in README.md"
|
||||
mvn exec:java --f ./tools/update-docs-version -Dexec.mainClass=com.microsoft.playwright.tools.UpdateBrowserVersions
|
||||
@@ -4,47 +4,30 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>parent-pom</artifactId>
|
||||
<version>0.170.1</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>api-generator</artifactId>
|
||||
<version>0.171.0</version>
|
||||
<name>Playwright - API Generator</name>
|
||||
<description>Java library to automate Chromium, Firefox and WebKit with a single API.
|
||||
Playwright is built to enable cross-browser web automation that is ever-green, capable,
|
||||
reliable and fast.
|
||||
|
||||
<description>
|
||||
This is an internal module used to generate Java API from the upstream Playwright
|
||||
definitions. It's an internal development module not intended for external use.
|
||||
</description>
|
||||
<properties>
|
||||
<compiler.version>1.8</compiler.version>
|
||||
<gson.version>2.8.6</gson.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<failOnError>false</failOnError>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>${compiler.version}</source>
|
||||
<target>${compiler.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
@@ -52,6 +35,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+15
-1
@@ -1102,6 +1102,10 @@ class NestedClass extends TypeDefinition {
|
||||
}
|
||||
} else {
|
||||
writeBuilderMethods(output, bodyOffset);
|
||||
if ("Browser.newContext.options".equals(jsonPath) ||
|
||||
"Browser.newPage.options".equals(jsonPath)) {
|
||||
writeDeviceDescriptorBuilder(output, bodyOffset);
|
||||
}
|
||||
}
|
||||
output.add(offset + "}");
|
||||
}
|
||||
@@ -1133,6 +1137,16 @@ class NestedClass extends TypeDefinition {
|
||||
output.add(bodyOffset + "}");
|
||||
}
|
||||
|
||||
private void writeDeviceDescriptorBuilder(List<String> output, String bodyOffset) {
|
||||
output.add(bodyOffset + "public " + name + " withDevice(DeviceDescriptor device) {");
|
||||
output.add(bodyOffset + " withViewport(device.viewport().width(), device.viewport().height());");
|
||||
output.add(bodyOffset + " withUserAgent(device.userAgent());");
|
||||
output.add(bodyOffset + " withDeviceScaleFactor(device.deviceScaleFactor());");
|
||||
output.add(bodyOffset + " withIsMobile(device.isMobile());");
|
||||
output.add(bodyOffset + " withHasTouch(device.hasTouch());");
|
||||
output.add(bodyOffset + " return this;");
|
||||
output.add(bodyOffset + "}");
|
||||
}
|
||||
}
|
||||
|
||||
class Enum extends TypeDefinition {
|
||||
@@ -1188,7 +1202,7 @@ public class ApiGenerator {
|
||||
public static void main(String[] args) throws IOException {
|
||||
File cwd = FileSystems.getDefault().getPath(".").toFile();
|
||||
System.out.println(cwd.getCanonicalPath());
|
||||
File file = new File(cwd, "api-generator/src/main/resources/api.json");
|
||||
File file = new File(cwd, "tools/api-generator/src/main/resources/api.json");
|
||||
System.out.println("Reading from: " + file.getCanonicalPath());
|
||||
new ApiGenerator(new FileReader(file));
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>update-version</artifactId>
|
||||
<version>0.171.0</version>
|
||||
<name>Playwright - Update Version in Documentation</name>
|
||||
<description>
|
||||
This is an internal module used to update versions in the documentation based on
|
||||
current driver.
|
||||
</description>
|
||||
<properties>
|
||||
<compiler.version>1.8</compiler.version>
|
||||
<gson.version>2.8.6</gson.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>${compiler.version}</source>
|
||||
<target>${compiler.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.playwright</groupId>
|
||||
<artifactId>playwright</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed 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 com.microsoft.playwright.tools;
|
||||
|
||||
import com.microsoft.playwright.Browser;
|
||||
import com.microsoft.playwright.BrowserType;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
public class UpdateBrowserVersions {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Path path = Paths.get("README.md");
|
||||
String readme = new String(Files.readAllBytes(path), UTF_8);
|
||||
|
||||
Playwright playwright = Playwright.create();
|
||||
List<BrowserType> browserTypes = Arrays.asList(
|
||||
playwright.chromium(),
|
||||
playwright.webkit(),
|
||||
playwright.firefox()
|
||||
);
|
||||
for (BrowserType browserType : browserTypes) {
|
||||
Browser browser = browserType.launch();
|
||||
String version = browser.version();
|
||||
browser.close();
|
||||
readme = readme.replaceAll(
|
||||
"<!-- GEN:" + browserType.name() + "-version -->([^<]+)<!-- GEN:stop -->",
|
||||
"<!-- GEN:" + browserType.name() + "-version -->" + version + "<!-- GEN:stop -->");
|
||||
try (FileWriter writer = new FileWriter(path.toFile())) {
|
||||
writer.write(readme);
|
||||
}
|
||||
}
|
||||
playwright.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user