Skip to content

Commit

Permalink
Updated docs about label. Updated detox init script.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonracz committed Sep 27, 2017
1 parent 5b130fe commit ad42950
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Login flow', () => {
await element(by.id('password')).typeText('123456');
await element(by.label('Login')).tap();

await expect(element(by.label('Welcome'))).toBeVisible();
await expect(element(by.text('Welcome'))).toBeVisible();
await expect(element(by.id('email'))).toNotExist();
});

Expand Down
4 changes: 2 additions & 2 deletions detox/local-cli/templates/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const firstTestContent = `describe('Example', () => {
it('should show hello screen after tap', async () => {
await element(by.id('hello_button')).tap();
await expect(element(by.label('Hello!!!'))).toBeVisible();
await expect(element(by.text('Hello!!!'))).toBeVisible();
});
it('should show world screen after tap', async () => {
await element(by.id('world_button')).tap();
await expect(element(by.label('World!!!'))).toBeVisible();
await expect(element(by.text('World!!!'))).toBeVisible();
});
})`
const initjsContent = `require('babel-polyfill');
Expand Down
2 changes: 1 addition & 1 deletion detox/src/android/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class ExpectElement extends Expect {
return await new MatcherAssertionInteraction(this._element, new TextMatcher(value)).execute();
}
async toHaveLabel(value) {
return await new MatcherAssertionInteraction(this._element, new TextMatcher(value)).execute();
return await new MatcherAssertionInteraction(this._element, new LabelMatcher(value)).execute();
}
async toHaveId(value) {
return await new MatcherAssertionInteraction(this._element, new IdMatcher(value)).execute();
Expand Down
8 changes: 8 additions & 0 deletions docs/APIRef.Expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Expect verifies if a certain value is as expected to be.
- [`.toExist()`](#toexist)
- [`.toNotExist()`](#tonotexist)
- [`.toHaveText()`](#tohavetexttext)
- [`.toHaveLabel()`](#tohavelabellabel)
- [`.toHaveId()`](#tohaveidid)
- [`.toHaveValue()`](#tohavevaluevalue)

Expand Down Expand Up @@ -52,6 +53,13 @@ await expect(element(by.id('RandomJunk959'))).toNotExist();
await expect(element(by.id('UniqueId204'))).toHaveText('I contain some text');
```

### `toHaveLabel(label)`
- Similar to `toHaveText(text)`, but searches by accessibilityLabel (iOS) or by contentDescription (Android)

```js
await expect(element(by.id('UniqueId204'))).toHaveLabel('Done');
```

### `toHaveId(id)`
- In React Native apps, expect UI component to have [`testID`](https://facebook.github.io/react-native/docs/view.html#testid) with that id.
- In native iOS apps, expect UI element to have accesibilityIdentifier with that id.
Expand Down
11 changes: 10 additions & 1 deletion docs/APIRef.Matchers.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Matchers find elements in your app that match one or more properties.

- [`by.id()`](#byidid)
- [`by.text()`](#bytexttext)
- [`by.label()`](#bylabellabel)
- [`by.type()`](#bytypenativeviewtype)
- [`by.traits()`](#bytraitstraits)

Expand Down Expand Up @@ -42,14 +43,22 @@ Find an element by text, useful for text fields, buttons.
```js
await element(by.text('Tap Me'));
```

#### `by.label(label)`
Find an element by accessibilityLabel(iOS) or contentDescription(Android), useful for text fields, buttons.

```js
await element(by.label('Welcome'));
```

#### `by.type(nativeViewType)`
Find an element by native view type.

```js
await element(by.type('RCTImageView'));
```
#### `by.traits([traits])`
Find an element with an accessibility trait.
Find an element with an accessibility trait. (iOS only)

```js
await element(by.traits(['button']));
Expand Down
4 changes: 2 additions & 2 deletions docs/Troubleshooting.RunningTests.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ render() {

```js
await element(by.label('Login')).tap();
await expect(element(by.label('Welcome'))).toBeVisible();
await expect(element(by.text('Welcome'))).toBeVisible();
```

In the test above, after tapping the Login button, the app performs several complex asynchronous operations until the Welcome message is displayed post-login. These can include querying a server, waiting for a response and then running an animated transition to the Welcome screen. Detox attempts to simplify your test code by synchronizing *automatically* with these asynchronous operations. What happens if for some reason the automatic synchronization doesn't work? As a result, Detox will not wait correctly until the Welcome screen appears and instead will continue immediately to the next line and try to run the expectation. Since the screen is not there yet, the test will fail.
Expand All @@ -136,7 +136,7 @@ Full documentation about `waitFor` is available [here](/docs/APIRef.waitFor.md).

```js
await element(by.label('Login')).tap();
await waitFor(element(by.label('Welcome'))).toBeVisible().withTimeout(2000);
await waitFor(element(by.text('Welcome'))).toBeVisible().withTimeout(2000);
```

<br>
Expand Down
14 changes: 7 additions & 7 deletions examples/demo-native-android/e2e/example.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ describe('Example', function () {
});

it('should have welcome screen', function () {
expect(element(by.label('Welcome'))).toBeVisible();
expect(element(by.label('Say Hello'))).toBeVisible();
expect(element(by.label('Say World'))).toBeVisible();
expect(element(by.text('Welcome'))).toBeVisible();
expect(element(by.text('Say Hello'))).toBeVisible();
expect(element(by.text('Say World'))).toBeVisible();
});

it('should show hello screen after tap', function () {
element(by.label('Say Hello')).tap();
expect(element(by.label('Hello!!!'))).toBeVisible();
element(by.text('Say Hello')).tap();
expect(element(by.text('Hello!!!'))).toBeVisible();
});

it('should show world screen after tap', function () {
element(by.label('Say World')).tap();
expect(element(by.label('World!!!'))).toBeVisible();
element(by.text('Say World')).tap();
expect(element(by.text('World!!!'))).toBeVisible();
});

});
4 changes: 2 additions & 2 deletions examples/demo-react-native/e2e/example.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ describe('Example', () => {

it('should show hello screen after tap', async () => {
await element(by.id('hello_button')).tap();
await expect(element(by.label('Hello!!!'))).toBeVisible();
await expect(element(by.text('Hello!!!'))).toBeVisible();
});

it('should show world screen after tap', async () => {
await element(by.id('world_button')).tap();
await expect(element(by.label('World!!!'))).toBeVisible();
await expect(element(by.text('World!!!'))).toBeVisible();
});
});

0 comments on commit ad42950

Please sign in to comment.