fix: use playwright-cli as driver (#9)

This commit is contained in:
Yury Semikhatsky 2020-10-13 11:10:21 -07:00 committed by GitHub
parent be8b400b2b
commit a5adc3180c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 62 deletions

View File

@ -20,12 +20,27 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8
- uses: actions/setup-node@v2-beta
with:
node-version: '12'
- name: Install driver dependencies
- run: mkdir -p driver
- name: Install driver
working-directory: driver
run: npm install
env:
OS: ${{ matrix.os }}
shell: bash
run: |
FILE_NAME="unkwnown"
if [[ $OS == *"ubuntu"* ]]; then
FILE_NAME=playwright-cli-0.5.3-linux.zip
fi
if [[ $OS == *"macos"* ]]; then
FILE_NAME=playwright-cli-0.5.3-mac.zip
fi
if [[ $OS == *"windows"* ]]; then
FILE_NAME=playwright-cli-0.5.3-win32_x64.zip
fi
echo "Downloading from $FILE_NAME"
curl -O https://playwright.azureedge.net/builds/cli/$FILE_NAME
unzip $FILE_NAME -d .
./playwright-cli install
- name: Build with Maven
run: mvn -B package -D skipTests
- name: Run tests

2
.gitignore vendored
View File

@ -18,3 +18,5 @@ target/
.idea
*.iml
/driver/

View File

@ -11,12 +11,14 @@ git clone https://github.com/microsoft/playwright-java
cd playwright-java
```
2. Checkout and build playwright node.js package
2. Checkout and install playwright-cli node.js package into `driver/` directory
```bash
mkdir driver
cd driver
npm install
npm run build
curl -O https://playwright.azureedge.net/builds/cli/playwright-cli-0.5.3-linux.zip
unzip playwright-cli-0.5.3-linux.zip -d .
./playwright-cli install
```
### Generating API

5
driver/.gitignore vendored
View File

@ -1,5 +0,0 @@
/node_modules/
.DS_Store
*.swp
.vscode
package-lock.json

View File

@ -1,17 +0,0 @@
/**
* 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.
*/
require('playwright/lib/server');

View File

@ -1,15 +0,0 @@
{
"name": "driver",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "Apache-2.0",
"dependencies": {
"playwright": "^1.4.2"
}
}

View File

@ -99,7 +99,6 @@ public class FrameImpl extends ChannelOwner implements Frame {
params.addProperty("selector", selector);
JsonElement json = sendMessage("querySelectorAll", params);
JsonArray elements = json.getAsJsonObject().getAsJsonArray("elements");
System.out.println(new Gson().toJson(elements));
if (elements == null) {
return null;
}
@ -385,7 +384,6 @@ public class FrameImpl extends ChannelOwner implements Frame {
params.addProperty("html", html);
params.remove("waitUntil");
params.addProperty("waitUntil", toProtocol(options.waitUntil));
// System.out.println(new Gson().toJson(params));
sendMessage("setContent", params);
}

View File

@ -34,9 +34,8 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright {
public static PlaywrightImpl create() {
try {
File cwd = FileSystems.getDefault().getPath(".").toFile();
File driver = new File(cwd, "../driver/main.js");
System.out.println("driver = " + driver.getCanonicalPath());
ProcessBuilder pb = new ProcessBuilder("node", driver.getCanonicalPath());
File driver = new File(cwd, "../driver/playwright-cli");
ProcessBuilder pb = new ProcessBuilder(driver.getCanonicalPath(), "run-driver");
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
// pb.environment().put("DEBUG", "pw:pro*");
Process p = pb.start();

View File

@ -198,16 +198,16 @@ public class TestQuerySelector {
assertEquals(2, elements.size());
}
// @Test
// void querySelectorAllShouldWorkWithBogusArrayFrom() {
// page.setContent("<div>hello</div><div></div>");
// JSHandle div1 = page.evaluateHandle("() => {\n" +
// " Array.from = () => [];\n" +
// " return document.querySelector('div');\n" +
// "}");
// List<ElementHandle> elements = page.querySelectorAll("div");
// assertEquals(2, elements.size());
// // Check that element handle is functional and belongs to the main world.
// assertEquals(true, elements.get(0).evaluate("(div, div1) => div === div1", div1));
// }
@Test
void querySelectorAllShouldWorkWithBogusArrayFrom() throws InterruptedException {
page.setContent("<div>hello</div><div></div>");
JSHandle div1 = page.evaluateHandle("() => {\n" +
" Array.from = () => [];\n" +
" return document.querySelector('div');\n" +
"}");
List<ElementHandle> elements = page.querySelectorAll("div");
assertEquals(2, elements.size());
// Check that element handle is functional and belongs to the main world.
assertEquals(true, elements.get(0).evaluate("(div, div1) => div === div1", div1));
}
}