-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
381ffa7
to
ea3f73d
Compare
Wow! YES! At a glance - seems very sexy... We will review ASAP |
There was a problem hiding this 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:
### `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(); | ||
``` |
There was a problem hiding this comment.
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();
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
There was a problem hiding this comment.
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
- Avoid multiple headings with the same name. - Wrap headings with empty lines.
Those actions works on web elements, and not on web-view element.
87e5861
to
e6197df
Compare
|
No description provided.