Skip to content

Commit

Permalink
feat: initial java documentation (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Feb 24, 2021
1 parent 15d6b56 commit 0e6c493
Show file tree
Hide file tree
Showing 64 changed files with 9,219 additions and 5 deletions.
13 changes: 13 additions & 0 deletions common/links-java.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[boolean]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "boolean"
[byte[]]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "byte[]"
[double]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double"
[InputStream]: https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html "InputStream"
[int]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "int"
[List]: https://docs.oracle.com/javase/8/docs/api/java/util/List.html "List"
[Map]: https://docs.oracle.com/javase/8/docs/api/java/util/Map.html "Map"
[null]: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.7 "null"
[Object]: https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html "Object"
[Path]: https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html "Path"
[Pattern]: https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html "Pattern"
[Runnable]: https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html "Runnable"
[String]: https://docs.oracle.com/javase/8/docs/api/java/lang/String.html "String"
149 changes: 149 additions & 0 deletions java/docs/actionability.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
---
id: actionability
title: "Auto-waiting"
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

Playwright performs a range of actionability checks on the elements before making actions to ensure these actions behave as expected. It auto-waits for all the relevant checks to pass and only then performs the requested action. If the required checks do not pass within the given `timeout`, action fails with the `TimeoutError`.

For example, for [Page.click(selector[, options])](./api/class-page.mdx#pageclickselector-options), Playwright will ensure that:
- element is [Attached] to the DOM
- element is [Visible]
- element is [Stable], as in not animating or completed animation
- element [Receives Events], as in not obscured by other elements
- element is [Enabled]

Here is the complete list of actionability checks performed for each action:

| Action | [Attached] | [Visible] | [Stable] | [Receives Events] | [Enabled] | [Editable] |
| :- | :-: | :-: | :-: | :-: | :-: | :-: |
| check | Yes | Yes | Yes | Yes | Yes | - |
| click | Yes | Yes | Yes | Yes | Yes | - |
| dblclick | Yes | Yes | Yes | Yes | Yes | - |
| tap | Yes | Yes | Yes | Yes | Yes | - |
| uncheck | Yes | Yes | Yes | Yes | Yes | - |
| hover | Yes | Yes | Yes | Yes | - | - |
| scrollIntoViewIfNeeded | Yes | Yes | Yes | - | - | - |
| screenshot | Yes | Yes | Yes | - | - | - |
| fill | Yes | Yes | - | - | Yes | Yes |
| selectText | Yes | Yes | - | - | - | - |
| dispatchEvent | Yes | - | - | - | - | - |
| focus | Yes | - | - | - | - | - |
| getAttribute | Yes | - | - | - | - | - |
| innerText | Yes | - | - | - | - | - |
| innerHTML | Yes | - | - | - | - | - |
| press | Yes | - | - | - | - | - |
| setInputFiles | Yes | - | - | - | - | - |
| selectOption | Yes | - | - | - | - | - |
| textContent | Yes | - | - | - | - | - |
| type | Yes | - | - | - | - | - |

<br/>

## Forcing actions

Some actions like [Page.click(selector[, options])](./api/class-page.mdx#pageclickselector-options) support `force` option that disables non-essential actionability checks, for example passing truthy `force` to [Page.click(selector[, options])](./api/class-page.mdx#pageclickselector-options) method will not check that the target element actually receives click events.

## Assertions

You can check the actionability state of the element using one of the following methods as well. This is typically not necessary, but it helps writing assertive tests that ensure that after certain actions, elements reach actionable state:
- [ElementHandle.isChecked()](./api/class-elementhandle.mdx#elementhandleischecked)
- [ElementHandle.isDisabled()](./api/class-elementhandle.mdx#elementhandleisdisabled)
- [ElementHandle.isEditable()](./api/class-elementhandle.mdx#elementhandleiseditable)
- [ElementHandle.isEnabled()](./api/class-elementhandle.mdx#elementhandleisenabled)
- [ElementHandle.isHidden()](./api/class-elementhandle.mdx#elementhandleishidden)
- [ElementHandle.isVisible()](./api/class-elementhandle.mdx#elementhandleisvisible)
- [Page.isChecked(selector[, options])](./api/class-page.mdx#pageischeckedselector-options)
- [Page.isDisabled(selector[, options])](./api/class-page.mdx#pageisdisabledselector-options)
- [Page.isEditable(selector[, options])](./api/class-page.mdx#pageiseditableselector-options)
- [Page.isEnabled(selector[, options])](./api/class-page.mdx#pageisenabledselector-options)
- [Page.isHidden(selector[, options])](./api/class-page.mdx#pageishiddenselector-options)
- [Page.isVisible(selector[, options])](./api/class-page.mdx#pageisvisibleselector-options)

<br/>

## Attached

Element is considered attached when it is [connected](https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected) to a Document or a ShadowRoot.

## Visible

Element is considered visible when it has non-empty bounding box and does not have `visibility:hidden` computed style. Note that elements of zero size or with `display:none` are not considered visible.

## Stable

Element is considered stable when it has maintained the same bounding box for at least two consecutive animation frames.

## Enabled

Element is considered enabled when it is not a `<button>`, `<select>`, `<input>` or `<textarea>` with a `disabled` property set.

## Editable

Element is considered editable when it is [enabled] and does not have `readonly` property set.

## Receives Events

Element is considered receiving pointer events when it is the hit target of the pointer event at the action point. For example, when clicking at the point `(10;10)`, Playwright checks whether some other element (usually an overlay) will instead capture the click at `(10;10)`.

For example, consider a scenario where Playwright will click `Sign Up` button regardless of when the [Page.click(selector[, options])](./api/class-page.mdx#pageclickselector-options) call was made:
- page is checking that user name is unique and `Sign Up` button is disabled;
- after checking with the server, the disabled `Sign Up` button is replaced with another one that is now enabled.

[Visible]: #visible "Visible"
[Stable]: #stable "Stable"
[Enabled]: #enabled "Enabled"
[Editable]: #editable "Editable"
[Receives Events]: #receives-events "Receives Events"
[Attached]: #attached "Attached"

[Accessibility]: ./api/class-accessibility.mdx "Accessibility"
[Browser]: ./api/class-browser.mdx "Browser"
[BrowserContext]: ./api/class-browsercontext.mdx "BrowserContext"
[BrowserType]: ./api/class-browsertype.mdx "BrowserType"
[ConsoleMessage]: ./api/class-consolemessage.mdx "ConsoleMessage"
[Dialog]: ./api/class-dialog.mdx "Dialog"
[Download]: ./api/class-download.mdx "Download"
[ElementHandle]: ./api/class-elementhandle.mdx "ElementHandle"
[FileChooser]: ./api/class-filechooser.mdx "FileChooser"
[Frame]: ./api/class-frame.mdx "Frame"
[JSHandle]: ./api/class-jshandle.mdx "JSHandle"
[Keyboard]: ./api/class-keyboard.mdx "Keyboard"
[Mouse]: ./api/class-mouse.mdx "Mouse"
[Page]: ./api/class-page.mdx "Page"
[Playwright]: ./api/class-playwright.mdx "Playwright"
[Request]: ./api/class-request.mdx "Request"
[Response]: ./api/class-response.mdx "Response"
[Route]: ./api/class-route.mdx "Route"
[Selectors]: ./api/class-selectors.mdx "Selectors"
[TimeoutError]: ./api/class-timeouterror.mdx "TimeoutError"
[Touchscreen]: ./api/class-touchscreen.mdx "Touchscreen"
[Video]: ./api/class-video.mdx "Video"
[WebSocket]: ./api/class-websocket.mdx "WebSocket"
[WebSocketFrame]: ./api/class-websocketframe.mdx "WebSocketFrame"
[Worker]: ./api/class-worker.mdx "Worker"
[Element]: https://developer.mozilla.org/en-US/docs/Web/API/element "Element"
[Evaluation Argument]: ./core-concepts.mdx#evaluationargument "Evaluation Argument"
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"
[iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols "Iterator"
[origin]: https://developer.mozilla.org/en-US/docs/Glossary/Origin "Origin"
[selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector"
[Serializable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable"
[UIEvent.detail]: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail"
[UnixTime]: https://en.wikipedia.org/wiki/Unix_time "Unix Time"
[xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath"

[boolean]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "boolean"
[byte&#91;&#93;]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "byte[]"
[double]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double"
[InputStream]: https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html "InputStream"
[int]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "int"
[List]: https://docs.oracle.com/javase/8/docs/api/java/util/List.html "List"
[Map]: https://docs.oracle.com/javase/8/docs/api/java/util/Map.html "Map"
[null]: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.7 "null"
[Object]: https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html "Object"
[Path]: https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html "Path"
[Pattern]: https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html "Pattern"
[Runnable]: https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html "Runnable"
[String]: https://docs.oracle.com/javase/8/docs/api/java/lang/String.html "String"
83 changes: 83 additions & 0 deletions java/docs/api/class-accessibility.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
id: class-accessibility
title: "Accessibility"
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or [switches](https://en.wikipedia.org/wiki/Switch_access).

Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might have wildly different output.

Rendering engines of Chromium, Firefox and Webkit have a concept of "accessibility tree", which is then translated into different platform-specific APIs. Accessibility namespace gives access to this Accessibility Tree.

Most of the accessibility tree gets filtered out when converting from internal browser AX Tree to Platform-specific AX-Tree or by assistive technologies themselves. By default, Playwright tries to approximate this filtering, exposing only the "interesting" nodes of the tree.


- [Accessibility.snapshot([options])](./api/class-accessibility.mdx#accessibilitysnapshotoptions)

## Accessibility.snapshot([options])
- `options` <[Map]>
- `interestingOnly` <[boolean]> Prune uninteresting nodes from the tree. Defaults to `true`.
- `root` <[ElementHandle]> The root DOM element for the snapshot. Defaults to the whole page.
- returns: <[null]|[String]>

Captures the current state of the accessibility tree. The returned object represents the root accessible node of the page.

:::note
The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers. Playwright will discard them as well for an easier to process tree, unless `interestingOnly` is set to `false`.
:::

An example of dumping the entire accessibility tree:

An example of logging the focused node's name:

[Accessibility]: ./api/class-accessibility.mdx "Accessibility"
[Browser]: ./api/class-browser.mdx "Browser"
[BrowserContext]: ./api/class-browsercontext.mdx "BrowserContext"
[BrowserType]: ./api/class-browsertype.mdx "BrowserType"
[ConsoleMessage]: ./api/class-consolemessage.mdx "ConsoleMessage"
[Dialog]: ./api/class-dialog.mdx "Dialog"
[Download]: ./api/class-download.mdx "Download"
[ElementHandle]: ./api/class-elementhandle.mdx "ElementHandle"
[FileChooser]: ./api/class-filechooser.mdx "FileChooser"
[Frame]: ./api/class-frame.mdx "Frame"
[JSHandle]: ./api/class-jshandle.mdx "JSHandle"
[Keyboard]: ./api/class-keyboard.mdx "Keyboard"
[Mouse]: ./api/class-mouse.mdx "Mouse"
[Page]: ./api/class-page.mdx "Page"
[Playwright]: ./api/class-playwright.mdx "Playwright"
[Request]: ./api/class-request.mdx "Request"
[Response]: ./api/class-response.mdx "Response"
[Route]: ./api/class-route.mdx "Route"
[Selectors]: ./api/class-selectors.mdx "Selectors"
[TimeoutError]: ./api/class-timeouterror.mdx "TimeoutError"
[Touchscreen]: ./api/class-touchscreen.mdx "Touchscreen"
[Video]: ./api/class-video.mdx "Video"
[WebSocket]: ./api/class-websocket.mdx "WebSocket"
[WebSocketFrame]: ./api/class-websocketframe.mdx "WebSocketFrame"
[Worker]: ./api/class-worker.mdx "Worker"
[Element]: https://developer.mozilla.org/en-US/docs/Web/API/element "Element"
[Evaluation Argument]: ./core-concepts.mdx#evaluationargument "Evaluation Argument"
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"
[iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols "Iterator"
[origin]: https://developer.mozilla.org/en-US/docs/Glossary/Origin "Origin"
[selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector"
[Serializable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable"
[UIEvent.detail]: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail"
[UnixTime]: https://en.wikipedia.org/wiki/Unix_time "Unix Time"
[xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath"

[boolean]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "boolean"
[byte&#91;&#93;]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "byte[]"
[double]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double"
[InputStream]: https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html "InputStream"
[int]: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "int"
[List]: https://docs.oracle.com/javase/8/docs/api/java/util/List.html "List"
[Map]: https://docs.oracle.com/javase/8/docs/api/java/util/Map.html "Map"
[null]: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.7 "null"
[Object]: https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html "Object"
[Path]: https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html "Path"
[Pattern]: https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html "Pattern"
[Runnable]: https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html "Runnable"
[String]: https://docs.oracle.com/javase/8/docs/api/java/lang/String.html "String"
Loading

0 comments on commit 0e6c493

Please sign in to comment.