Skip to content

Commit

Permalink
Publish docs version 20.x
Browse files Browse the repository at this point in the history
  • Loading branch information
mobile1-internal committed Jun 19, 2024
1 parent 19e0909 commit 7345e6c
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 6 deletions.
131 changes: 125 additions & 6 deletions website/versioned_docs/version-20.x/api/webviews.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ Web view matchers are used to find elements within a web view:
- [`by.web.href()`]
- [`by.web.hrefContains()`]
- [`by.web.tag()`]
- [`by.web.value()`] (iOS only)
- [`by.web.label()`] (iOS only, supports [`asSecured()`])
- [`by.web.type()`] (iOS only, [`asSecured()`] only)
- [`atIndex()`]

### `by.web.id(id)`
Expand Down Expand Up @@ -141,6 +144,56 @@ Match elements with the specified tag.
web.element(by.web.tag('h1'));
```

### `by.web.value(value)`

:::note

This matcher is available for **iOS only** at the moment.

:::

Match elements with the specified value.

```js
web.element(by.web.value('value'));
```

### `by.web.label(label)`

:::note

This matcher is available for **iOS only** at the moment and supports [`asSecured()`].

:::

Match elements with the specified label.

```js
web.element(by.web.label('label'));
```

Supports [`asSecured()`] on **iOS only**:

```js
web.element(by.web.label('label')).asSecured();
```

### `by.web.type(accessibilityType)`

:::note

This matcher is available for **iOS only** at the moment and supported with [`asSecured()`] only.

:::

Match elements with the specified type.

```js
web.element(by.web.type('textField')).asSecured();
```

The type value can be any of XCUIElement.ElementType values, such as 'button' or 'textField'. See [XCUIElement.ElementType](https://developer.apple.com/documentation/xctest/xcuielement/elementtype).

### `atIndex(index)`

Choose the element at the specified index.
Expand All @@ -155,10 +208,10 @@ Use it sparingly for those rare cases when you cannot make your matcher less amb

Web view actions are used to interact with elements within a web view:

- [`tap()`]
- [`typeText()`]
- [`replaceText()`]
- [`clearText()`]
- [`tap()`] (supports [`asSecured()`])
- [`typeText()`] (supports [`asSecured()`])
- [`replaceText()`] (supports [`asSecured()`])
- [`clearText()`] (supports [`asSecured()`])
- [`selectAllText()`]
- [`getText()`]
- [`scrollToView()`]
Expand All @@ -176,6 +229,12 @@ Tap the element.
await web.element(by.web.id('identifier')).tap();
```

Supports [`asSecured()`] on **iOS only**:

```js
await web.element(by.web.label('Submit')).asSecured().tap();
```

### `typeText(text[, isContentEditable])`

Type the specified text into the element.
Expand All @@ -186,6 +245,12 @@ Type the specified text into the element.
await web.element(by.web.id('identifier')).typeText('Hello World!');
```

Supports [`asSecured()`] on **iOS only**:

```js
await web.element(by.web.type('textField')).asSecured().typeText('Hello World!');
```

:::note

The `isContentEditable` parameter is currently necessary for content-editable elements only on Android.
Expand All @@ -202,6 +267,12 @@ Replace the text of the element with the specified text.
await web.element(by.web.id('identifier')).replaceText('Hello World!');
```

Supports [`asSecured()`] on **iOS only**:

```js
await web.element(by.web.type('textField')).asSecured().replaceText('Hello World!');
```

:::note

This action is currently not supported for content-editable elements on Android.
Expand All @@ -218,6 +289,12 @@ Clear the text of the element.
await web.element(by.web.id('identifier')).clearText();
```

Supports [`asSecured()`] on **iOS only**:

```js
await web.element(by.web.type('textField')).asSecured().clearText();
```

:::note

This action is currently not supported for content-editable elements on Android.
Expand Down Expand Up @@ -338,8 +415,8 @@ const title = await web.element(by.web.id('identifier')).getTitle();
Web view expectations are used to assert the state of elements within a web view:

- [`toHaveText()`]
- [`toExist()`]
- [`not`]
- [`toExist()`] (supports [`asSecured()`])
- [`not`] (supports [`asSecured()`])

### `toHaveText(text)`

Expand All @@ -357,6 +434,12 @@ Assert that the element exists.
await expect(web.element(by.web.id('identifier'))).toExist();
```

Supports [`asSecured()`] on **iOS only**:

```js
await expect(web.element(by.web.label('Hello World!')).asSecured()).toExist();
```

:::note

You might face issues with this expectation on Android. Check [this GitHub issue](https://github.com/wix/Detox/issues/4398) for more information.
Expand All @@ -371,6 +454,32 @@ Negate the expectation.
await expect(web.element(by.web.id('identifier'))).not.toHaveText('Hello World!');
```

Supports [`asSecured()`] on **iOS only**:

```js
await expect(web.element(by.web.label('Hello World!')).asSecured().atIndex(1)).not.toExist();
```

## `asSecured()`

:::note experimental

This API is available only on **iOS** and is currently in the experimental phase. It is subject to changes in the near future.

:::

The `asSecured()` API is designed for interacting with web pages that use secured protocols, such as PCI DSS for payment pages. Use it when the regular API fails to interact with such pages. Detox uses system-level interactions with the webview in these scenarios. This approach is less performant and has fewer APIs.

Example:

```js
await web.element(by.web.label('Submit')).asSecured().tap();
```

### Why use `asSecured()`?

Use `asSecured()` for web pages with secured protocols when regular Detox interactions fail. For CORS issues, consider passing the [`detoxDisableWebKitSecurity`] launch argument to enable less strict security limitations for interacting with secured web views.

[native matchers]: matchers.md

[`by.id()`]: matchers.md#byidid
Expand All @@ -397,6 +506,12 @@ await expect(web.element(by.web.id('identifier'))).not.toHaveText('Hello World!'

[`by.web.tag()`]: webviews.md#bywebtagtag

[`by.web.value()`]: webviews.md#bywebvaluevalue

[`by.web.label()`]: webviews.md#byweblabellabel

[`by.web.type()`]: webviews.md#bywebtypeaccessibilitytype

[`atIndex()`]: webviews.md#atindexindex

[`tap()`]: webviews.md#tap
Expand Down Expand Up @@ -432,3 +547,7 @@ await expect(web.element(by.web.id('identifier'))).not.toHaveText('Hello World!'
[`toExist()`]: webviews.md#toexist

[`not`]: webviews.md#not

[`asSecured()`]: webviews.md#assecured

[`detoxDisableWebKitSecurity`]: device.md#12-detoxdisablewebkitsecuritydisable-webkit-security-ios-only
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This can be a result of various reasons. It is generally up to you to debug and
- You might have forgotten to run `device.launchApp()` in the beginning of your test.
- The app might have crashed before Detox has had a chance to connect to it. To get the crash details, you can run Detox tests with `--record-logs all` CLI option and then inspect the device logs in the artifacts' folder.
- **On Android**, there might be a problem with the native test code in the `DetoxTest.java` file. Revisit the [associated section](../introduction/project-setup.mdx#step-4-additional-android-configuration) in the setup guide.
- **On Android**, your `Network Security Config` may not be recognized. Revisit the [associated section](../introduction/project-setup.mdx#43-enabling-unencrypted-traffic-for-detox) in the setup guide.

### If you _do_ see your app running on the device

Expand Down

0 comments on commit 7345e6c

Please sign in to comment.