feat: roll driver, implement new APIs (#1142)
This commit is contained in:
@@ -11,9 +11,9 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
|
||||
|
||||
| | Linux | macOS | Windows |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| Chromium <!-- GEN:chromium-version -->108.0.5359.29<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| Chromium <!-- GEN:chromium-version -->109.0.5414.46<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| WebKit <!-- GEN:webkit-version -->16.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
|
||||
| Firefox <!-- GEN:firefox-version -->106.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||
| Firefox <!-- GEN:firefox-version -->107.0<!-- 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/java/docs/next/intro/#system-requirements) for details.
|
||||
|
||||
|
||||
@@ -57,17 +57,17 @@ public interface APIRequest {
|
||||
*/
|
||||
public Proxy proxy;
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()} or {@link APIRequestContext#storageState
|
||||
* APIRequestContext.storageState()}. Either a path to the file with saved storage, or the value returned by one of {@link
|
||||
* BrowserContext#storageState BrowserContext.storageState()} or {@link APIRequestContext#storageState
|
||||
* APIRequestContext.storageState()} methods.
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in
|
||||
* information obtained via {@link BrowserContext#storageState BrowserContext.storageState()} or {@link
|
||||
* APIRequestContext#storageState APIRequestContext.storageState()}. Either a path to the file with saved storage, or the
|
||||
* value returned by one of {@link BrowserContext#storageState BrowserContext.storageState()} or {@link
|
||||
* APIRequestContext#storageState APIRequestContext.storageState()} methods.
|
||||
*/
|
||||
public String storageState;
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved storage
|
||||
* state.
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in
|
||||
* information obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved
|
||||
* storage state.
|
||||
*/
|
||||
public Path storageStatePath;
|
||||
/**
|
||||
@@ -136,20 +136,20 @@ public interface APIRequest {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()} or {@link APIRequestContext#storageState
|
||||
* APIRequestContext.storageState()}. Either a path to the file with saved storage, or the value returned by one of {@link
|
||||
* BrowserContext#storageState BrowserContext.storageState()} or {@link APIRequestContext#storageState
|
||||
* APIRequestContext.storageState()} methods.
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in
|
||||
* information obtained via {@link BrowserContext#storageState BrowserContext.storageState()} or {@link
|
||||
* APIRequestContext#storageState APIRequestContext.storageState()}. Either a path to the file with saved storage, or the
|
||||
* value returned by one of {@link BrowserContext#storageState BrowserContext.storageState()} or {@link
|
||||
* APIRequestContext#storageState APIRequestContext.storageState()} methods.
|
||||
*/
|
||||
public NewContextOptions setStorageState(String storageState) {
|
||||
this.storageState = storageState;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved storage
|
||||
* state.
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in
|
||||
* information obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved
|
||||
* storage state.
|
||||
*/
|
||||
public NewContextOptions setStorageStatePath(Path storageStatePath) {
|
||||
this.storageStatePath = storageStatePath;
|
||||
|
||||
@@ -20,8 +20,8 @@ import com.microsoft.playwright.options.*;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare
|
||||
* environment or the service to your e2e test.
|
||||
* This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services,
|
||||
* prepare environment or the service to your e2e test.
|
||||
*
|
||||
* <p> Each Playwright browser context has associated with it {@code APIRequestContext} instance which shares cookie storage with the
|
||||
* browser context and can be accessed via {@link BrowserContext#request BrowserContext.request()} or {@link Page#request
|
||||
@@ -36,8 +36,8 @@ import java.nio.file.Path;
|
||||
* automatically update {@code BrowserContext} cookies and requests made from the page will pick them up. This means that if you
|
||||
* log in using this API, your e2e test will be logged in and vice versa.
|
||||
*
|
||||
* <p> If you want API requests to not interfere with the browser cookies you should create a new {@code APIRequestContext} by
|
||||
* calling {@link APIRequest#newContext APIRequest.newContext()}. Such {@code APIRequestContext} object will have its own
|
||||
* <p> If you want API requests to not interfere with the browser cookies you should create a new {@code APIRequestContext}
|
||||
* by calling {@link APIRequest#newContext APIRequest.newContext()}. Such {@code APIRequestContext} object will have its own
|
||||
* isolated cookie storage.
|
||||
*/
|
||||
public interface APIRequestContext {
|
||||
@@ -83,10 +83,11 @@ public interface APIRequestContext {
|
||||
*/
|
||||
void dispose();
|
||||
/**
|
||||
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
||||
* context cookies from the response. The method will automatically follow redirects.
|
||||
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and
|
||||
* update context cookies from the response. The method will automatically follow redirects. JSON objects can be passed
|
||||
* directly to the request.
|
||||
*
|
||||
* <p> JSON objects can be passed directly to the request:
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Map<String, Object> data = new HashMap();
|
||||
* data.put("title", "Book Title");
|
||||
@@ -117,10 +118,11 @@ public interface APIRequestContext {
|
||||
return fetch(urlOrRequest, null);
|
||||
}
|
||||
/**
|
||||
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
||||
* context cookies from the response. The method will automatically follow redirects.
|
||||
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and
|
||||
* update context cookies from the response. The method will automatically follow redirects. JSON objects can be passed
|
||||
* directly to the request.
|
||||
*
|
||||
* <p> JSON objects can be passed directly to the request:
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Map<String, Object> data = new HashMap();
|
||||
* data.put("title", "Book Title");
|
||||
@@ -150,10 +152,11 @@ public interface APIRequestContext {
|
||||
*/
|
||||
APIResponse fetch(String urlOrRequest, RequestOptions params);
|
||||
/**
|
||||
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
||||
* context cookies from the response. The method will automatically follow redirects.
|
||||
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and
|
||||
* update context cookies from the response. The method will automatically follow redirects. JSON objects can be passed
|
||||
* directly to the request.
|
||||
*
|
||||
* <p> JSON objects can be passed directly to the request:
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Map<String, Object> data = new HashMap();
|
||||
* data.put("title", "Book Title");
|
||||
@@ -184,10 +187,11 @@ public interface APIRequestContext {
|
||||
return fetch(urlOrRequest, null);
|
||||
}
|
||||
/**
|
||||
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
||||
* context cookies from the response. The method will automatically follow redirects.
|
||||
* Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and
|
||||
* update context cookies from the response. The method will automatically follow redirects. JSON objects can be passed
|
||||
* directly to the request.
|
||||
*
|
||||
* <p> JSON objects can be passed directly to the request:
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Map<String, Object> data = new HashMap();
|
||||
* data.put("title", "Book Title");
|
||||
@@ -221,6 +225,8 @@ public interface APIRequestContext {
|
||||
* response. The method will populate request cookies from the context and update context cookies from the response. The
|
||||
* method will automatically follow redirects.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Request parameters can be configured with {@code params} option, they will be serialized into the URL search parameters:
|
||||
* <pre>{@code
|
||||
* request.get("https://example.com/api/getText", RequestOptions.create()
|
||||
@@ -238,6 +244,8 @@ public interface APIRequestContext {
|
||||
* response. The method will populate request cookies from the context and update context cookies from the response. The
|
||||
* method will automatically follow redirects.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Request parameters can be configured with {@code params} option, they will be serialized into the URL search parameters:
|
||||
* <pre>{@code
|
||||
* request.get("https://example.com/api/getText", RequestOptions.create()
|
||||
@@ -292,6 +300,8 @@ public interface APIRequestContext {
|
||||
* response. The method will populate request cookies from the context and update context cookies from the response. The
|
||||
* method will automatically follow redirects.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> JSON objects can be passed directly to the request:
|
||||
* <pre>{@code
|
||||
* Map<String, Object> data = new HashMap();
|
||||
@@ -335,6 +345,8 @@ public interface APIRequestContext {
|
||||
* response. The method will populate request cookies from the context and update context cookies from the response. The
|
||||
* method will automatically follow redirects.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> JSON objects can be passed directly to the request:
|
||||
* <pre>{@code
|
||||
* Map<String, Object> data = new HashMap();
|
||||
|
||||
@@ -80,8 +80,8 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code "no-preference"}. See
|
||||
* {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code "no-preference"}.
|
||||
* See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
* Defaults to {@code "light"}.
|
||||
*/
|
||||
public Optional<ColorScheme> colorScheme;
|
||||
@@ -112,8 +112,8 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not supported
|
||||
* in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
@@ -121,8 +121,8 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value, {@code Accept-Language}
|
||||
* request header value as well as number and date formatting rules.
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
@@ -196,20 +196,20 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public ServiceWorkerPolicy serviceWorkers;
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}.
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in
|
||||
* information obtained via {@link BrowserContext#storageState BrowserContext.storageState()}.
|
||||
*/
|
||||
public String storageState;
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved storage
|
||||
* state.
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in
|
||||
* information obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved
|
||||
* storage state.
|
||||
*/
|
||||
public Path storageStatePath;
|
||||
/**
|
||||
* If specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. See {@code Locator} to learn
|
||||
* more about the strict mode.
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
*/
|
||||
public Boolean strictSelectors;
|
||||
/**
|
||||
@@ -259,8 +259,8 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code "no-preference"}. See
|
||||
* {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code "no-preference"}.
|
||||
* See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
* Defaults to {@code "light"}.
|
||||
*/
|
||||
public NewContextOptions setColorScheme(ColorScheme colorScheme) {
|
||||
@@ -324,8 +324,8 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not supported
|
||||
* in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
*/
|
||||
public NewContextOptions setIsMobile(boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
@@ -339,8 +339,8 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value, {@code Accept-Language}
|
||||
* request header value as well as number and date formatting rules.
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public NewContextOptions setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
@@ -485,26 +485,26 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}.
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in
|
||||
* information obtained via {@link BrowserContext#storageState BrowserContext.storageState()}.
|
||||
*/
|
||||
public NewContextOptions setStorageState(String storageState) {
|
||||
this.storageState = storageState;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved storage
|
||||
* state.
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in
|
||||
* information obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved
|
||||
* storage state.
|
||||
*/
|
||||
public NewContextOptions setStorageStatePath(Path storageStatePath) {
|
||||
this.storageStatePath = storageStatePath;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. See {@code Locator} to learn
|
||||
* more about the strict mode.
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
*/
|
||||
public NewContextOptions setStrictSelectors(boolean strictSelectors) {
|
||||
this.strictSelectors = strictSelectors;
|
||||
@@ -564,8 +564,8 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean bypassCSP;
|
||||
/**
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code "no-preference"}. See
|
||||
* {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code "no-preference"}.
|
||||
* See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
* Defaults to {@code "light"}.
|
||||
*/
|
||||
public Optional<ColorScheme> colorScheme;
|
||||
@@ -596,8 +596,8 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not supported
|
||||
* in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
@@ -605,8 +605,8 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value, {@code Accept-Language}
|
||||
* request header value as well as number and date formatting rules.
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
@@ -680,20 +680,20 @@ public interface Browser extends AutoCloseable {
|
||||
*/
|
||||
public ServiceWorkerPolicy serviceWorkers;
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}.
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in
|
||||
* information obtained via {@link BrowserContext#storageState BrowserContext.storageState()}.
|
||||
*/
|
||||
public String storageState;
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved storage
|
||||
* state.
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in
|
||||
* information obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved
|
||||
* storage state.
|
||||
*/
|
||||
public Path storageStatePath;
|
||||
/**
|
||||
* If specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. See {@code Locator} to learn
|
||||
* more about the strict mode.
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
*/
|
||||
public Boolean strictSelectors;
|
||||
/**
|
||||
@@ -743,8 +743,8 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code "no-preference"}. See
|
||||
* {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code "no-preference"}.
|
||||
* See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
* Defaults to {@code "light"}.
|
||||
*/
|
||||
public NewPageOptions setColorScheme(ColorScheme colorScheme) {
|
||||
@@ -808,8 +808,8 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not supported
|
||||
* in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
*/
|
||||
public NewPageOptions setIsMobile(boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
@@ -823,8 +823,8 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value, {@code Accept-Language}
|
||||
* request header value as well as number and date formatting rules.
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public NewPageOptions setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
@@ -969,26 +969,26 @@ public interface Browser extends AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}.
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in
|
||||
* information obtained via {@link BrowserContext#storageState BrowserContext.storageState()}.
|
||||
*/
|
||||
public NewPageOptions setStorageState(String storageState) {
|
||||
this.storageState = storageState;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in information
|
||||
* obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved storage
|
||||
* state.
|
||||
* Populates context with given storage state. This option can be used to initialize context with logged-in
|
||||
* information obtained via {@link BrowserContext#storageState BrowserContext.storageState()}. Path to the file with saved
|
||||
* storage state.
|
||||
*/
|
||||
public NewPageOptions setStorageStatePath(Path storageStatePath) {
|
||||
this.storageStatePath = storageStatePath;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. See {@code Locator} to learn
|
||||
* more about the strict mode.
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
*/
|
||||
public NewPageOptions setStrictSelectors(boolean strictSelectors) {
|
||||
this.strictSelectors = strictSelectors;
|
||||
@@ -1068,8 +1068,8 @@ public interface Browser extends AutoCloseable {
|
||||
* In case this browser is obtained using {@link BrowserType#launch BrowserType.launch()}, closes the browser and all of
|
||||
* its pages (if any were opened).
|
||||
*
|
||||
* <p> In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
|
||||
* browser server.
|
||||
* <p> In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from
|
||||
* the browser server.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> This is similar to force quitting the browser. Therefore, you should call {@link BrowserContext#close
|
||||
* BrowserContext.close()} on any {@code BrowserContext}'s you explicitly created earlier with {@link Browser#newContext
|
||||
@@ -1080,6 +1080,8 @@ public interface Browser extends AutoCloseable {
|
||||
void close();
|
||||
/**
|
||||
* Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Browser browser = pw.webkit().launch();
|
||||
* System.out.println(browser.contexts().size()); // prints "0"
|
||||
@@ -1099,6 +1101,8 @@ public interface Browser extends AutoCloseable {
|
||||
* via {@link BrowserContext#close BrowserContext.close()} when your code is done with the {@code BrowserContext}, and before
|
||||
* calling {@link Browser#close Browser.close()}. This will ensure the {@code context} is closed gracefully and any
|
||||
* artifacts—like HARs and videos—are fully flushed and saved.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Browser browser = playwright.firefox().launch(); // Or 'chromium' or 'webkit'.
|
||||
* // Create a new incognito browser context.
|
||||
@@ -1122,6 +1126,8 @@ public interface Browser extends AutoCloseable {
|
||||
* via {@link BrowserContext#close BrowserContext.close()} when your code is done with the {@code BrowserContext}, and before
|
||||
* calling {@link Browser#close Browser.close()}. This will ensure the {@code context} is closed gracefully and any
|
||||
* artifacts—like HARs and videos—are fully flushed and saved.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Browser browser = playwright.firefox().launch(); // Or 'chromium' or 'webkit'.
|
||||
* // Create a new incognito browser context.
|
||||
@@ -1139,8 +1145,8 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Creates a new page in a new browser context. Closing this page will close the context as well.
|
||||
*
|
||||
* <p> This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
|
||||
* testing frameworks should explicitly create {@link Browser#newContext Browser.newContext()} followed by the {@link
|
||||
* <p> This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code
|
||||
* and testing frameworks should explicitly create {@link Browser#newContext Browser.newContext()} followed by the {@link
|
||||
* BrowserContext#newPage BrowserContext.newPage()} to control their exact life times.
|
||||
*/
|
||||
default Page newPage() {
|
||||
@@ -1149,8 +1155,8 @@ public interface Browser extends AutoCloseable {
|
||||
/**
|
||||
* Creates a new page in a new browser context. Closing this page will close the context as well.
|
||||
*
|
||||
* <p> This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
|
||||
* testing frameworks should explicitly create {@link Browser#newContext Browser.newContext()} followed by the {@link
|
||||
* <p> This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code
|
||||
* and testing frameworks should explicitly create {@link Browser#newContext Browser.newContext()} followed by the {@link
|
||||
* BrowserContext#newPage BrowserContext.newPage()} to control their exact life times.
|
||||
*/
|
||||
Page newPage(NewPageOptions options);
|
||||
@@ -1162,6 +1168,8 @@ public interface Browser extends AutoCloseable {
|
||||
*
|
||||
* <p> You can use {@link Browser#startTracing Browser.startTracing()} and {@link Browser#stopTracing Browser.stopTracing()} to
|
||||
* create a trace file that can be opened in Chrome DevTools performance panel.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* browser.startTracing(page, new Browser.StartTracingOptions()
|
||||
* .setPath(Paths.get("trace.json")));
|
||||
@@ -1182,6 +1190,8 @@ public interface Browser extends AutoCloseable {
|
||||
*
|
||||
* <p> You can use {@link Browser#startTracing Browser.startTracing()} and {@link Browser#stopTracing Browser.stopTracing()} to
|
||||
* create a trace file that can be opened in Chrome DevTools performance panel.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* browser.startTracing(page, new Browser.StartTracingOptions()
|
||||
* .setPath(Paths.get("trace.json")));
|
||||
@@ -1200,6 +1210,8 @@ public interface Browser extends AutoCloseable {
|
||||
*
|
||||
* <p> You can use {@link Browser#startTracing Browser.startTracing()} and {@link Browser#stopTracing Browser.stopTracing()} to
|
||||
* create a trace file that can be opened in Chrome DevTools performance panel.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* browser.startTracing(page, new Browser.StartTracingOptions()
|
||||
* .setPath(Paths.get("trace.json")));
|
||||
|
||||
@@ -26,8 +26,8 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* BrowserContexts provide a way to operate multiple independent browser sessions.
|
||||
*
|
||||
* <p> If a page opens another page, e.g. with a {@code window.open} call, the popup will belong to the parent page's browser
|
||||
* context.
|
||||
* <p> If a page opens another page, e.g. with a {@code window.open} call, the popup will belong to the parent page's
|
||||
* browser context.
|
||||
*
|
||||
* <p> Playwright allows creating "incognito" browser contexts with {@link Browser#newContext Browser.newContext()} method.
|
||||
* "Incognito" browser contexts don't write any browsing data to disk.
|
||||
@@ -58,16 +58,16 @@ public interface BrowserContext extends AutoCloseable {
|
||||
void offClose(Consumer<BrowserContext> handler);
|
||||
|
||||
/**
|
||||
* The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
|
||||
* also fire for popup pages. See also {@link Page#onPopup Page.onPopup()} to receive events about popups relevant to a
|
||||
* specific page.
|
||||
* The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event
|
||||
* will also fire for popup pages. See also {@link Page#onPopup Page.onPopup()} to receive events about popups relevant to
|
||||
* a specific page.
|
||||
*
|
||||
* <p> The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
|
||||
* popup with {@code window.open('http://example.com')}, this event will fire when the network request to "http://example.com" is
|
||||
* done and its response has started loading in the popup.
|
||||
* <p> The earliest moment that page is available is when it has navigated to the initial url. For example, when opening
|
||||
* a popup with {@code window.open('http://example.com')}, this event will fire when the network request to "http://example.com"
|
||||
* is done and its response has started loading in the popup.
|
||||
* <pre>{@code
|
||||
* Page newPage = context.waitForPage(() -> {
|
||||
* page.locator("a[target=_blank]").click();
|
||||
* page.getByText("open new page").click();
|
||||
* });
|
||||
* System.out.println(newPage.evaluate("location.href"));
|
||||
* }</pre>
|
||||
@@ -98,8 +98,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* Emitted when a request fails, for example by timing out. To only listen for failed requests from a particular page, use
|
||||
* {@link Page#onRequestFailed Page.onRequestFailed()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete
|
||||
* with {@link BrowserContext#onRequestFinished BrowserContext.onRequestFinished()} event and not with {@link
|
||||
* <p> <strong>NOTE:</strong> HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
|
||||
* complete with {@link BrowserContext#onRequestFinished BrowserContext.onRequestFinished()} event and not with {@link
|
||||
* BrowserContext#onRequestFailed BrowserContext.onRequestFailed()}.
|
||||
*/
|
||||
void onRequestFailed(Consumer<Request> handler);
|
||||
@@ -109,9 +109,9 @@ public interface BrowserContext extends AutoCloseable {
|
||||
void offRequestFailed(Consumer<Request> handler);
|
||||
|
||||
/**
|
||||
* Emitted when a request finishes successfully after downloading the response body. For a successful response, the
|
||||
* sequence of events is {@code request}, {@code response} and {@code requestfinished}. To listen for successful requests from a particular
|
||||
* page, use {@link Page#onRequestFinished Page.onRequestFinished()}.
|
||||
* Emitted when a request finishes successfully after downloading the response body. For a successful response,
|
||||
* the sequence of events is {@code request}, {@code response} and {@code requestfinished}. To listen for successful requests from a
|
||||
* particular page, use {@link Page#onRequestFinished Page.onRequestFinished()}.
|
||||
*/
|
||||
void onRequestFinished(Consumer<Request> handler);
|
||||
/**
|
||||
@@ -120,8 +120,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
void offRequestFinished(Consumer<Request> handler);
|
||||
|
||||
/**
|
||||
* Emitted when [response] status and headers are received for a request. For a successful response, the sequence of events
|
||||
* is {@code request}, {@code response} and {@code requestfinished}. To listen for response events from a particular page, use {@link
|
||||
* Emitted when [response] status and headers are received for a request. For a successful response, the sequence of
|
||||
* events is {@code request}, {@code response} and {@code requestfinished}. To listen for response events from a particular page, use {@link
|
||||
* Page#onResponse Page.onResponse()}.
|
||||
*/
|
||||
void onResponse(Consumer<Response> handler);
|
||||
@@ -132,14 +132,14 @@ public interface BrowserContext extends AutoCloseable {
|
||||
|
||||
class ExposeBindingOptions {
|
||||
/**
|
||||
* Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is
|
||||
* supported. When passing by value, multiple arguments are supported.
|
||||
* Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument
|
||||
* is supported. When passing by value, multiple arguments are supported.
|
||||
*/
|
||||
public Boolean handle;
|
||||
|
||||
/**
|
||||
* Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is
|
||||
* supported. When passing by value, multiple arguments are supported.
|
||||
* Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument
|
||||
* is supported. When passing by value, multiple arguments are supported.
|
||||
*/
|
||||
public ExposeBindingOptions setHandle(boolean handle) {
|
||||
this.handle = handle;
|
||||
@@ -276,8 +276,10 @@ public interface BrowserContext extends AutoCloseable {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
|
||||
* obtained via {@link BrowserContext#cookies BrowserContext.cookies()}.
|
||||
* Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can
|
||||
* be obtained via {@link BrowserContext#cookies BrowserContext.cookies()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* browserContext.addCookies(Arrays.asList(cookieObject1, cookieObject2));
|
||||
* }</pre>
|
||||
@@ -287,12 +289,14 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* Adds a script which would be evaluated in one of the following scenarios:
|
||||
* <ul>
|
||||
* <li> Whenever a page is created in the browser context or is navigated.</li>
|
||||
* <li> Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is
|
||||
* evaluated in the context of the newly attached frame.</li>
|
||||
* <li> Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script
|
||||
* is evaluated in the context of the newly attached frame.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
|
||||
* the JavaScript environment, e.g. to seed {@code Math.random}.
|
||||
* <p> The script is evaluated after the document was created but before any of its scripts were run. This is useful to
|
||||
* amend the JavaScript environment, e.g. to seed {@code Math.random}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of overriding {@code Math.random} before the page loads:
|
||||
* <pre>{@code
|
||||
@@ -310,12 +314,14 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* Adds a script which would be evaluated in one of the following scenarios:
|
||||
* <ul>
|
||||
* <li> Whenever a page is created in the browser context or is navigated.</li>
|
||||
* <li> Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is
|
||||
* evaluated in the context of the newly attached frame.</li>
|
||||
* <li> Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script
|
||||
* is evaluated in the context of the newly attached frame.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
|
||||
* the JavaScript environment, e.g. to seed {@code Math.random}.
|
||||
* <p> The script is evaluated after the document was created but before any of its scripts were run. This is useful to
|
||||
* amend the JavaScript environment, e.g. to seed {@code Math.random}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of overriding {@code Math.random} before the page loads:
|
||||
* <pre>{@code
|
||||
@@ -339,6 +345,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
void clearCookies();
|
||||
/**
|
||||
* Clears all permission overrides for the browser context.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* BrowserContext context = browser.newContext();
|
||||
* context.grantPermissions(Arrays.asList("clipboard-read"));
|
||||
@@ -354,22 +362,22 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void close();
|
||||
/**
|
||||
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
|
||||
* are returned.
|
||||
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those
|
||||
* URLs are returned.
|
||||
*/
|
||||
default List<Cookie> cookies() {
|
||||
return cookies((String) null);
|
||||
}
|
||||
/**
|
||||
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
|
||||
* are returned.
|
||||
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those
|
||||
* URLs are returned.
|
||||
*
|
||||
* @param urls Optional list of URLs.
|
||||
*/
|
||||
List<Cookie> cookies(String urls);
|
||||
/**
|
||||
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
|
||||
* are returned.
|
||||
* If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those
|
||||
* URLs are returned.
|
||||
*
|
||||
* @param urls Optional list of URLs.
|
||||
*/
|
||||
@@ -387,6 +395,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*
|
||||
* <p> See {@link Page#exposeBinding Page.exposeBinding()} for page-only version.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of exposing page URL to all frames in all pages in the context:
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.*;
|
||||
@@ -406,7 +416,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* "</script>\n" +
|
||||
* "<button onclick=\"onClick()\">Click me</button>\n" +
|
||||
* "<div></div>");
|
||||
* page.getByRole("button").click();
|
||||
* page.getByRole(AriaRole.BUTTON).click();
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
@@ -446,6 +456,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*
|
||||
* <p> See {@link Page#exposeBinding Page.exposeBinding()} for page-only version.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of exposing page URL to all frames in all pages in the context:
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.*;
|
||||
@@ -465,7 +477,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* "</script>\n" +
|
||||
* "<button onclick=\"onClick()\">Click me</button>\n" +
|
||||
* "<div></div>");
|
||||
* page.getByRole("button").click();
|
||||
* page.getByRole(AriaRole.BUTTON).click();
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
@@ -502,6 +514,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*
|
||||
* <p> See {@link Page#exposeFunction Page.exposeFunction()} for page-only version.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of adding a {@code sha256} function to all pages in the context:
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.*;
|
||||
@@ -535,7 +549,7 @@ public interface BrowserContext extends AutoCloseable {
|
||||
* "</script>\n" +
|
||||
* "<button onclick=\"onClick()\">Click me</button>\n" +
|
||||
* "<div></div>\n");
|
||||
* page.getByRole("button").click();
|
||||
* page.getByRole(AriaRole.BUTTON).click();
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
@@ -546,8 +560,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void exposeFunction(String name, FunctionCallback callback);
|
||||
/**
|
||||
* Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
|
||||
* specified.
|
||||
* Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin
|
||||
* if specified.
|
||||
*
|
||||
* @param permissions A permission or an array of permissions to grant. Permissions can be one of the following values:
|
||||
* <ul>
|
||||
@@ -572,8 +586,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
grantPermissions(permissions, null);
|
||||
}
|
||||
/**
|
||||
* Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
|
||||
* specified.
|
||||
* Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin
|
||||
* if specified.
|
||||
*
|
||||
* @param permissions A permission or an array of permissions to grant. Permissions can be one of the following values:
|
||||
* <ul>
|
||||
@@ -608,13 +622,15 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
APIRequestContext request();
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once
|
||||
* route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by Service Worker. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
* using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of a naive handler that aborts all image requests:
|
||||
* <pre>{@code
|
||||
* BrowserContext context = browser.newContext();
|
||||
@@ -660,13 +676,15 @@ public interface BrowserContext extends AutoCloseable {
|
||||
route(url, handler, null);
|
||||
}
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once
|
||||
* route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by Service Worker. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
* using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of a naive handler that aborts all image requests:
|
||||
* <pre>{@code
|
||||
* BrowserContext context = browser.newContext();
|
||||
@@ -710,13 +728,15 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void route(String url, Consumer<Route> handler, RouteOptions options);
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once
|
||||
* route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by Service Worker. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
* using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of a naive handler that aborts all image requests:
|
||||
* <pre>{@code
|
||||
* BrowserContext context = browser.newContext();
|
||||
@@ -762,13 +782,15 @@ public interface BrowserContext extends AutoCloseable {
|
||||
route(url, handler, null);
|
||||
}
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once
|
||||
* route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by Service Worker. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
* using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of a naive handler that aborts all image requests:
|
||||
* <pre>{@code
|
||||
* BrowserContext context = browser.newContext();
|
||||
@@ -812,13 +834,15 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void route(Pattern url, Consumer<Route> handler, RouteOptions options);
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once
|
||||
* route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by Service Worker. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
* using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of a naive handler that aborts all image requests:
|
||||
* <pre>{@code
|
||||
* BrowserContext context = browser.newContext();
|
||||
@@ -864,13 +888,15 @@ public interface BrowserContext extends AutoCloseable {
|
||||
route(url, handler, null);
|
||||
}
|
||||
/**
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
||||
* is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
* Routing provides the capability to modify network requests that are made by any page in the browser context. Once
|
||||
* route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#route BrowserContext.route()} will not intercept requests intercepted by Service Worker. See <a
|
||||
* href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
|
||||
* using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of a naive handler that aborts all image requests:
|
||||
* <pre>{@code
|
||||
* BrowserContext context = browser.newContext();
|
||||
@@ -969,9 +995,9 @@ public interface BrowserContext extends AutoCloseable {
|
||||
*/
|
||||
void setDefaultTimeout(double timeout);
|
||||
/**
|
||||
* The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged
|
||||
* with page-specific extra HTTP headers set with {@link Page#setExtraHTTPHeaders Page.setExtraHTTPHeaders()}. If page
|
||||
* overrides a particular header, page-specific header value will be used instead of the browser context header value.
|
||||
* The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are
|
||||
* merged with page-specific extra HTTP headers set with {@link Page#setExtraHTTPHeaders Page.setExtraHTTPHeaders()}. If
|
||||
* page overrides a particular header, page-specific header value will be used instead of the browser context header value.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> {@link BrowserContext#setExtraHTTPHeaders BrowserContext.setExtraHTTPHeaders()} does not guarantee the order of headers
|
||||
* in the outgoing requests.
|
||||
@@ -981,6 +1007,8 @@ public interface BrowserContext extends AutoCloseable {
|
||||
void setExtraHTTPHeaders(Map<String, String> headers);
|
||||
/**
|
||||
* Sets the context's geolocation. Passing {@code null} or {@code undefined} emulates position unavailable.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* browserContext.setGeolocation(new Geolocation(59.95, 30.31667));
|
||||
* }</pre>
|
||||
|
||||
@@ -22,8 +22,8 @@ import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is a
|
||||
* typical example of using Playwright to drive automation:
|
||||
* BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is
|
||||
* a typical example of using Playwright to drive automation:
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.*;
|
||||
*
|
||||
@@ -142,9 +142,9 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean devtools;
|
||||
/**
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
|
||||
* deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in
|
||||
* is closed.
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and
|
||||
* is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created
|
||||
* in is closed.
|
||||
*/
|
||||
public Path downloadsPath;
|
||||
/**
|
||||
@@ -177,8 +177,8 @@ public interface BrowserType {
|
||||
/**
|
||||
* Whether to run browser in headless mode. More details for <a
|
||||
* href="https://developers.google.com/web/updates/2017/04/headless-chrome">Chromium</a> and <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode">Firefox</a>. Defaults to {@code true} unless the
|
||||
* {@code devtools} option is {@code true}.
|
||||
* href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode">Firefox</a>. Defaults to {@code true} unless
|
||||
* the {@code devtools} option is {@code true}.
|
||||
*/
|
||||
public Boolean headless;
|
||||
/**
|
||||
@@ -200,8 +200,8 @@ public interface BrowserType {
|
||||
*/
|
||||
public Double slowMo;
|
||||
/**
|
||||
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to
|
||||
* disable timeout.
|
||||
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0}
|
||||
* to disable timeout.
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
@@ -252,9 +252,9 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
|
||||
* deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in
|
||||
* is closed.
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and
|
||||
* is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created
|
||||
* in is closed.
|
||||
*/
|
||||
public LaunchOptions setDownloadsPath(Path downloadsPath) {
|
||||
this.downloadsPath = downloadsPath;
|
||||
@@ -308,8 +308,8 @@ public interface BrowserType {
|
||||
/**
|
||||
* Whether to run browser in headless mode. More details for <a
|
||||
* href="https://developers.google.com/web/updates/2017/04/headless-chrome">Chromium</a> and <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode">Firefox</a>. Defaults to {@code true} unless the
|
||||
* {@code devtools} option is {@code true}.
|
||||
* href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode">Firefox</a>. Defaults to {@code true} unless
|
||||
* the {@code devtools} option is {@code true}.
|
||||
*/
|
||||
public LaunchOptions setHeadless(boolean headless) {
|
||||
this.headless = headless;
|
||||
@@ -352,8 +352,8 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to
|
||||
* disable timeout.
|
||||
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0}
|
||||
* to disable timeout.
|
||||
*/
|
||||
public LaunchOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -406,8 +406,8 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean chromiumSandbox;
|
||||
/**
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code "no-preference"}. See
|
||||
* {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code "no-preference"}.
|
||||
* See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
* Defaults to {@code "light"}.
|
||||
*/
|
||||
public Optional<ColorScheme> colorScheme;
|
||||
@@ -421,9 +421,9 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean devtools;
|
||||
/**
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
|
||||
* deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in
|
||||
* is closed.
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and
|
||||
* is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created
|
||||
* in is closed.
|
||||
*/
|
||||
public Path downloadsPath;
|
||||
/**
|
||||
@@ -465,8 +465,8 @@ public interface BrowserType {
|
||||
/**
|
||||
* Whether to run browser in headless mode. More details for <a
|
||||
* href="https://developers.google.com/web/updates/2017/04/headless-chrome">Chromium</a> and <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode">Firefox</a>. Defaults to {@code true} unless the
|
||||
* {@code devtools} option is {@code true}.
|
||||
* href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode">Firefox</a>. Defaults to {@code true} unless
|
||||
* the {@code devtools} option is {@code true}.
|
||||
*/
|
||||
public Boolean headless;
|
||||
/**
|
||||
@@ -488,8 +488,8 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean ignoreHTTPSErrors;
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not supported
|
||||
* in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
*/
|
||||
public Boolean isMobile;
|
||||
/**
|
||||
@@ -497,8 +497,8 @@ public interface BrowserType {
|
||||
*/
|
||||
public Boolean javaScriptEnabled;
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value, {@code Accept-Language}
|
||||
* request header value as well as number and date formatting rules.
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public String locale;
|
||||
/**
|
||||
@@ -572,14 +572,14 @@ public interface BrowserType {
|
||||
*/
|
||||
public Double slowMo;
|
||||
/**
|
||||
* If specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. See {@code Locator} to learn
|
||||
* more about the strict mode.
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
*/
|
||||
public Boolean strictSelectors;
|
||||
/**
|
||||
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to
|
||||
* disable timeout.
|
||||
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0}
|
||||
* to disable timeout.
|
||||
*/
|
||||
public Double timeout;
|
||||
/**
|
||||
@@ -667,8 +667,8 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code "no-preference"}. See
|
||||
* {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
* Emulates {@code "prefers-colors-scheme"} media feature, supported values are {@code "light"}, {@code "dark"}, {@code "no-preference"}.
|
||||
* See {@link Page#emulateMedia Page.emulateMedia()} for more details. Passing {@code null} resets emulation to system defaults.
|
||||
* Defaults to {@code "light"}.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setColorScheme(ColorScheme colorScheme) {
|
||||
@@ -691,9 +691,9 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
|
||||
* deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in
|
||||
* is closed.
|
||||
* If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and
|
||||
* is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created
|
||||
* in is closed.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setDownloadsPath(Path downloadsPath) {
|
||||
this.downloadsPath = downloadsPath;
|
||||
@@ -768,8 +768,8 @@ public interface BrowserType {
|
||||
/**
|
||||
* Whether to run browser in headless mode. More details for <a
|
||||
* href="https://developers.google.com/web/updates/2017/04/headless-chrome">Chromium</a> and <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode">Firefox</a>. Defaults to {@code true} unless the
|
||||
* {@code devtools} option is {@code true}.
|
||||
* href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode">Firefox</a>. Defaults to {@code true} unless
|
||||
* the {@code devtools} option is {@code true}.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setHeadless(boolean headless) {
|
||||
this.headless = headless;
|
||||
@@ -812,8 +812,8 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not supported
|
||||
* in Firefox.
|
||||
* Whether the {@code meta viewport} tag is taken into account and touch events are enabled. Defaults to {@code false}. Not
|
||||
* supported in Firefox.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setIsMobile(boolean isMobile) {
|
||||
this.isMobile = isMobile;
|
||||
@@ -827,8 +827,8 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value, {@code Accept-Language}
|
||||
* request header value as well as number and date formatting rules.
|
||||
* Specify user locale, for example {@code en-GB}, {@code de-DE}, etc. Locale will affect {@code navigator.language} value,
|
||||
* {@code Accept-Language} request header value as well as number and date formatting rules.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
@@ -972,17 +972,17 @@ public interface BrowserType {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. See {@code Locator} to learn
|
||||
* more about the strict mode.
|
||||
* If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
|
||||
* that imply single target DOM element will throw when more than one element matches the selector. This option does not
|
||||
* affect any Locator APIs (Locators are always strict). See {@code Locator} to learn more about the strict mode.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setStrictSelectors(boolean strictSelectors) {
|
||||
this.strictSelectors = strictSelectors;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to
|
||||
* disable timeout.
|
||||
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0}
|
||||
* to disable timeout.
|
||||
*/
|
||||
public LaunchPersistentContextOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -1049,6 +1049,8 @@ public interface BrowserType {
|
||||
* <p> The default browser context is accessible via {@link Browser#contexts Browser.contexts()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Browser browser = playwright.chromium().connectOverCDP("http://localhost:9222");
|
||||
* BrowserContext defaultContext = browser.contexts().get(0);
|
||||
@@ -1067,6 +1069,8 @@ public interface BrowserType {
|
||||
* <p> The default browser context is accessible via {@link Browser#contexts Browser.contexts()}.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Browser browser = playwright.chromium().connectOverCDP("http://localhost:9222");
|
||||
* BrowserContext defaultContext = browser.contexts().get(0);
|
||||
@@ -1084,6 +1088,8 @@ public interface BrowserType {
|
||||
/**
|
||||
* Returns the browser instance.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> You can use {@code ignoreDefaultArgs} to filter out {@code --mute-audio} from default arguments:
|
||||
* <pre>{@code
|
||||
* // Or "firefox" or "webkit".
|
||||
@@ -1107,8 +1113,8 @@ public interface BrowserType {
|
||||
* video playback. See <a
|
||||
* href="https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/">this article</a> for
|
||||
* other differences between Chromium and Chrome. <a
|
||||
* href="https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md">This article</a>
|
||||
* describes some differences for Linux users.
|
||||
* href="https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md">This
|
||||
* article</a> describes some differences for Linux users.
|
||||
*/
|
||||
default Browser launch() {
|
||||
return launch(null);
|
||||
@@ -1116,6 +1122,8 @@ public interface BrowserType {
|
||||
/**
|
||||
* Returns the browser instance.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> You can use {@code ignoreDefaultArgs} to filter out {@code --mute-audio} from default arguments:
|
||||
* <pre>{@code
|
||||
* // Or "firefox" or "webkit".
|
||||
@@ -1139,8 +1147,8 @@ public interface BrowserType {
|
||||
* video playback. See <a
|
||||
* href="https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/">this article</a> for
|
||||
* other differences between Chromium and Chrome. <a
|
||||
* href="https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md">This article</a>
|
||||
* describes some differences for Linux users.
|
||||
* href="https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md">This
|
||||
* article</a> describes some differences for Linux users.
|
||||
*/
|
||||
Browser launch(LaunchOptions options);
|
||||
/**
|
||||
|
||||
@@ -56,9 +56,9 @@ public interface ConsoleMessage {
|
||||
*/
|
||||
String text();
|
||||
/**
|
||||
* One of the following values: {@code "log"}, {@code "debug"}, {@code "info"}, {@code "error"}, {@code "warning"}, {@code "dir"}, {@code "dirxml"}, {@code "table"},
|
||||
* {@code "trace"}, {@code "clear"}, {@code "startGroup"}, {@code "startGroupCollapsed"}, {@code "endGroup"}, {@code "assert"}, {@code "profile"}, {@code "profileEnd"},
|
||||
* {@code "count"}, {@code "timeEnd"}.
|
||||
* One of the following values: {@code "log"}, {@code "debug"}, {@code "info"}, {@code "error"}, {@code "warning"}, {@code "dir"}, {@code "dirxml"},
|
||||
* {@code "table"}, {@code "trace"}, {@code "clear"}, {@code "startGroup"}, {@code "startGroupCollapsed"}, {@code "endGroup"}, {@code "assert"}, {@code "profile"},
|
||||
* {@code "profileEnd"}, {@code "count"}, {@code "timeEnd"}.
|
||||
*/
|
||||
String type();
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ public interface Download {
|
||||
* Returns path to the downloaded file in case of successful download. The method will wait for the download to finish if
|
||||
* necessary. The method throws when connected remotely.
|
||||
*
|
||||
* <p> Note that the download's file name is a random GUID, use {@link Download#suggestedFilename Download.suggestedFilename()}
|
||||
* to get suggested file name.
|
||||
* <p> Note that the download's file name is a random GUID, use {@link Download#suggestedFilename
|
||||
* Download.suggestedFilename()} to get suggested file name.
|
||||
*/
|
||||
Path path();
|
||||
/**
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -22,38 +22,38 @@ import java.nio.file.Path;
|
||||
/**
|
||||
* {@code FileChooser} objects are dispatched by the page in the {@link Page#onFileChooser Page.onFileChooser()} event.
|
||||
* <pre>{@code
|
||||
* FileChooser fileChooser = page.waitForFileChooser(() -> page.getByText("Upload").click());
|
||||
* FileChooser fileChooser = page.waitForFileChooser(() -> page.getByText("Upload file").click());
|
||||
* fileChooser.setFiles(Paths.get("myfile.pdf"));
|
||||
* }</pre>
|
||||
*/
|
||||
public interface FileChooser {
|
||||
class SetFilesOptions {
|
||||
/**
|
||||
* Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
|
||||
* opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
|
||||
* inaccessible pages. Defaults to {@code false}.
|
||||
* Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You
|
||||
* can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as
|
||||
* navigating to inaccessible pages. Defaults to {@code false}.
|
||||
*/
|
||||
public Boolean noWaitAfter;
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by
|
||||
* using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link Page#setDefaultTimeout
|
||||
* Page.setDefaultTimeout()} methods.
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed
|
||||
* by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public Double timeout;
|
||||
|
||||
/**
|
||||
* Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
|
||||
* opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
|
||||
* inaccessible pages. Defaults to {@code false}.
|
||||
* Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You
|
||||
* can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as
|
||||
* navigating to inaccessible pages. Defaults to {@code false}.
|
||||
*/
|
||||
public SetFilesOptions setNoWaitAfter(boolean noWaitAfter) {
|
||||
this.noWaitAfter = noWaitAfter;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by
|
||||
* using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link Page#setDefaultTimeout
|
||||
* Page.setDefaultTimeout()} methods.
|
||||
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed
|
||||
* by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link
|
||||
* Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
|
||||
*/
|
||||
public SetFilesOptions setTimeout(double timeout) {
|
||||
this.timeout = timeout;
|
||||
@@ -73,51 +73,51 @@ public interface FileChooser {
|
||||
*/
|
||||
Page page();
|
||||
/**
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths, then
|
||||
* they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths,
|
||||
* then they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
*/
|
||||
default void setFiles(Path files) {
|
||||
setFiles(files, null);
|
||||
}
|
||||
/**
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths, then
|
||||
* they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths,
|
||||
* then they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
*/
|
||||
void setFiles(Path files, SetFilesOptions options);
|
||||
/**
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths, then
|
||||
* they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths,
|
||||
* then they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
*/
|
||||
default void setFiles(Path[] files) {
|
||||
setFiles(files, null);
|
||||
}
|
||||
/**
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths, then
|
||||
* they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths,
|
||||
* then they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
*/
|
||||
void setFiles(Path[] files, SetFilesOptions options);
|
||||
/**
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths, then
|
||||
* they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths,
|
||||
* then they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
*/
|
||||
default void setFiles(FilePayload files) {
|
||||
setFiles(files, null);
|
||||
}
|
||||
/**
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths, then
|
||||
* they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths,
|
||||
* then they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
*/
|
||||
void setFiles(FilePayload files, SetFilesOptions options);
|
||||
/**
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths, then
|
||||
* they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths,
|
||||
* then they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
*/
|
||||
default void setFiles(FilePayload[] files) {
|
||||
setFiles(files, null);
|
||||
}
|
||||
/**
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths, then
|
||||
* they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
* Sets the value of the file input this chooser is associated with. If some of the {@code filePaths} are relative paths,
|
||||
* then they are resolved relative to the current working directory. For empty array, clears the selected files.
|
||||
*/
|
||||
void setFiles(FilePayload[] files, SetFilesOptions options);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -34,10 +34,10 @@ import java.util.regex.Pattern;
|
||||
* a given selector.
|
||||
* <pre>{@code
|
||||
* // Throws if there are several frames in DOM:
|
||||
* page.frame_locator(".result-frame").getByRole("button").click();
|
||||
* page.frame_locator(".result-frame").getByRole(AriaRole.BUTTON).click();
|
||||
*
|
||||
* // Works because we explicitly tell locator to pick the first frame:
|
||||
* page.frame_locator(".result-frame").first().getByRole("button").click();
|
||||
* page.frame_locator(".result-frame").first().getByRole(AriaRole.BUTTON).click();
|
||||
* }</pre>
|
||||
*
|
||||
* <p> **Converting Locator to FrameLocator**
|
||||
@@ -285,8 +285,8 @@ public interface FrameLocator {
|
||||
}
|
||||
class LocatorOptions {
|
||||
/**
|
||||
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
|
||||
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
|
||||
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer
|
||||
* one. For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
@@ -299,8 +299,8 @@ public interface FrameLocator {
|
||||
public Object hasText;
|
||||
|
||||
/**
|
||||
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer one.
|
||||
* For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
|
||||
* Matches elements containing an element that matches an inner locator. Inner locator is queried against the outer
|
||||
* one. For example, {@code article} that has {@code text=Playwright} matches {@code <article><div>Playwright</div></article>}.
|
||||
*
|
||||
* <p> Note that outer and inner locators must belong to the same frame. Inner locator must not contain {@code FrameLocator}s.
|
||||
*/
|
||||
@@ -335,8 +335,7 @@ public interface FrameLocator {
|
||||
* When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in
|
||||
* that iframe.
|
||||
*
|
||||
* @param selector A selector to use when resolving DOM element. See <a href="https://playwright.dev/java/docs/selectors">working with
|
||||
* selectors</a> for more details.
|
||||
* @param selector A selector to use when resolving DOM element.
|
||||
*/
|
||||
FrameLocator frameLocator(String selector);
|
||||
/**
|
||||
@@ -470,6 +469,13 @@ public interface FrameLocator {
|
||||
* @param testId Id to locate the element by.
|
||||
*/
|
||||
Locator getByTestId(String testId);
|
||||
/**
|
||||
* Locate element by the test id. By default, the {@code data-testid} attribute is used as a test id. Use {@link
|
||||
* Selectors#setTestIdAttribute Selectors.setTestIdAttribute()} to configure a different test id attribute if necessary.
|
||||
*
|
||||
* @param testId Id to locate the element by.
|
||||
*/
|
||||
Locator getByTestId(Pattern testId);
|
||||
/**
|
||||
* Allows locating elements that contain given text. Consider the following DOM structure:
|
||||
*
|
||||
@@ -644,8 +650,7 @@ public interface FrameLocator {
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
* @param selector A selector to use when resolving DOM element. See <a href="https://playwright.dev/java/docs/selectors">working with
|
||||
* selectors</a> for more details.
|
||||
* @param selector A selector to use when resolving DOM element.
|
||||
*/
|
||||
default Locator locator(String selector) {
|
||||
return locator(selector, null);
|
||||
@@ -656,8 +661,7 @@ public interface FrameLocator {
|
||||
*
|
||||
* <p> <a href="https://playwright.dev/java/docs/locators">Learn more about locators</a>.
|
||||
*
|
||||
* @param selector A selector to use when resolving DOM element. See <a href="https://playwright.dev/java/docs/selectors">working with
|
||||
* selectors</a> for more details.
|
||||
* @param selector A selector to use when resolving DOM element.
|
||||
*/
|
||||
Locator locator(String selector, LocatorOptions options);
|
||||
/**
|
||||
|
||||
@@ -51,7 +51,7 @@ public interface JSHandle {
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, then
|
||||
* {@code handle.evaluate} would wait for the promise to resolve and return its value.
|
||||
*
|
||||
* <p> Examples:
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* ElementHandle tweetHandle = page.querySelector(".tweet .retweets");
|
||||
* assertEquals("10 retweets", tweetHandle.evaluate("node => node.innerText"));
|
||||
@@ -72,7 +72,7 @@ public interface JSHandle {
|
||||
* href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise'>Promise</a>, then
|
||||
* {@code handle.evaluate} would wait for the promise to resolve and return its value.
|
||||
*
|
||||
* <p> Examples:
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* ElementHandle tweetHandle = page.querySelector(".tweet .retweets");
|
||||
* assertEquals("10 retweets", tweetHandle.evaluate("node => node.innerText"));
|
||||
@@ -124,6 +124,8 @@ public interface JSHandle {
|
||||
JSHandle evaluateHandle(String expression, Object arg);
|
||||
/**
|
||||
* The method returns a map with **own property names** as keys and JSHandle instances for the property values.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* JSHandle handle = page.evaluateHandle("() => ({window, document}"););
|
||||
* Map<String, JSHandle> properties = handle.getProperties();
|
||||
@@ -142,8 +144,8 @@ public interface JSHandle {
|
||||
/**
|
||||
* Returns a JSON representation of the object. If the object has a {@code toJSON} function, it **will not be called**.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> The method will return an empty JSON object if the referenced object is not stringifiable. It will throw an error if the
|
||||
* object has circular references.
|
||||
* <p> <strong>NOTE:</strong> The method will return an empty JSON object if the referenced object is not stringifiable. It will throw an error if
|
||||
* the object has circular references.
|
||||
*/
|
||||
Object jsonValue();
|
||||
}
|
||||
|
||||
@@ -89,8 +89,9 @@ public interface Keyboard {
|
||||
* character to generate the text for. A superset of the {@code key} values can be found <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">here</a>. Examples of the keys are:
|
||||
*
|
||||
* <p> {@code F1} - {@code F12}, {@code Digit0}- {@code Digit9}, {@code KeyA}- {@code KeyZ}, {@code Backquote}, {@code Minus}, {@code Equal}, {@code Backslash}, {@code Backspace}, {@code Tab},
|
||||
* {@code Delete}, {@code Escape}, {@code ArrowDown}, {@code End}, {@code Enter}, {@code Home}, {@code Insert}, {@code PageDown}, {@code PageUp}, {@code ArrowRight}, {@code ArrowUp}, etc.
|
||||
* <p> {@code F1} - {@code F12}, {@code Digit0}- {@code Digit9}, {@code KeyA}- {@code KeyZ}, {@code Backquote}, {@code Minus}, {@code Equal}, {@code Backslash}, {@code Backspace},
|
||||
* {@code Tab}, {@code Delete}, {@code Escape}, {@code ArrowDown}, {@code End}, {@code Enter}, {@code Home}, {@code Insert}, {@code PageDown}, {@code PageUp}, {@code ArrowRight}, {@code ArrowUp},
|
||||
* etc.
|
||||
*
|
||||
* <p> Following modification shortcuts are also supported: {@code Shift}, {@code Control}, {@code Alt}, {@code Meta}, {@code ShiftLeft}.
|
||||
*
|
||||
@@ -113,6 +114,8 @@ public interface Keyboard {
|
||||
void down(String key);
|
||||
/**
|
||||
* Dispatches only {@code input} event, does not emit the {@code keydown}, {@code keyup} or {@code keypress} events.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* page.keyboard().insertText("嗨");
|
||||
* }</pre>
|
||||
@@ -128,8 +131,9 @@ public interface Keyboard {
|
||||
* character to generate the text for. A superset of the {@code key} values can be found <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">here</a>. Examples of the keys are:
|
||||
*
|
||||
* <p> {@code F1} - {@code F12}, {@code Digit0}- {@code Digit9}, {@code KeyA}- {@code KeyZ}, {@code Backquote}, {@code Minus}, {@code Equal}, {@code Backslash}, {@code Backspace}, {@code Tab},
|
||||
* {@code Delete}, {@code Escape}, {@code ArrowDown}, {@code End}, {@code Enter}, {@code Home}, {@code Insert}, {@code PageDown}, {@code PageUp}, {@code ArrowRight}, {@code ArrowUp}, etc.
|
||||
* <p> {@code F1} - {@code F12}, {@code Digit0}- {@code Digit9}, {@code KeyA}- {@code KeyZ}, {@code Backquote}, {@code Minus}, {@code Equal}, {@code Backslash}, {@code Backspace},
|
||||
* {@code Tab}, {@code Delete}, {@code Escape}, {@code ArrowDown}, {@code End}, {@code Enter}, {@code Home}, {@code Insert}, {@code PageDown}, {@code PageUp}, {@code ArrowRight}, {@code ArrowUp},
|
||||
* etc.
|
||||
*
|
||||
* <p> Following modification shortcuts are also supported: {@code Shift}, {@code Control}, {@code Alt}, {@code Meta}, {@code ShiftLeft}.
|
||||
*
|
||||
@@ -138,8 +142,10 @@ public interface Keyboard {
|
||||
* <p> If {@code key} is a single character, it is case-sensitive, so the values {@code a} and {@code A} will generate different respective
|
||||
* texts.
|
||||
*
|
||||
* <p> Shortcuts such as {@code key: "Control+o"} or {@code key: "Control+Shift+T"} are supported as well. When specified with the
|
||||
* modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
* <p> Shortcuts such as {@code key: "Control+o"} or {@code key: "Control+Shift+T"} are supported as well. When specified with
|
||||
* the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Page page = browser.newPage();
|
||||
* page.navigate("https://keycode.info");
|
||||
@@ -165,8 +171,9 @@ public interface Keyboard {
|
||||
* character to generate the text for. A superset of the {@code key} values can be found <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">here</a>. Examples of the keys are:
|
||||
*
|
||||
* <p> {@code F1} - {@code F12}, {@code Digit0}- {@code Digit9}, {@code KeyA}- {@code KeyZ}, {@code Backquote}, {@code Minus}, {@code Equal}, {@code Backslash}, {@code Backspace}, {@code Tab},
|
||||
* {@code Delete}, {@code Escape}, {@code ArrowDown}, {@code End}, {@code Enter}, {@code Home}, {@code Insert}, {@code PageDown}, {@code PageUp}, {@code ArrowRight}, {@code ArrowUp}, etc.
|
||||
* <p> {@code F1} - {@code F12}, {@code Digit0}- {@code Digit9}, {@code KeyA}- {@code KeyZ}, {@code Backquote}, {@code Minus}, {@code Equal}, {@code Backslash}, {@code Backspace},
|
||||
* {@code Tab}, {@code Delete}, {@code Escape}, {@code ArrowDown}, {@code End}, {@code Enter}, {@code Home}, {@code Insert}, {@code PageDown}, {@code PageUp}, {@code ArrowRight}, {@code ArrowUp},
|
||||
* etc.
|
||||
*
|
||||
* <p> Following modification shortcuts are also supported: {@code Shift}, {@code Control}, {@code Alt}, {@code Meta}, {@code ShiftLeft}.
|
||||
*
|
||||
@@ -175,8 +182,10 @@ public interface Keyboard {
|
||||
* <p> If {@code key} is a single character, it is case-sensitive, so the values {@code a} and {@code A} will generate different respective
|
||||
* texts.
|
||||
*
|
||||
* <p> Shortcuts such as {@code key: "Control+o"} or {@code key: "Control+Shift+T"} are supported as well. When specified with the
|
||||
* modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
* <p> Shortcuts such as {@code key: "Control+o"} or {@code key: "Control+Shift+T"} are supported as well. When specified with
|
||||
* the modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* Page page = browser.newPage();
|
||||
* page.navigate("https://keycode.info");
|
||||
@@ -198,6 +207,8 @@ public interface Keyboard {
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Types instantly
|
||||
* page.keyboard().type("Hello");
|
||||
@@ -218,6 +229,8 @@ public interface Keyboard {
|
||||
* Sends a {@code keydown}, {@code keypress}/{@code input}, and {@code keyup} event for each character in the text.
|
||||
*
|
||||
* <p> To press a special key, like {@code Control} or {@code ArrowDown}, use {@link Keyboard#press Keyboard.press()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* // Types instantly
|
||||
* page.keyboard().type("Hello");
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -20,8 +20,8 @@ import com.microsoft.playwright.impl.PlaywrightImpl;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright
|
||||
* to drive automation:
|
||||
* Playwright module provides a method to launch a browser instance. The following is a typical example of using
|
||||
* Playwright to drive automation:
|
||||
* <pre>{@code
|
||||
* import com.microsoft.playwright.*;
|
||||
*
|
||||
@@ -70,7 +70,7 @@ public interface Playwright extends AutoCloseable {
|
||||
APIRequest request();
|
||||
/**
|
||||
* Selectors can be used to install custom selector engines. See <a
|
||||
* href="https://playwright.dev/java/docs/selectors">Working with selectors</a> for more information.
|
||||
* href="https://playwright.dev/java/docs/extensibility">extensibility</a> for more information.
|
||||
*/
|
||||
Selectors selectors();
|
||||
/**
|
||||
|
||||
@@ -28,14 +28,14 @@ import java.util.*;
|
||||
* complete.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> If request fails at some point, then instead of {@code "requestfinished"} event (and possibly instead of 'response' event),
|
||||
* the {@link Page#onRequestFailed Page.onRequestFailed()} event is emitted.
|
||||
* <p> If request fails at some point, then instead of {@code "requestfinished"} event (and possibly instead of 'response'
|
||||
* event), the {@link Page#onRequestFailed Page.onRequestFailed()} event is emitted.
|
||||
*
|
||||
* <p> <strong>NOTE:</strong> HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete
|
||||
* with {@code "requestfinished"} event.
|
||||
* <p> <strong>NOTE:</strong> HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
|
||||
* complete with {@code "requestfinished"} event.
|
||||
*
|
||||
* <p> If request gets a 'redirect' response, the request is successfully finished with the {@code requestfinished} event, and a new
|
||||
* request is issued to a redirected url.
|
||||
* <p> If request gets a 'redirect' response, the request is successfully finished with the {@code requestfinished} event, and a
|
||||
* new request is issued to a redirected url.
|
||||
*/
|
||||
public interface Request {
|
||||
/**
|
||||
@@ -45,6 +45,8 @@ public interface Request {
|
||||
/**
|
||||
* The method returns {@code null} unless this request has failed, as reported by {@code requestfailed} event.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> Example of logging of all the failed requests:
|
||||
* <pre>{@code
|
||||
* page.onRequestFailed(request -> {
|
||||
@@ -94,9 +96,11 @@ public interface Request {
|
||||
/**
|
||||
* Request that was redirected by the server to this one, if any.
|
||||
*
|
||||
* <p> When the server responds with a redirect, Playwright creates a new {@code Request} object. The two requests are connected by
|
||||
* {@code redirectedFrom()} and {@code redirectedTo()} methods. When multiple server redirects has happened, it is possible to
|
||||
* construct the whole redirect chain by repeatedly calling {@code redirectedFrom()}.
|
||||
* <p> When the server responds with a redirect, Playwright creates a new {@code Request} object. The two requests are connected
|
||||
* by {@code redirectedFrom()} and {@code redirectedTo()} methods. When multiple server redirects has happened, it is possible
|
||||
* to construct the whole redirect chain by repeatedly calling {@code redirectedFrom()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, if the website {@code http://example.com} redirects to {@code https://example.com}:
|
||||
* <pre>{@code
|
||||
@@ -114,6 +118,8 @@ public interface Request {
|
||||
/**
|
||||
* New request issued by the browser if the server responded with redirect.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> This method is the opposite of {@link Request#redirectedFrom Request.redirectedFrom()}:
|
||||
* <pre>{@code
|
||||
* System.out.println(request.redirectedFrom().redirectedTo() == request); // true
|
||||
@@ -121,9 +127,9 @@ public interface Request {
|
||||
*/
|
||||
Request redirectedTo();
|
||||
/**
|
||||
* Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the
|
||||
* following: {@code document}, {@code stylesheet}, {@code image}, {@code media}, {@code font}, {@code script}, {@code texttrack}, {@code xhr}, {@code fetch}, {@code eventsource},
|
||||
* {@code websocket}, {@code manifest}, {@code other}.
|
||||
* Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of
|
||||
* the following: {@code document}, {@code stylesheet}, {@code image}, {@code media}, {@code font}, {@code script}, {@code texttrack}, {@code xhr}, {@code fetch},
|
||||
* {@code eventsource}, {@code websocket}, {@code manifest}, {@code other}.
|
||||
*/
|
||||
String resourceType();
|
||||
/**
|
||||
@@ -135,9 +141,11 @@ public interface Request {
|
||||
*/
|
||||
Sizes sizes();
|
||||
/**
|
||||
* Returns resource timing information for given request. Most of the timing values become available upon the response,
|
||||
* {@code responseEnd} becomes available when request finishes. Find more information at <a
|
||||
* Returns resource timing information for given request. Most of the timing values become available upon the
|
||||
* response, {@code responseEnd} becomes available when request finishes. Find more information at <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming">Resource Timing API</a>.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* page.onRequestFinished(request -> {
|
||||
* Timing timing = request.timing();
|
||||
|
||||
@@ -32,11 +32,11 @@ public interface Route {
|
||||
*/
|
||||
public Map<String, String> headers;
|
||||
/**
|
||||
* If set changes the request method (e.g. GET or POST)
|
||||
* If set changes the request method (e.g. GET or POST).
|
||||
*/
|
||||
public String method;
|
||||
/**
|
||||
* If set changes the post data of request
|
||||
* If set changes the post data of request.
|
||||
*/
|
||||
public Object postData;
|
||||
/**
|
||||
@@ -52,21 +52,21 @@ public interface Route {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the request method (e.g. GET or POST)
|
||||
* If set changes the request method (e.g. GET or POST).
|
||||
*/
|
||||
public ResumeOptions setMethod(String method) {
|
||||
this.method = method;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the post data of request
|
||||
* If set changes the post data of request.
|
||||
*/
|
||||
public ResumeOptions setPostData(String postData) {
|
||||
this.postData = postData;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the post data of request
|
||||
* If set changes the post data of request.
|
||||
*/
|
||||
public ResumeOptions setPostData(byte[] postData) {
|
||||
this.postData = postData;
|
||||
@@ -86,11 +86,11 @@ public interface Route {
|
||||
*/
|
||||
public Map<String, String> headers;
|
||||
/**
|
||||
* If set changes the request method (e.g. GET or POST)
|
||||
* If set changes the request method (e.g. GET or POST).
|
||||
*/
|
||||
public String method;
|
||||
/**
|
||||
* If set changes the post data of request
|
||||
* If set changes the post data of request.
|
||||
*/
|
||||
public Object postData;
|
||||
/**
|
||||
@@ -107,21 +107,21 @@ public interface Route {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the request method (e.g. GET or POST)
|
||||
* If set changes the request method (e.g. GET or POST).
|
||||
*/
|
||||
public FallbackOptions setMethod(String method) {
|
||||
this.method = method;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the post data of request
|
||||
* If set changes the post data of request.
|
||||
*/
|
||||
public FallbackOptions setPostData(String postData) {
|
||||
this.postData = postData;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the post data of request
|
||||
* If set changes the post data of request.
|
||||
*/
|
||||
public FallbackOptions setPostData(byte[] postData) {
|
||||
this.postData = postData;
|
||||
@@ -136,6 +136,60 @@ public interface Route {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class FetchOptions {
|
||||
/**
|
||||
* If set changes the request HTTP headers. Header values will be converted to a string.
|
||||
*/
|
||||
public Map<String, String> headers;
|
||||
/**
|
||||
* If set changes the request method (e.g. GET or POST).
|
||||
*/
|
||||
public String method;
|
||||
/**
|
||||
* If set changes the post data of request.
|
||||
*/
|
||||
public Object postData;
|
||||
/**
|
||||
* If set changes the request URL. New URL must have same protocol as original one.
|
||||
*/
|
||||
public String url;
|
||||
|
||||
/**
|
||||
* If set changes the request HTTP headers. Header values will be converted to a string.
|
||||
*/
|
||||
public FetchOptions setHeaders(Map<String, String> headers) {
|
||||
this.headers = headers;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the request method (e.g. GET or POST).
|
||||
*/
|
||||
public FetchOptions setMethod(String method) {
|
||||
this.method = method;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the post data of request.
|
||||
*/
|
||||
public FetchOptions setPostData(String postData) {
|
||||
this.postData = postData;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the post data of request.
|
||||
*/
|
||||
public FetchOptions setPostData(byte[] postData) {
|
||||
this.postData = postData;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If set changes the request URL. New URL must have same protocol as original one.
|
||||
*/
|
||||
public FetchOptions setUrl(String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class FulfillOptions {
|
||||
/**
|
||||
* Optional response body as text.
|
||||
@@ -154,8 +208,8 @@ public interface Route {
|
||||
*/
|
||||
public Map<String, String> headers;
|
||||
/**
|
||||
* File path to respond with. The content type will be inferred from file extension. If {@code path} is a relative path, then it
|
||||
* is resolved relative to the current working directory.
|
||||
* File path to respond with. The content type will be inferred from file extension. If {@code path} is a relative path, then
|
||||
* it is resolved relative to the current working directory.
|
||||
*/
|
||||
public Path path;
|
||||
/**
|
||||
@@ -197,8 +251,8 @@ public interface Route {
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* File path to respond with. The content type will be inferred from file extension. If {@code path} is a relative path, then it
|
||||
* is resolved relative to the current working directory.
|
||||
* File path to respond with. The content type will be inferred from file extension. If {@code path} is a relative path, then
|
||||
* it is resolved relative to the current working directory.
|
||||
*/
|
||||
public FulfillOptions setPath(Path path) {
|
||||
this.path = path;
|
||||
@@ -252,6 +306,8 @@ public interface Route {
|
||||
void abort(String errorCode);
|
||||
/**
|
||||
* Continues route's request with optional overrides.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* page.route("**\/*", route -> {
|
||||
* // Override headers
|
||||
@@ -267,6 +323,8 @@ public interface Route {
|
||||
}
|
||||
/**
|
||||
* Continues route's request with optional overrides.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* page.route("**\/*", route -> {
|
||||
* // Override headers
|
||||
@@ -283,6 +341,8 @@ public interface Route {
|
||||
* registered route can always override all the previous ones. In the example below, request will be handled by the
|
||||
* bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first
|
||||
* registered route.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* page.route("**\/*", route -> {
|
||||
* // Runs last.
|
||||
@@ -344,6 +404,8 @@ public interface Route {
|
||||
* registered route can always override all the previous ones. In the example below, request will be handled by the
|
||||
* bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first
|
||||
* registered route.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* page.route("**\/*", route -> {
|
||||
* // Runs last.
|
||||
@@ -398,9 +460,49 @@ public interface Route {
|
||||
* }</pre>
|
||||
*/
|
||||
void fallback(FallbackOptions options);
|
||||
/**
|
||||
* Performs the request and fetches result without fulfilling it, so that the response could be modified and then
|
||||
* fulfilled.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* page.route("https://dog.ceo/api/breeds/list/all", route -> {
|
||||
* APIResponse response = route.fetch();
|
||||
* JsonObject json = new Gson().fromJson(response.text(), JsonObject.class);
|
||||
* JsonObject message = itemObj.get("json").getAsJsonObject();
|
||||
* message.set("big_red_dog", new JsonArray());
|
||||
* route.fulfill(new Route.FulfillOptions()
|
||||
* .setResponse(response)
|
||||
* .setBody(json.toString()));
|
||||
* });
|
||||
* }</pre>
|
||||
*/
|
||||
default APIResponse fetch() {
|
||||
return fetch(null);
|
||||
}
|
||||
/**
|
||||
* Performs the request and fetches result without fulfilling it, so that the response could be modified and then
|
||||
* fulfilled.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* page.route("https://dog.ceo/api/breeds/list/all", route -> {
|
||||
* APIResponse response = route.fetch();
|
||||
* JsonObject json = new Gson().fromJson(response.text(), JsonObject.class);
|
||||
* JsonObject message = itemObj.get("json").getAsJsonObject();
|
||||
* message.set("big_red_dog", new JsonArray());
|
||||
* route.fulfill(new Route.FulfillOptions()
|
||||
* .setResponse(response)
|
||||
* .setBody(json.toString()));
|
||||
* });
|
||||
* }</pre>
|
||||
*/
|
||||
APIResponse fetch(FetchOptions options);
|
||||
/**
|
||||
* Fulfills route's request with given response.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of fulfilling all requests with 404 responses:
|
||||
* <pre>{@code
|
||||
* page.route("**\/*", route -> {
|
||||
@@ -423,6 +525,8 @@ public interface Route {
|
||||
/**
|
||||
* Fulfills route's request with given response.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> An example of fulfilling all requests with 404 responses:
|
||||
* <pre>{@code
|
||||
* page.route("**\/*", route -> {
|
||||
|
||||
@@ -20,21 +20,21 @@ import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* Selectors can be used to install custom selector engines. See <a
|
||||
* href="https://playwright.dev/java/docs/selectors">Working with selectors</a> for more information.
|
||||
* href="https://playwright.dev/java/docs/extensibility">extensibility</a> for more information.
|
||||
*/
|
||||
public interface Selectors {
|
||||
class RegisterOptions {
|
||||
/**
|
||||
* Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same DOM, but
|
||||
* not any JavaScript objects from the frame's scripts. Defaults to {@code false}. Note that running as a content script is not
|
||||
* guaranteed when this engine is used together with other registered engines.
|
||||
* Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same DOM,
|
||||
* but not any JavaScript objects from the frame's scripts. Defaults to {@code false}. Note that running as a content script is
|
||||
* not guaranteed when this engine is used together with other registered engines.
|
||||
*/
|
||||
public Boolean contentScript;
|
||||
|
||||
/**
|
||||
* Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same DOM, but
|
||||
* not any JavaScript objects from the frame's scripts. Defaults to {@code false}. Note that running as a content script is not
|
||||
* guaranteed when this engine is used together with other registered engines.
|
||||
* Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same DOM,
|
||||
* but not any JavaScript objects from the frame's scripts. Defaults to {@code false}. Note that running as a content script is
|
||||
* not guaranteed when this engine is used together with other registered engines.
|
||||
*/
|
||||
public RegisterOptions setContentScript(boolean contentScript) {
|
||||
this.contentScript = contentScript;
|
||||
@@ -42,7 +42,9 @@ public interface Selectors {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* An example of registering selector engine that queries elements based on a tag name:
|
||||
* **Usage**
|
||||
*
|
||||
* <p> An example of registering selector engine that queries elements based on a tag name:
|
||||
* <pre>{@code
|
||||
* // Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||
* String createTagNameEngine = "{\n" +
|
||||
@@ -69,15 +71,17 @@ public interface Selectors {
|
||||
* browser.close();
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Name that is used in selectors as a prefix, e.g. {@code {name: 'foo'}} enables {@code foo=myselectorbody} selectors. May only
|
||||
* contain {@code [a-zA-Z0-9_]} characters.
|
||||
* @param name Name that is used in selectors as a prefix, e.g. {@code {name: 'foo'}} enables {@code foo=myselectorbody} selectors. May
|
||||
* only contain {@code [a-zA-Z0-9_]} characters.
|
||||
* @param script Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||
*/
|
||||
default void register(String name, String script) {
|
||||
register(name, script, null);
|
||||
}
|
||||
/**
|
||||
* An example of registering selector engine that queries elements based on a tag name:
|
||||
* **Usage**
|
||||
*
|
||||
* <p> An example of registering selector engine that queries elements based on a tag name:
|
||||
* <pre>{@code
|
||||
* // Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||
* String createTagNameEngine = "{\n" +
|
||||
@@ -104,13 +108,15 @@ public interface Selectors {
|
||||
* browser.close();
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Name that is used in selectors as a prefix, e.g. {@code {name: 'foo'}} enables {@code foo=myselectorbody} selectors. May only
|
||||
* contain {@code [a-zA-Z0-9_]} characters.
|
||||
* @param name Name that is used in selectors as a prefix, e.g. {@code {name: 'foo'}} enables {@code foo=myselectorbody} selectors. May
|
||||
* only contain {@code [a-zA-Z0-9_]} characters.
|
||||
* @param script Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||
*/
|
||||
void register(String name, String script, RegisterOptions options);
|
||||
/**
|
||||
* An example of registering selector engine that queries elements based on a tag name:
|
||||
* **Usage**
|
||||
*
|
||||
* <p> An example of registering selector engine that queries elements based on a tag name:
|
||||
* <pre>{@code
|
||||
* // Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||
* String createTagNameEngine = "{\n" +
|
||||
@@ -137,15 +143,17 @@ public interface Selectors {
|
||||
* browser.close();
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Name that is used in selectors as a prefix, e.g. {@code {name: 'foo'}} enables {@code foo=myselectorbody} selectors. May only
|
||||
* contain {@code [a-zA-Z0-9_]} characters.
|
||||
* @param name Name that is used in selectors as a prefix, e.g. {@code {name: 'foo'}} enables {@code foo=myselectorbody} selectors. May
|
||||
* only contain {@code [a-zA-Z0-9_]} characters.
|
||||
* @param script Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||
*/
|
||||
default void register(String name, Path script) {
|
||||
register(name, script, null);
|
||||
}
|
||||
/**
|
||||
* An example of registering selector engine that queries elements based on a tag name:
|
||||
* **Usage**
|
||||
*
|
||||
* <p> An example of registering selector engine that queries elements based on a tag name:
|
||||
* <pre>{@code
|
||||
* // Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||
* String createTagNameEngine = "{\n" +
|
||||
@@ -172,8 +180,8 @@ public interface Selectors {
|
||||
* browser.close();
|
||||
* }</pre>
|
||||
*
|
||||
* @param name Name that is used in selectors as a prefix, e.g. {@code {name: 'foo'}} enables {@code foo=myselectorbody} selectors. May only
|
||||
* contain {@code [a-zA-Z0-9_]} characters.
|
||||
* @param name Name that is used in selectors as a prefix, e.g. {@code {name: 'foo'}} enables {@code foo=myselectorbody} selectors. May
|
||||
* only contain {@code [a-zA-Z0-9_]} characters.
|
||||
* @param script Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||
*/
|
||||
void register(String name, Path script, RegisterOptions options);
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.microsoft.playwright;
|
||||
|
||||
|
||||
/**
|
||||
* The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on the
|
||||
* touchscreen can only be used in browser contexts that have been initialized with {@code hasTouch} set to true.
|
||||
* The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on
|
||||
* the touchscreen can only be used in browser contexts that have been initialized with {@code hasTouch} set to true.
|
||||
*/
|
||||
public interface Touchscreen {
|
||||
/**
|
||||
|
||||
@@ -154,6 +154,8 @@ public interface Tracing {
|
||||
}
|
||||
/**
|
||||
* Start tracing.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* context.tracing().start(new Tracing.StartOptions()
|
||||
* .setScreenshots(true)
|
||||
@@ -169,6 +171,8 @@ public interface Tracing {
|
||||
}
|
||||
/**
|
||||
* Start tracing.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* context.tracing().start(new Tracing.StartOptions()
|
||||
* .setScreenshots(true)
|
||||
@@ -184,6 +188,8 @@ public interface Tracing {
|
||||
* Start a new trace chunk. If you'd like to record multiple traces on the same {@code BrowserContext}, use {@link Tracing#start
|
||||
* Tracing.start()} once, and then create multiple trace chunks with {@link Tracing#startChunk Tracing.startChunk()} and
|
||||
* {@link Tracing#stopChunk Tracing.stopChunk()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* context.tracing().start(new Tracing.StartOptions()
|
||||
* .setScreenshots(true)
|
||||
@@ -211,6 +217,8 @@ public interface Tracing {
|
||||
* Start a new trace chunk. If you'd like to record multiple traces on the same {@code BrowserContext}, use {@link Tracing#start
|
||||
* Tracing.start()} once, and then create multiple trace chunks with {@link Tracing#startChunk Tracing.startChunk()} and
|
||||
* {@link Tracing#stopChunk Tracing.stopChunk()}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* context.tracing().start(new Tracing.StartOptions()
|
||||
* .setScreenshots(true)
|
||||
|
||||
@@ -30,8 +30,8 @@ public interface Video {
|
||||
*/
|
||||
void delete();
|
||||
/**
|
||||
* Returns the file system path this video will be recorded to. The video is guaranteed to be written to the filesystem
|
||||
* upon closing the browser context. This method throws when connected remotely.
|
||||
* Returns the file system path this video will be recorded to. The video is guaranteed to be written to the
|
||||
* filesystem upon closing the browser context. This method throws when connected remotely.
|
||||
*/
|
||||
Path path();
|
||||
/**
|
||||
|
||||
+2
@@ -47,6 +47,8 @@ public interface APIResponseAssertions {
|
||||
APIResponseAssertions not();
|
||||
/**
|
||||
* Ensures the response status code is within {@code 200..299} range.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(response).isOK();
|
||||
* }</pre>
|
||||
|
||||
+159
-31
@@ -31,7 +31,7 @@ import java.util.regex.Pattern;
|
||||
* @Test
|
||||
* void statusBecomesSubmitted() {
|
||||
* ...
|
||||
* page.getByRole("button").click();
|
||||
* page.getByRole(AriaRole.BUTTON).click();
|
||||
* assertThat(page.locator(".status")).hasText("Submitted");
|
||||
* }
|
||||
* }
|
||||
@@ -368,6 +368,8 @@ public interface LocatorAssertions {
|
||||
LocatorAssertions not();
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a checked input.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByLabel("Subscribe to newsletter")).isChecked();
|
||||
* }</pre>
|
||||
@@ -377,6 +379,8 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a checked input.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByLabel("Subscribe to newsletter")).isChecked();
|
||||
* }</pre>
|
||||
@@ -385,9 +389,11 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a disabled element. Element is disabled if it has "disabled" attribute or is disabled
|
||||
* via <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled">'aria-disabled'</a>.
|
||||
* Note that only native control elements such as HTML {@code button}, {@code input}, {@code select}, {@code textarea}, {@code option}, {@code optgroup} can be
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled">'aria-disabled'</a>. Note
|
||||
* that only native control elements such as HTML {@code button}, {@code input}, {@code select}, {@code textarea}, {@code option}, {@code optgroup} can be
|
||||
* disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("button.submit")).isDisabled();
|
||||
* }</pre>
|
||||
@@ -398,9 +404,11 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a disabled element. Element is disabled if it has "disabled" attribute or is disabled
|
||||
* via <a
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled">'aria-disabled'</a>.
|
||||
* Note that only native control elements such as HTML {@code button}, {@code input}, {@code select}, {@code textarea}, {@code option}, {@code optgroup} can be
|
||||
* href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled">'aria-disabled'</a>. Note
|
||||
* that only native control elements such as HTML {@code button}, {@code input}, {@code select}, {@code textarea}, {@code option}, {@code optgroup} can be
|
||||
* disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("button.submit")).isDisabled();
|
||||
* }</pre>
|
||||
@@ -408,8 +416,10 @@ public interface LocatorAssertions {
|
||||
void isDisabled(IsDisabledOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an editable element.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole("textbox")).isEditable();
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).isEditable();
|
||||
* }</pre>
|
||||
*/
|
||||
default void isEditable() {
|
||||
@@ -417,13 +427,17 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an editable element.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole("textbox")).isEditable();
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).isEditable();
|
||||
* }</pre>
|
||||
*/
|
||||
void isEditable(IsEditableOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an empty editable element or to a DOM node that has no text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("div.warning")).isEmpty();
|
||||
* }</pre>
|
||||
@@ -433,6 +447,8 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an empty editable element or to a DOM node that has no text.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("div.warning")).isEmpty();
|
||||
* }</pre>
|
||||
@@ -440,6 +456,8 @@ public interface LocatorAssertions {
|
||||
void isEmpty(IsEmptyOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an enabled element.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("button.submit")).isEnabled();
|
||||
* }</pre>
|
||||
@@ -449,6 +467,8 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an enabled element.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("button.submit")).isEnabled();
|
||||
* }</pre>
|
||||
@@ -456,8 +476,10 @@ public interface LocatorAssertions {
|
||||
void isEnabled(IsEnabledOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a focused DOM node.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole("textbox")).isFocused();
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).isFocused();
|
||||
* }</pre>
|
||||
*/
|
||||
default void isFocused() {
|
||||
@@ -465,14 +487,18 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to a focused DOM node.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole("textbox")).isFocused();
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).isFocused();
|
||||
* }</pre>
|
||||
*/
|
||||
void isFocused(IsFocusedOptions options);
|
||||
/**
|
||||
* Ensures that {@code Locator} either does not resolve to any DOM node, or resolves to a <a
|
||||
* href="https://playwright.dev/java/docs/api/actionability#visible">non-visible</a> one.
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">non-visible</a> one.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".my-element")).isHidden();
|
||||
* }</pre>
|
||||
@@ -482,15 +508,19 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures that {@code Locator} either does not resolve to any DOM node, or resolves to a <a
|
||||
* href="https://playwright.dev/java/docs/api/actionability#visible">non-visible</a> one.
|
||||
* href="https://playwright.dev/java/docs/actionability#visible">non-visible</a> one.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".my-element")).isHidden();
|
||||
* }</pre>
|
||||
*/
|
||||
void isHidden(IsHiddenOptions options);
|
||||
/**
|
||||
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/api/actionability#attached">attached</a>
|
||||
* and <a href="https://playwright.dev/java/docs/api/actionability#visible">visible</a> DOM node.
|
||||
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a> and
|
||||
* <a href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".my-element")).isVisible();
|
||||
* }</pre>
|
||||
@@ -499,8 +529,10 @@ public interface LocatorAssertions {
|
||||
isVisible(null);
|
||||
}
|
||||
/**
|
||||
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/api/actionability#attached">attached</a>
|
||||
* and <a href="https://playwright.dev/java/docs/api/actionability#visible">visible</a> DOM node.
|
||||
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/actionability#attached">attached</a> and
|
||||
* <a href="https://playwright.dev/java/docs/actionability#visible">visible</a> DOM node.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".my-element")).isVisible();
|
||||
* }</pre>
|
||||
@@ -509,6 +541,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the value
|
||||
* as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -546,6 +580,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the value
|
||||
* as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -581,6 +617,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the value
|
||||
* as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -618,6 +656,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the value
|
||||
* as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -653,6 +693,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the value
|
||||
* as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -690,6 +732,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the value
|
||||
* as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -725,6 +769,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the value
|
||||
* as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -762,6 +808,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element that contains the given text. You can use regular expressions for the value
|
||||
* as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).containsText("substring");
|
||||
* }</pre>
|
||||
@@ -796,6 +844,8 @@ public interface LocatorAssertions {
|
||||
void containsText(Pattern[] expected, ContainsTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input")).hasAttribute("type", "text");
|
||||
* }</pre>
|
||||
@@ -808,6 +858,8 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input")).hasAttribute("type", "text");
|
||||
* }</pre>
|
||||
@@ -818,6 +870,8 @@ public interface LocatorAssertions {
|
||||
void hasAttribute(String name, String value, HasAttributeOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input")).hasAttribute("type", "text");
|
||||
* }</pre>
|
||||
@@ -830,6 +884,8 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given attribute.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input")).hasAttribute("type", "text");
|
||||
* }</pre>
|
||||
@@ -841,6 +897,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a relaxed
|
||||
* regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -859,6 +917,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a relaxed
|
||||
* regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -875,6 +935,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a relaxed
|
||||
* regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -893,6 +955,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a relaxed
|
||||
* regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -909,6 +973,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a relaxed
|
||||
* regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -927,6 +993,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a relaxed
|
||||
* regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -943,6 +1011,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a relaxed
|
||||
* regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -961,6 +1031,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given CSS classes. This needs to be a full match or using a relaxed
|
||||
* regular expression.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("#component")).hasClass(Pattern.compile("selected"));
|
||||
* assertThat(page.locator("#component")).hasClass("selected row");
|
||||
@@ -976,6 +1048,8 @@ public interface LocatorAssertions {
|
||||
void hasClass(Pattern[] expected, HasClassOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} resolves to an exact number of DOM nodes.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("list > .component")).hasCount(3);
|
||||
* }</pre>
|
||||
@@ -987,6 +1061,8 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} resolves to an exact number of DOM nodes.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("list > .component")).hasCount(3);
|
||||
* }</pre>
|
||||
@@ -996,8 +1072,10 @@ public interface LocatorAssertions {
|
||||
void hasCount(int count, HasCountOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} resolves to an element with the given computed CSS style.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole("button")).hasCSS("display", "flex");
|
||||
* assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
|
||||
* }</pre>
|
||||
*
|
||||
* @param name CSS property name.
|
||||
@@ -1008,8 +1086,10 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} resolves to an element with the given computed CSS style.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole("button")).hasCSS("display", "flex");
|
||||
* assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
|
||||
* }</pre>
|
||||
*
|
||||
* @param name CSS property name.
|
||||
@@ -1018,8 +1098,10 @@ public interface LocatorAssertions {
|
||||
void hasCSS(String name, String value, HasCSSOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} resolves to an element with the given computed CSS style.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole("button")).hasCSS("display", "flex");
|
||||
* assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
|
||||
* }</pre>
|
||||
*
|
||||
* @param name CSS property name.
|
||||
@@ -1030,8 +1112,10 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} resolves to an element with the given computed CSS style.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole("button")).hasCSS("display", "flex");
|
||||
* assertThat(page.getByRole(AriaRole.BUTTON)).hasCSS("display", "flex");
|
||||
* }</pre>
|
||||
*
|
||||
* @param name CSS property name.
|
||||
@@ -1040,8 +1124,10 @@ public interface LocatorAssertions {
|
||||
void hasCSS(String name, Pattern value, HasCSSOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given DOM Node ID.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole("textbox")).hasId("lastname");
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
|
||||
* }</pre>
|
||||
*
|
||||
* @param id Element id.
|
||||
@@ -1051,8 +1137,10 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given DOM Node ID.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole("textbox")).hasId("lastname");
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
|
||||
* }</pre>
|
||||
*
|
||||
* @param id Element id.
|
||||
@@ -1060,8 +1148,10 @@ public interface LocatorAssertions {
|
||||
void hasId(String id, HasIdOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given DOM Node ID.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole("textbox")).hasId("lastname");
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
|
||||
* }</pre>
|
||||
*
|
||||
* @param id Element id.
|
||||
@@ -1071,8 +1161,10 @@ public interface LocatorAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given DOM Node ID.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.getByRole("textbox")).hasId("lastname");
|
||||
* assertThat(page.getByRole(AriaRole.TEXTBOX)).hasId("lastname");
|
||||
* }</pre>
|
||||
*
|
||||
* @param id Element id.
|
||||
@@ -1081,6 +1173,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given JavaScript property. Note that this property can be of a primitive
|
||||
* type as well as a plain serializable JavaScript object.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input")).hasJSProperty("loaded", true);
|
||||
* }</pre>
|
||||
@@ -1094,6 +1188,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with given JavaScript property. Note that this property can be of a primitive
|
||||
* type as well as a plain serializable JavaScript object.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input")).hasJSProperty("loaded", true);
|
||||
* }</pre>
|
||||
@@ -1104,6 +1200,8 @@ public interface LocatorAssertions {
|
||||
void hasJSProperty(String name, Object value, HasJSPropertyOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1133,13 +1231,15 @@ public interface LocatorAssertions {
|
||||
* assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
|
||||
* }</pre>
|
||||
*
|
||||
* @param expected Expected substring or RegExp or a list of those.
|
||||
* @param expected Expected string or RegExp or a list of those.
|
||||
*/
|
||||
default void hasText(String expected) {
|
||||
hasText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1169,11 +1269,13 @@ public interface LocatorAssertions {
|
||||
* assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
|
||||
* }</pre>
|
||||
*
|
||||
* @param expected Expected substring or RegExp or a list of those.
|
||||
* @param expected Expected string or RegExp or a list of those.
|
||||
*/
|
||||
void hasText(String expected, HasTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1203,13 +1305,15 @@ public interface LocatorAssertions {
|
||||
* assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
|
||||
* }</pre>
|
||||
*
|
||||
* @param expected Expected substring or RegExp or a list of those.
|
||||
* @param expected Expected string or RegExp or a list of those.
|
||||
*/
|
||||
default void hasText(Pattern expected) {
|
||||
hasText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1239,11 +1343,13 @@ public interface LocatorAssertions {
|
||||
* assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
|
||||
* }</pre>
|
||||
*
|
||||
* @param expected Expected substring or RegExp or a list of those.
|
||||
* @param expected Expected string or RegExp or a list of those.
|
||||
*/
|
||||
void hasText(Pattern expected, HasTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1273,13 +1379,15 @@ public interface LocatorAssertions {
|
||||
* assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
|
||||
* }</pre>
|
||||
*
|
||||
* @param expected Expected substring or RegExp or a list of those.
|
||||
* @param expected Expected string or RegExp or a list of those.
|
||||
*/
|
||||
default void hasText(String[] expected) {
|
||||
hasText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1309,11 +1417,13 @@ public interface LocatorAssertions {
|
||||
* assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
|
||||
* }</pre>
|
||||
*
|
||||
* @param expected Expected substring or RegExp or a list of those.
|
||||
* @param expected Expected string or RegExp or a list of those.
|
||||
*/
|
||||
void hasText(String[] expected, HasTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1343,13 +1453,15 @@ public interface LocatorAssertions {
|
||||
* assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
|
||||
* }</pre>
|
||||
*
|
||||
* @param expected Expected substring or RegExp or a list of those.
|
||||
* @param expected Expected string or RegExp or a list of those.
|
||||
*/
|
||||
default void hasText(Pattern[] expected) {
|
||||
hasText(expected, null);
|
||||
}
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given text. You can use regular expressions for the value as well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator(".title")).hasText("Welcome, Test User");
|
||||
* assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
|
||||
@@ -1379,12 +1491,14 @@ public interface LocatorAssertions {
|
||||
* assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
|
||||
* }</pre>
|
||||
*
|
||||
* @param expected Expected substring or RegExp or a list of those.
|
||||
* @param expected Expected string or RegExp or a list of those.
|
||||
*/
|
||||
void hasText(Pattern[] expected, HasTextOptions options);
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given input value. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
|
||||
* }</pre>
|
||||
@@ -1397,6 +1511,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given input value. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
|
||||
* }</pre>
|
||||
@@ -1407,6 +1523,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given input value. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
|
||||
* }</pre>
|
||||
@@ -1419,6 +1537,8 @@ public interface LocatorAssertions {
|
||||
/**
|
||||
* Ensures the {@code Locator} points to an element with the given input value. You can use regular expressions for the value as
|
||||
* well.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
|
||||
* }</pre>
|
||||
@@ -1430,6 +1550,8 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to multi-select/combobox (i.e. a {@code select} with the {@code multiple} attribute) and the specified
|
||||
* values are selected.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, given the following element:
|
||||
* <pre>{@code
|
||||
* page.locator("id=favorite-colors").selectOption(["R", "G"]);
|
||||
@@ -1445,6 +1567,8 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to multi-select/combobox (i.e. a {@code select} with the {@code multiple} attribute) and the specified
|
||||
* values are selected.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, given the following element:
|
||||
* <pre>{@code
|
||||
* page.locator("id=favorite-colors").selectOption(["R", "G"]);
|
||||
@@ -1458,6 +1582,8 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to multi-select/combobox (i.e. a {@code select} with the {@code multiple} attribute) and the specified
|
||||
* values are selected.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, given the following element:
|
||||
* <pre>{@code
|
||||
* page.locator("id=favorite-colors").selectOption(["R", "G"]);
|
||||
@@ -1473,6 +1599,8 @@ public interface LocatorAssertions {
|
||||
* Ensures the {@code Locator} points to multi-select/combobox (i.e. a {@code select} with the {@code multiple} attribute) and the specified
|
||||
* values are selected.
|
||||
*
|
||||
* <p> **Usage**
|
||||
*
|
||||
* <p> For example, given the following element:
|
||||
* <pre>{@code
|
||||
* page.locator("id=favorite-colors").selectOption(["R", "G"]);
|
||||
|
||||
@@ -76,6 +76,8 @@ public interface PageAssertions {
|
||||
PageAssertions not();
|
||||
/**
|
||||
* Ensures the page has the given title.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasTitle("Playwright");
|
||||
* }</pre>
|
||||
@@ -87,6 +89,8 @@ public interface PageAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the page has the given title.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasTitle("Playwright");
|
||||
* }</pre>
|
||||
@@ -96,6 +100,8 @@ public interface PageAssertions {
|
||||
void hasTitle(String titleOrRegExp, HasTitleOptions options);
|
||||
/**
|
||||
* Ensures the page has the given title.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasTitle("Playwright");
|
||||
* }</pre>
|
||||
@@ -107,6 +113,8 @@ public interface PageAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the page has the given title.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasTitle("Playwright");
|
||||
* }</pre>
|
||||
@@ -116,6 +124,8 @@ public interface PageAssertions {
|
||||
void hasTitle(Pattern titleOrRegExp, HasTitleOptions options);
|
||||
/**
|
||||
* Ensures the page is navigated to the given URL.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasURL(".com");
|
||||
* }</pre>
|
||||
@@ -127,6 +137,8 @@ public interface PageAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the page is navigated to the given URL.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasURL(".com");
|
||||
* }</pre>
|
||||
@@ -136,6 +148,8 @@ public interface PageAssertions {
|
||||
void hasURL(String urlOrRegExp, HasURLOptions options);
|
||||
/**
|
||||
* Ensures the page is navigated to the given URL.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasURL(".com");
|
||||
* }</pre>
|
||||
@@ -147,6 +161,8 @@ public interface PageAssertions {
|
||||
}
|
||||
/**
|
||||
* Ensures the page is navigated to the given URL.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* assertThat(page).hasURL(".com");
|
||||
* }</pre>
|
||||
|
||||
@@ -53,6 +53,8 @@ import com.microsoft.playwright.impl.PageAssertionsImpl;
|
||||
public interface PlaywrightAssertions {
|
||||
/**
|
||||
* Creates a {@code APIResponseAssertions} object for the given {@code APIResponse}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* PlaywrightAssertions.assertThat(response).isOK();
|
||||
* }</pre>
|
||||
@@ -65,6 +67,8 @@ public interface PlaywrightAssertions {
|
||||
|
||||
/**
|
||||
* Creates a {@code LocatorAssertions} object for the given {@code Locator}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* PlaywrightAssertions.assertThat(locator).isVisible();
|
||||
* }</pre>
|
||||
@@ -77,6 +81,8 @@ public interface PlaywrightAssertions {
|
||||
|
||||
/**
|
||||
* Creates a {@code PageAssertions} object for the given {@code Page}.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* PlaywrightAssertions.assertThat(page).hasTitle("News");
|
||||
* }</pre>
|
||||
@@ -89,6 +95,8 @@ public interface PlaywrightAssertions {
|
||||
|
||||
/**
|
||||
* Changes default timeout for Playwright assertions from 5 seconds to the specified value.
|
||||
*
|
||||
* <p> **Usage**
|
||||
* <pre>{@code
|
||||
* PlaywrightAssertions.setDefaultAssertionTimeout(30_000);
|
||||
* }</pre>
|
||||
|
||||
@@ -320,6 +320,8 @@ public class Connection {
|
||||
case "Selectors":
|
||||
result = new SelectorsImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
case "SocksSupport":
|
||||
break;
|
||||
case "Tracing":
|
||||
result = new TracingImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
|
||||
@@ -375,11 +375,14 @@ public class ElementHandleImpl extends JSHandleImpl implements ElementHandle {
|
||||
|
||||
@Override
|
||||
public List<String> selectOption(String[] values, SelectOptionOptions options) {
|
||||
if (values == null) {
|
||||
return selectOption(new SelectOption[0], options);
|
||||
if (options == null) {
|
||||
options = new SelectOptionOptions();
|
||||
}
|
||||
return selectOption(Arrays.asList(values).stream().map(
|
||||
v -> new SelectOption().setValue(v)).toArray(SelectOption[]::new), options);
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
if (values != null) {
|
||||
params.add("options", toSelectValueOrLabel(values));
|
||||
}
|
||||
return selectOption(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -110,11 +110,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
|
||||
@Override
|
||||
public List<String> selectOption(String selector, String[] values, SelectOptionOptions options) {
|
||||
if (values == null) {
|
||||
return selectOption(selector, new SelectOption[0], options);
|
||||
}
|
||||
return selectOption(selector, Arrays.asList(values).stream().map(
|
||||
v -> new SelectOption().setValue(v)).toArray(SelectOption[]::new), options);
|
||||
return withLogging("Frame.selectOption", () -> selectOptionImpl(selector, values, options));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -414,6 +410,11 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
return locator(getByTestIdSelector(testId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator getByTestId(Pattern testId) {
|
||||
return locator(getByTestIdSelector(testId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator getByText(String text, GetByTextOptions options) {
|
||||
return locator(getByTextSelector(text, convertType(options, Locator.GetByTextOptions.class)));
|
||||
@@ -688,6 +689,18 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
return selectOption(params);
|
||||
}
|
||||
|
||||
List<String> selectOptionImpl(String selector, String[] values, SelectOptionOptions options) {
|
||||
if (options == null) {
|
||||
options = new SelectOptionOptions();
|
||||
}
|
||||
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
|
||||
params.addProperty("selector", selector);
|
||||
if (values != null) {
|
||||
params.add("options", toSelectValueOrLabel(values));
|
||||
}
|
||||
return selectOption(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> selectOption(String selector, ElementHandle[] values, SelectOptionOptions options) {
|
||||
return withLogging("Frame.selectOption", () -> selectOptionImpl(selector, values, options));
|
||||
|
||||
@@ -84,6 +84,11 @@ class FrameLocatorImpl implements FrameLocator {
|
||||
return locator(getByTestIdSelector(testId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator getByTestId(Pattern testId) {
|
||||
return locator(getByTestIdSelector(testId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator getByText(String text, GetByTextOptions options) {
|
||||
return locator(getByTextSelector(text, convertType(options, Locator.GetByTextOptions.class)));
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.microsoft.playwright.options.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -61,6 +62,16 @@ class LocatorImpl implements Locator {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Locator> all() {
|
||||
List<Locator> result = new ArrayList<>();
|
||||
int count = this.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
result.add(nth(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> allInnerTexts() {
|
||||
return (List<String>) frame.evalOnSelectorAll(selector, "ee => ee.map(e => e.innerText)");
|
||||
@@ -253,6 +264,11 @@ class LocatorImpl implements Locator {
|
||||
return locator(getByTestIdSelector(testId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator getByTestId(Pattern testId) {
|
||||
return locator(getByTestIdSelector(testId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator getByText(String text, GetByTextOptions options) {
|
||||
return locator(getByTextSelector(text, options));
|
||||
|
||||
@@ -31,7 +31,7 @@ public class LocatorUtils {
|
||||
return "internal:attr=[" + attrName + "=" + escapeForAttributeSelector((String) value, exact) + "]";
|
||||
}
|
||||
|
||||
static String getByTestIdSelector(String testId) {
|
||||
static String getByTestIdSelector(Object testId) {
|
||||
return getByAttributeTextSelector(testIdAttributeName, testId, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,7 @@ import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
import static com.microsoft.playwright.impl.Utils.convertType;
|
||||
import static com.microsoft.playwright.impl.Utils.isSafeCloseError;
|
||||
import static com.microsoft.playwright.impl.Utils.*;
|
||||
import static com.microsoft.playwright.options.ScreenshotType.JPEG;
|
||||
import static com.microsoft.playwright.options.ScreenshotType.PNG;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
@@ -782,6 +781,11 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
return withLogging("Page.getByTestId", () -> mainFrame.getByTestId(testId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator getByTestId(Pattern testId) {
|
||||
return withLogging("Page.getByTestId", () -> mainFrame.getByTestId(testId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locator getByText(String text, GetByTextOptions options) {
|
||||
return withLogging("Page.getByText",
|
||||
@@ -1045,8 +1049,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
return withLogging("Page.screenshot", () -> screenshotImpl(options));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> selectOption(String selector, String value, SelectOptionOptions options) {
|
||||
String[] values = value == null ? null : new String[]{ value };
|
||||
@@ -1061,11 +1063,8 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public List<String> selectOption(String selector, String[] values, SelectOptionOptions options) {
|
||||
if (values == null) {
|
||||
return selectOption(selector, new SelectOption[0], options);
|
||||
}
|
||||
return selectOption(selector, Arrays.asList(values).stream().map(
|
||||
v -> new SelectOption().setValue(v)).toArray(SelectOption[]::new), options);
|
||||
return withLogging("Page.selectOption",
|
||||
() -> mainFrame.selectOptionImpl(selector, values, convertType(options, Frame.SelectOptionOptions.class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.Frame;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.Route;
|
||||
import com.microsoft.playwright.*;
|
||||
import com.microsoft.playwright.options.RequestOptions;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -75,6 +74,28 @@ public class RouteImpl extends ChannelOwner implements Route {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public APIResponse fetch(FetchOptions fetchOptions) {
|
||||
RequestOptionsImpl options = convertType(fetchOptions, RequestOptionsImpl.class);
|
||||
if (options == null) {
|
||||
options = new RequestOptionsImpl();
|
||||
}
|
||||
if (options.method == null) {
|
||||
options.method = request.method();
|
||||
}
|
||||
if (options.headers == null) {
|
||||
options.headers = request.headers();
|
||||
}
|
||||
if (fetchOptions != null && fetchOptions.postData != null) {
|
||||
options.data = fetchOptions.postData;
|
||||
} else {
|
||||
options.data = request.postDataBuffer();
|
||||
}
|
||||
APIRequestContextImpl apiRequest = request.frame().page().context().request();
|
||||
String url = (fetchOptions == null || fetchOptions.url == null) ? request().url() : fetchOptions.url;
|
||||
return apiRequest.fetch(url, options);
|
||||
}
|
||||
|
||||
private void applyOverrides(FallbackOptions options) {
|
||||
if (options == null) {
|
||||
return;
|
||||
|
||||
@@ -348,6 +348,16 @@ class Serialization {
|
||||
return array;
|
||||
}
|
||||
|
||||
static JsonArray toSelectValueOrLabel(String[] values) {
|
||||
JsonArray jsonOptions = new JsonArray();
|
||||
for (String value : values) {
|
||||
JsonObject option = new JsonObject();
|
||||
option.addProperty("valueOrLabel", value);
|
||||
jsonOptions.add(option);
|
||||
}
|
||||
return jsonOptions;
|
||||
}
|
||||
|
||||
static Map<String, String> fromNameValues(JsonArray array) {
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
for (JsonElement element : array) {
|
||||
@@ -411,12 +421,6 @@ class Serialization {
|
||||
}
|
||||
}
|
||||
|
||||
private static class BrowserChannelSerializer implements JsonSerializer<BrowserChannel> {
|
||||
@Override
|
||||
public JsonElement serialize(BrowserChannel src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.toString().toLowerCase().replace('_', '-'));
|
||||
}
|
||||
}
|
||||
private static class ToLowerCaseAndDashSerializer<E extends Enum<E>> implements JsonSerializer<E> {
|
||||
@Override
|
||||
public JsonElement serialize(E src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
import com.microsoft.playwright.options.FilePayload;
|
||||
import com.microsoft.playwright.options.HttpHeader;
|
||||
import com.microsoft.playwright.options.SelectOption;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -19,8 +19,8 @@ package com.microsoft.playwright.options;
|
||||
import com.microsoft.playwright.impl.RequestOptionsImpl;
|
||||
|
||||
/**
|
||||
* The {@code RequestOptions} allows to create form data to be sent via {@code APIRequestContext}. Playwright will automatically
|
||||
* determine content type of the request.
|
||||
* The {@code RequestOptions} allows to create form data to be sent via {@code APIRequestContext}. Playwright will
|
||||
* automatically determine content type of the request.
|
||||
* <pre>{@code
|
||||
* context.request().post(
|
||||
* "https://example.com/submit",
|
||||
|
||||
@@ -83,4 +83,13 @@ public class TestElementHandleMisc extends TestBase {
|
||||
input.setChecked(false);
|
||||
assertEquals(false, page.evaluate("checkbox.checked"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFallBackToSelectingByLabel() {
|
||||
page.navigate(server.PREFIX + "/input/select.html");
|
||||
page.querySelector("select").selectOption("Blue");
|
||||
assertEquals(asList("blue"), page.evaluate("() => window['result'].onInput"));
|
||||
assertEquals(asList("blue"), page.evaluate("() => window['result'].onChange"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestLocatorList extends TestBase {
|
||||
@Test
|
||||
void locatorAllShouldWork() {
|
||||
page.setContent("<div><p>A</p><p>B</p><p>C</p></div>");
|
||||
List<String> texts = new ArrayList<>();
|
||||
for (Locator p : page.locator("div >> p").all()) {
|
||||
texts.add(p.textContent());
|
||||
}
|
||||
assertEquals(asList("A", "B", "C"), texts);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package com.microsoft.playwright;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -57,4 +59,37 @@ public class TestPageInterception extends TestBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFulfillInterceptedResponseUsingAlias() {
|
||||
page.route("**/*", route -> {
|
||||
APIResponse response = route.fetch();
|
||||
System.out.println(response.headers().get("content-type"));
|
||||
route.fulfill(new Route.FulfillOptions().setResponse(response));
|
||||
});
|
||||
Response response = page.navigate(server.PREFIX + "/empty.html");
|
||||
assertEquals(200, response.status());
|
||||
assertTrue(response.headers().get("content-type").contains("text/html"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInterceptWithUrlOverride() {
|
||||
page.route("**/*.html", route -> {
|
||||
APIResponse response = route.fetch(new Route.FetchOptions().setUrl(server.PREFIX + "/one-style.html"));
|
||||
route.fulfill(new Route.FulfillOptions().setResponse(response));
|
||||
});
|
||||
Response response = page.navigate(server.PREFIX + "/empty.html");
|
||||
assertEquals(200, response.status());
|
||||
assertTrue(response.text().contains("one-style.css"), response.text());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInterceptWithPostDataOverride() throws ExecutionException, InterruptedException {
|
||||
Future<Server.Request> request = server.futureRequest("/empty.html");
|
||||
page.route("**/*.html", route -> {
|
||||
APIResponse response = route.fetch(new Route.FetchOptions().setPostData("{ \"foo\": \"bar\" }"));
|
||||
route.fulfill(new Route.FulfillOptions().setResponse(response));
|
||||
});
|
||||
page.navigate(server.PREFIX + "/empty.html");
|
||||
assertEquals("{ \"foo\": \"bar\" }", new String(request.get().postBody));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,14 @@ public class TestPageSelectOption extends TestBase {
|
||||
assertEquals(asList("blue"), page.evaluate("() => window['result'].onChange"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFallBackToSelectingByLabel() {
|
||||
page.navigate(server.PREFIX + "/input/select.html");
|
||||
page.selectOption("select", "Blue");
|
||||
assertEquals(asList("blue"), page.evaluate("() => window['result'].onInput"));
|
||||
assertEquals(asList("blue"), page.evaluate("() => window['result'].onChange"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSelectSingleOptionByLabel() {
|
||||
page.navigate(server.PREFIX + "/input/select.html");
|
||||
|
||||
@@ -25,6 +25,14 @@ public class TestSelectorsGetBy extends TestBase {
|
||||
assertThat(page.getByTestId("He\"llo")).hasText("Hello world");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getByTestIdShouldWorkForRegex() {
|
||||
page.setContent("<div><div data-testid='Hello'>Hello world</div></div>");
|
||||
assertThat(page.getByTestId(Pattern.compile("He[l]*o"))).hasText("Hello world");
|
||||
assertThat(page.mainFrame().getByTestId("Hello")).hasText("Hello world");
|
||||
assertThat(page.locator("div").getByTestId("Hello")).hasText("Hello world");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getByTextShouldWork() {
|
||||
page.setContent("<div>yo</div><div>ya</div><div>\nye </div>");
|
||||
|
||||
@@ -153,26 +153,42 @@ public class TestSelectorsRole extends TestBase {
|
||||
|
||||
@Test
|
||||
void shouldSupportExpanded() {
|
||||
page.setContent("<button>Hi</button>\n" +
|
||||
" <button aria-expanded=\"true\">Hello</button>\n" +
|
||||
" <button aria-expanded=\"false\">Bye</button>");
|
||||
page.setContent("<div role=\"treeitem\">Hi</div>\n" +
|
||||
" <div role=\"treeitem\" aria-expanded=\"true\">Hello</div>\n" +
|
||||
" <div role=\"treeitem\" aria-expanded=\"false\">Bye</div>");
|
||||
assertEquals(asList(
|
||||
"<button aria-expanded=\"true\">Hello</button>"
|
||||
), page.locator("role=button[expanded]").evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
"<div role=\"treeitem\">Hi</div>",
|
||||
"<div role=\"treeitem\" aria-expanded=\"true\">Hello</div>",
|
||||
"<div role=\"treeitem\" aria-expanded=\"false\">Bye</div>"
|
||||
), page.locator("role=treeitem").evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
assertEquals(asList(
|
||||
"<button aria-expanded=\"true\">Hello</button>"
|
||||
), page.locator("role=button[expanded=true]").evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
"<div role=\"treeitem\">Hi</div>",
|
||||
"<div role=\"treeitem\" aria-expanded=\"true\">Hello</div>",
|
||||
"<div role=\"treeitem\" aria-expanded=\"false\">Bye</div>"
|
||||
), page.getByRole(AriaRole.TREEITEM).evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
|
||||
|
||||
assertEquals(asList(
|
||||
"<button aria-expanded=\"true\">Hello</button>"
|
||||
), page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setExpanded(true)).evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
"<div role=\"treeitem\" aria-expanded=\"true\">Hello</div>"
|
||||
), page.locator("role=treeitem[expanded]").evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
assertEquals(asList(
|
||||
"<button>Hi</button>",
|
||||
"<button aria-expanded=\"false\">Bye</button>"
|
||||
), page.locator("role=button[expanded=false]").evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
"<div role=\"treeitem\" aria-expanded=\"true\">Hello</div>"
|
||||
), page.locator("role=treeitem[expanded=true]").evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
assertEquals(asList(
|
||||
"<button>Hi</button>",
|
||||
"<button aria-expanded=\"false\">Bye</button>"
|
||||
), page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setExpanded(false)).evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
"<div role=\"treeitem\" aria-expanded=\"true\">Hello</div>"
|
||||
), page.getByRole(AriaRole.TREEITEM, new Page.GetByRoleOptions().setExpanded(true)).evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
|
||||
assertEquals(asList(
|
||||
"<div role=\"treeitem\" aria-expanded=\"false\">Bye</div>"
|
||||
), page.locator("role=treeitem[expanded=false]").evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
assertEquals(asList(
|
||||
"<div role=\"treeitem\" aria-expanded=\"false\">Bye</div>"
|
||||
), page.getByRole(AriaRole.TREEITEM, new Page.GetByRoleOptions().setExpanded(false)).evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
|
||||
// Workaround for expanded='none'.
|
||||
assertEquals(asList(
|
||||
"<div role=\"treeitem\">Hi</div>"
|
||||
), page.locator("[role=treeitem]:not([aria-expanded])").evaluateAll("els => els.map(e => e.outerHTML)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -149,7 +149,7 @@ class Utils {
|
||||
case "chromium":
|
||||
switch (getOS()) {
|
||||
case MAC:
|
||||
return Arrays.asList("net::ERR_CERT_INVALID");
|
||||
return Arrays.asList("net::ERR_CERT_INVALID", "net::ERR_CERT_AUTHORITY_INVALID");
|
||||
default:
|
||||
return Arrays.asList("net::ERR_CERT_AUTHORITY_INVALID");
|
||||
}
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
1.28.0
|
||||
1.29.0-beta-1671218511000
|
||||
|
||||
@@ -90,6 +90,9 @@ abstract class Element {
|
||||
if (!json.has("spec")) {
|
||||
return "";
|
||||
}
|
||||
if (json.has("deprecated")) {
|
||||
return "@deprecated " + beautify(json.get("deprecated").getAsString());
|
||||
}
|
||||
return formatSpec(json.getAsJsonArray("spec"));
|
||||
}
|
||||
|
||||
@@ -143,6 +146,7 @@ abstract class Element {
|
||||
out.add("</" + currentItemList + ">");
|
||||
currentItemList = null;
|
||||
}
|
||||
|
||||
return String.join("\n", out);
|
||||
}
|
||||
|
||||
@@ -151,7 +155,8 @@ abstract class Element {
|
||||
linkified = updateExternalLinks(linkified);
|
||||
return wrapText(linkified, 120, "")
|
||||
.replaceAll("`'([^`]+)'`", "{@code \"$1\"}")
|
||||
.replaceAll("`([^`]+)`", "{@code $1}");
|
||||
.replaceAll("`([^`]+)`", "{@code $1}")
|
||||
.replaceAll("↵", " ");
|
||||
}
|
||||
|
||||
private static String linkifyMemberRefs(String paragraph) {
|
||||
|
||||
Reference in New Issue
Block a user