Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add web views API documentation. #3731

Merged
merged 8 commits into from
Dec 12, 2022
Merged

Conversation

asafkorem
Copy link
Contributor

No description provided.

@asafkorem
Copy link
Contributor Author

asafkorem commented Nov 23, 2022

@asafkorem asafkorem linked an issue Nov 23, 2022 that may be closed by this pull request
@d4vidi
Copy link
Collaborator

d4vidi commented Nov 23, 2022

Wow! YES! At a glance - seems very sexy... We will review ASAP

@d4vidi d4vidi self-assigned this Nov 24, 2022
Copy link
Collaborator

@noomorph noomorph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @asafkorem ! You have my review here, in your own repository as a pull request:

asafkorem#9

Comment on lines +237 to +287
### `runScript(script)`

Run the specified script on the element.

The script should be a string that contains a valid JavaScript function.
It will be called with that element as the first argument.

```js
const webElement = web.element(by.web.id('identifier'));
await webElement.runScript(`function foo(element) {
console.log(element);
}`);
```

### `runScriptWithArgs(script, ...args)`

Run the specified script on the element with extra arguments.

The script should be a string that contains a valid JavaScript function.
It will be called with the specified arguments and the element itself as the last argument.

```js
const webElement = web.element(by.web.id('identifier'));
await webElement.runScriptWithArgs(`function foo(arg1, arg2, element) {
console.log(arg1, arg2, element);
}`, "foo", 123);
```

### `getCurrentUrl()`

Get the current URL of the web view.

:::note
Although this action returns the URL of the presented web document, it can be called from an inner element only (for example, an iframe id or the HTML) and not from the root native web view element itself.
:::

```js
const url = await web.element(by.web.id('identifier')).getCurrentUrl();
```

### `getTitle()`

Get the title of the web view.

:::note
Although this action returns the title of the presented web document, it can be called from an inner element only (for example, an iframe id or the HTML) and not from the root native web view element itself.
:::

```js
const title = await web.element(by.web.id('identifier')).getTitle();
```
Copy link
Contributor Author

@asafkorem asafkorem Dec 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like these APIs. It can be useful when testing an inner iframe URL or title, but not convenient when trying to test the root document frame. It may work when targeting the HTML tag element using by.web.tag("html") or IDK, I haven't tried that yet and I can't find any usage of this on Detox tests. I wonder if this API may even be redundant.

We should expose the same APIs for the web-view element (the root native element), for running the same operations on the web-view element (the main frame).

The Espresso code we're running with this APIs is:

return getWebViewInteraction().withElement(get()).perform(Atoms.getCurrentUrl()).get();

https://github.com/wix/Detox/blob/master/detox/android/detox/src/full/java/com/wix/detox/espresso/web/WebElement.java#L65-L79 (WebElement)

While we should enable operating on the root frame without specifying the inner element (from WebViewElement object) is something like:

return getWebViewInteraction().reset().perform(Atoms.getCurrentUrl()).get();

Should be in the same API level with web.element(..) https://github.com/wix/Detox/blob/master/detox/android/detox/src/full/java/com/wix/detox/espresso/web/WebViewElement.java

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened a new issue for this: #3752

@asafkorem asafkorem assigned asafkorem and unassigned d4vidi Dec 11, 2022
@asafkorem asafkorem requested review from noomorph and removed request for d4vidi December 11, 2022 13:38
@noomorph
Copy link
Collaborator

:shipit:

@asafkorem asafkorem merged commit 0a9cd93 into wix:master Dec 12, 2022
@asafkorem asafkorem deleted the docs/web-views branch December 12, 2022 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Web-views API documentation
3 participants