chore: delete Page.LoadState, use Frame.LoadState instead (#234)

This commit is contained in:
Yury Semikhatsky 2021-01-25 16:00:30 -08:00 committed by GitHub
parent e545829bf5
commit 1da197fdf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 15 additions and 14 deletions

View File

@ -263,7 +263,6 @@ public interface Page {
Worker waitForWorker(Runnable code, WaitForWorkerOptions options);
default Worker waitForWorker(Runnable code) { return waitForWorker(code, null); }
enum LoadState { LOAD, DOMCONTENTLOADED, NETWORKIDLE }
class AddScriptTagOptions {
/**
* Raw JavaScript content to be injected into frame.
@ -2354,7 +2353,7 @@ public interface Page {
* @param arg Optional argument to pass to {@code pageFunction}
*/
JSHandle waitForFunction(String pageFunction, Object arg, WaitForFunctionOptions options);
default void waitForLoadState(LoadState state) {
default void waitForLoadState(Frame.LoadState state) {
waitForLoadState(state, null);
}
default void waitForLoadState() {
@ -2374,7 +2373,7 @@ public interface Page {
* - {@code 'domcontentloaded'} - wait for the {@code DOMContentLoaded} event to be fired.
* - {@code 'networkidle'} - wait until there are no network connections for at least {@code 500} ms.
*/
void waitForLoadState(LoadState state, WaitForLoadStateOptions options);
void waitForLoadState(Frame.LoadState state, WaitForLoadStateOptions options);
default Response waitForNavigation(Runnable code) { return waitForNavigation(code, null); }
/**
* Waits for the main frame navigation and returns the main resource response. In case of multiple redirects, the

View File

@ -1158,9 +1158,9 @@ public class PageImpl extends ChannelOwner implements Page {
}
@Override
public void waitForLoadState(LoadState state, WaitForLoadStateOptions options) {
public void waitForLoadState(Frame.LoadState state, WaitForLoadStateOptions options) {
withLogging("Page.waitForLoadState",
() -> mainFrame.waitForLoadStateImpl(convertViaJson(state, Frame.LoadState.class), convertViaJson(options, Frame.WaitForLoadStateOptions.class)));
() -> mainFrame.waitForLoadStateImpl(state, convertViaJson(options, Frame.WaitForLoadStateOptions.class)));
}
@Override

View File

@ -43,7 +43,6 @@ class Serialization {
.registerTypeAdapter(Page.ScreenshotOptions.Type.class, new ToLowerCaseSerializer<Page.ScreenshotOptions.Type>())
.registerTypeAdapter(Mouse.Button.class, new ToLowerCaseSerializer<Mouse.Button>())
.registerTypeAdapter(Frame.LoadState.class, new ToLowerCaseSerializer<Frame.LoadState>())
.registerTypeAdapter(Page.LoadState.class, new ToLowerCaseSerializer<Page.LoadState>())
.registerTypeAdapter(ElementHandle.WaitForSelectorOptions.State.class, new ToLowerCaseSerializer<ElementHandle.WaitForSelectorOptions.State>())
.registerTypeAdapter(Frame.WaitForSelectorOptions.State.class, new ToLowerCaseSerializer<Frame.WaitForSelectorOptions.State>())
.registerTypeAdapter(Page.WaitForSelectorOptions.State.class, new ToLowerCaseSerializer<Page.WaitForSelectorOptions.State>())

View File

@ -18,6 +18,7 @@ package com.microsoft.playwright;
import org.junit.jupiter.api.Test;
import static com.microsoft.playwright.Frame.LoadState.DOMCONTENTLOADED;
import static com.microsoft.playwright.Utils.attachFrame;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -104,7 +105,7 @@ public class TestElementHandleOwnerFrame extends TestBase {
" return div;\n" +
"}");
assertEquals(page.mainFrame(), divHandle.asElement().ownerFrame());
popup.waitForLoadState(Page.LoadState.DOMCONTENTLOADED);
popup.waitForLoadState(DOMCONTENTLOADED);
page.evaluate("() => {\n" +
" const div = document.querySelector('div');\n" +
" window['__popup'].document.body.appendChild(div);\n" +

View File

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static com.microsoft.playwright.Frame.LoadState.DOMCONTENTLOADED;
import static org.junit.jupiter.api.Assertions.*;
public class TestElementHandleQuerySelector extends TestBase {
@ -45,7 +46,7 @@ public class TestElementHandleQuerySelector extends TestBase {
assertNotNull(divHandle.asElement().querySelector("span"));
assertEquals("hello", divHandle.asElement().querySelector("span").evaluate( "e => e.textContent"));
// Test Popup
popup.waitForLoadState(Page.LoadState.DOMCONTENTLOADED);
popup.waitForLoadState(DOMCONTENTLOADED);
page.evaluate("() => {\n" +
" const div = document.querySelector('div');\n" +
" window['__popup'].document.body.appendChild(div);\n" +

View File

@ -29,6 +29,7 @@ import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import static com.microsoft.playwright.Frame.LoadState.DOMCONTENTLOADED;
import static org.junit.jupiter.api.Assertions.*;
public class TestHar extends TestBase {
@ -99,7 +100,7 @@ public class TestHar extends TestBase {
void shouldHavePages() throws IOException {
pageWithHar.page.navigate("data:text/html,<title>Hello</title>");
// For data: load comes before domcontentloaded...
pageWithHar.page.waitForLoadState(Page.LoadState.DOMCONTENTLOADED);
pageWithHar.page.waitForLoadState(DOMCONTENTLOADED);
JsonObject log = pageWithHar.log();
assertEquals(1, log.getAsJsonArray("pages").size());
@ -122,7 +123,7 @@ public class TestHar extends TestBase {
page.navigate("data:text/html,<title>Hello</title>");
// For data: load comes before domcontentloaded...
page.waitForLoadState(Page.LoadState.DOMCONTENTLOADED);
page.waitForLoadState(DOMCONTENTLOADED);
context.close();
JsonObject log;
try (Reader reader = new FileReader(harPath.toFile())) {

View File

@ -25,8 +25,8 @@ import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static com.microsoft.playwright.Page.LoadState.DOMCONTENTLOADED;
import static com.microsoft.playwright.Page.LoadState.LOAD;
import static com.microsoft.playwright.Frame.LoadState.DOMCONTENTLOADED;
import static com.microsoft.playwright.Frame.LoadState.LOAD;
import static org.junit.jupiter.api.Assertions.*;
public class TestPageBasic extends TestBase {

View File

@ -24,7 +24,7 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import static com.microsoft.playwright.Page.LoadState.DOMCONTENTLOADED;
import static com.microsoft.playwright.Frame.LoadState.DOMCONTENTLOADED;
import static com.microsoft.playwright.Utils.mapOf;
import static org.junit.jupiter.api.Assertions.*;

View File

@ -46,7 +46,7 @@ class Types {
Types() {
// State enums
add("Page.waitForLoadState.state", "\"domcontentloaded\"|\"load\"|\"networkidle\"", "LoadState");
add("Page.waitForLoadState.state", "\"domcontentloaded\"|\"load\"|\"networkidle\"", "Frame.LoadState", new Empty());
add("Frame.waitForLoadState.state", "\"domcontentloaded\"|\"load\"|\"networkidle\"", "LoadState");
add("ElementHandle.waitForElementState.state", "\"disabled\"|\"editable\"|\"enabled\"|\"hidden\"|\"stable\"|\"visible\"", "ElementState");
add("Logger.isEnabled.severity", "\"error\"|\"info\"|\"verbose\"|\"warning\"", "Severity");