Skip to content

Commit

Permalink
install browsers as separate step
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Nov 14, 2024
1 parent 02863c5 commit 1f07b32
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
run: scripts/download_driver.sh
- name: Build & Install
run: mvn -B install -D skipTests --no-transfer-progress
- name: Install browsers
run: mvn compile exec:java -f playwright -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install --with-deps"
- name: Run tests
run: mvn test --no-transfer-progress --fail-at-end -D org.slf4j.simpleLogger.showDateTime=true -D org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss
env:
Expand Down Expand Up @@ -78,6 +80,8 @@ jobs:
run: scripts/download_driver.sh
- name: Build & Install
run: mvn -B install -D skipTests --no-transfer-progress
- name: Install browsers
run: mvn compile exec:java -f playwright/pom.xml -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install --with-deps"
- name: Install MS Edge
if: matrix.browser-channel == 'msedge' && matrix.os == 'macos-latest'
shell: bash
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/verify_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
run: scripts/download_driver.sh
- name: Regenerate APIs
run: scripts/generate_api.sh
- name: Install browsers
run: mvn compile exec:java -f playwright/pom.xml -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install --with-deps"
- name: Update browser versions in README
run: scripts/update_readme.sh
- name: Verify API is up to date
Expand Down
53 changes: 52 additions & 1 deletion playwright/src/main/java/com/microsoft/playwright/Locator.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
*/
public interface Locator {
class AriaSnapshotOptions {
/**
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
* value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
* BrowserContext.setDefaultTimeout()} or {@link com.microsoft.playwright.Page#setDefaultTimeout Page.setDefaultTimeout()}
* methods.
*/
public Double timeout;

/**
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
* value can be changed by using the {@link com.microsoft.playwright.BrowserContext#setDefaultTimeout
* BrowserContext.setDefaultTimeout()} or {@link com.microsoft.playwright.Page#setDefaultTimeout Page.setDefaultTimeout()}
* methods.
*/
public AriaSnapshotOptions setTimeout(double timeout) {
this.timeout = timeout;
return this;
}
}
class BlurOptions {
/**
* Maximum time in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The default
Expand Down Expand Up @@ -2230,7 +2250,38 @@ public WaitForOptions setTimeout(double timeout) {
*
* @since v1.49
*/
String ariaSnapshot();
default String ariaSnapshot() {
return ariaSnapshot(null);
}
/**
* Captures the aria snapshot of the given element. Read more about <a
* href="https://playwright.dev/java/docs/aria-snapshots">aria snapshots</a> and {@link
* com.microsoft.playwright.assertions.LocatorAssertions#matchesAriaSnapshot LocatorAssertions.matchesAriaSnapshot()} for
* the corresponding assertion.
*
* <p> <strong>Usage</strong>
* <pre>{@code
* page.getByRole(AriaRole.LINK).ariaSnapshot();
* }</pre>
*
* <p> <strong>Details</strong>
*
* <p> This method captures the aria snapshot of the given element. The snapshot is a string that represents the state of the
* element and its children. The snapshot can be used to assert the state of the element in the test, or to compare it to
* state in the future.
*
* <p> The ARIA snapshot is represented using <a href="https://yaml.org/spec/1.2.2/">YAML</a> markup language:
* <ul>
* <li> The keys of the objects are the roles and optional accessible names of the elements.</li>
* <li> The values are either text content or an array of child elements.</li>
* <li> Generic static text can be represented with the {@code text} key.</li>
* </ul>
*
* <p> Below is the HTML markup and the respective ARIA snapshot:
*
* @since v1.49
*/
String ariaSnapshot(AriaSnapshotOptions options);
/**
* Calls <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur">blur</a> on the element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,20 @@ public HasValuesOptions setTimeout(double timeout) {
return this;
}
}
class MatchesAriaSnapshotOptions {
/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
*/
public Double timeout;

/**
* Time to retry the assertion for in milliseconds. Defaults to {@code 5000}.
*/
public MatchesAriaSnapshotOptions setTimeout(double timeout) {
this.timeout = timeout;
return this;
}
}
/**
* Makes the assertion check for the opposite condition. For example, this code tests that the Locator doesn't contain text
* {@code "error"}:
Expand Down Expand Up @@ -2172,6 +2186,24 @@ default void hasValues(Pattern[] values) {
*
* @since v1.49
*/
void matchesAriaSnapshot(String expected);
default void matchesAriaSnapshot(String expected) {
matchesAriaSnapshot(expected, null);
}
/**
* Asserts that the target element matches the given <a
* href="https://playwright.dev/java/docs/aria-snapshots">accessibility snapshot</a>.
*
* <p> <strong>Usage</strong>
* <pre>{@code
* page.navigate("https://demo.playwright.dev/todomvc/");
* assertThat(page.locator("body")).matchesAriaSnapshot("""
* - heading "todos"
* - textbox "What needs to be done?"
* """);
* }</pre>
*
* @since v1.49
*/
void matchesAriaSnapshot(String expected, MatchesAriaSnapshotOptions options);
}

Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,8 @@ public void hasValues(Pattern[] patterns, HasValuesOptions options) {
}

@Override
public void matchesAriaSnapshot(String expected) {
// expected = unshift(expected);
// TODO: timeout
FrameExpectOptions options = new FrameExpectOptions();
public void matchesAriaSnapshot(String expected, MatchesAriaSnapshotOptions snapshotOptions) {
FrameExpectOptions options = convertType(snapshotOptions, FrameExpectOptions.class);
options.expectedValue = serializeArgument(expected);
expectImpl("to.match.aria", options, expected,"Locator expected to match Aria snapshot");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ public Locator and(Locator locator) {
}

@Override
public String ariaSnapshot() {
return frame.withLogging("Locator.ariaSnapshot", () -> ariaSnapshotImpl());
public String ariaSnapshot(AriaSnapshotOptions options) {
return frame.withLogging("Locator.ariaSnapshot", () -> ariaSnapshotImpl(options));
}

private String ariaSnapshotImpl() {
JsonObject params = new JsonObject();
private String ariaSnapshotImpl(AriaSnapshotOptions options) {
if (options == null) {
options = new AriaSnapshotOptions();
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
params.addProperty("selector", selector);
JsonObject result = frame.sendMessage("ariaSnapshot", params).getAsJsonObject();
return result.get("snapshot").getAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ void shouldSnapshotComplex(Page page) {
@Test
void shouldAllowTextNodes(Page page) {
page.setContent("<h1>Microsoft</h1><div>Open source projects and samples from Microsoft</div>");
checkAndMatchSnapshot(page.locator("body"), "- heading \"Microsoft\" [level=1]\n" +
"- text: Open source projects and samples from Microsoft");
checkAndMatchSnapshot(page.locator("body"), "" +
" - heading \"Microsoft\" [level=1]\n" +
" - text: Open source projects and samples from Microsoft");
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion scripts/DRIVER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.49.0-beta-1731595428000
1.49.0-beta-1731616844000

0 comments on commit 1f07b32

Please sign in to comment.