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

[Android] label -> contentDescription #293

Merged
merged 4 commits into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ describe('Login flow', () => {

await element(by.id('email')).typeText('john@example.com');
await element(by.id('password')).typeText('123456');
await element(by.label('Login')).tap();
await element(by.text('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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -340,7 +340,7 @@ function element(matcher) {

const by = {
accessibilityLabel: (value) => new LabelMatcher(value),
label: (value) => new TextMatcher(value),
label: (value) => new LabelMatcher(value),
id: (value) => new IdMatcher(value),
type: (value) => new TypeMatcher(value),
traits: (value) => new TraitsMatcher(value),
Expand Down
1 change: 1 addition & 0 deletions detox/test/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Choose a reason for hiding this comment

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

Can't get the point of this line in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was missing for an Android test. (Which is not triggered by CI yet.)

The whole point of the PR was to make the test suite cross platform.


<uses-sdk
android:minSdkVersion="16"
Expand Down
16 changes: 8 additions & 8 deletions detox/test/e2e/a-sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ describe('Sanity', () => {
});

beforeEach(async () => {
await element(by.label('Sanity')).tap();
await element(by.text('Sanity')).tap();
});

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

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

it('should show world screen after tap', async () => {
await element(by.label('Say World')).tap();
await expect(element(by.label('World!!!'))).toBeVisible();
await element(by.text('Say World')).tap();
await expect(element(by.text('World!!!'))).toBeVisible();
});
});
14 changes: 7 additions & 7 deletions detox/test/e2e/b-matchers.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
describe('Matchers', () => {
beforeEach(async () => {
await device.reloadReactNative();
await element(by.label('Matchers')).tap();
await element(by.text('Matchers')).tap();
});

it('should match elements by (accesibility) label', async () => {
await element(by.label('Label')).tap();
await expect(element(by.label('Label Working!!!'))).toBeVisible();
await expect(element(by.text('Label Working!!!'))).toBeVisible();
});

it('should match elements by (accesibility) id', async () => {
await element(by.id('UniqueId345')).tap();
await expect(element(by.label('ID Working!!!'))).toBeVisible();
await expect(element(by.text('ID Working!!!'))).toBeVisible();
});

it('should match elements by type (native class)', async () => {
Expand All @@ -26,7 +26,7 @@ describe('Matchers', () => {
// Accessibility Inspector in the simulator can help investigate traits
it(':ios: should match elements by accesibility trait', async () => {
await element(by.traits(['button', 'text'])).tap();
await expect(element(by.label('Traits Working!!!'))).toBeVisible();
await expect(element(by.text('Traits Working!!!'))).toBeVisible();
});

it('should match elements with ancenstor (parent)', async () => {
Expand All @@ -48,13 +48,13 @@ describe('Matchers', () => {
});

it('should match elements by using two matchers together with and', async () => {
await expect(element(by.id('UniqueId345').and(by.label('ID')))).toExist();
await expect(element(by.id('UniqueId345').and(by.label('RandomJunk')))).toNotExist();
await expect(element(by.id('UniqueId345').and(by.text('ID')))).toExist();
await expect(element(by.id('UniqueId345').and(by.text('RandomJunk')))).toNotExist();
});

// waiting to upgrade EarlGrey version in order to test this (not supported in our current one)
it.skip('should choose from multiple elements matching the same matcher using index', async () => {
await expect(element(by.label('Product')).atIndex(2)).toHaveId('ProductId002');
await expect(element(by.text('Product')).atIndex(2)).toHaveId('ProductId002');
});

});
44 changes: 22 additions & 22 deletions detox/test/e2e/c-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,81 @@ describe('Actions', () => {
});

beforeEach(async () => {
await element(by.label('Actions')).tap();
await element(by.text('Actions')).tap();
});

it('should tap on an element', async () => {
await element(by.label('Tap Me')).tap();
await expect(element(by.label('Tap Working!!!'))).toBeVisible();
await element(by.text('Tap Me')).tap();
await expect(element(by.text('Tap Working!!!'))).toBeVisible();
});

it('should long press on an element', async () => {
await element(by.label('Tap Me')).longPress();
await expect(element(by.label('Long Press Working!!!'))).toBeVisible();
await element(by.text('Tap Me')).longPress();
await expect(element(by.text('Long Press Working!!!'))).toBeVisible();
});

it('should multi tap on an element', async () => {
await element(by.id('UniqueId819')).multiTap(3);
await expect(element(by.id('UniqueId819'))).toHaveLabel('Taps: 3');
await expect(element(by.id('UniqueId819'))).toHaveText('Taps: 3');
});

it('should tap on an element at point', async () => {
await element(by.id('View7990')).tapAtPoint({x:180, y:140});
await expect(element(by.id('UniqueId819'))).toHaveLabel('Taps: 1');
await expect(element(by.id('UniqueId819'))).toHaveText('Taps: 1');
});

// Backspace is supported by using "\b" in the string. Return key is supported with "\n"
it('should type in an element', async () => {
await element(by.id('UniqueId937')).tap();
await element(by.id('UniqueId937')).typeText('passcode');
await expect(element(by.label('Type Working!!!'))).toBeVisible();
await expect(element(by.text('Type Working!!!'))).toBeVisible();
});

it('should clear text in an element', async () => {
await element(by.id('UniqueId005')).tap();
await element(by.id('UniqueId005')).clearText();
await expect(element(by.label('Clear Working!!!'))).toBeVisible();
await expect(element(by.text('Clear Working!!!'))).toBeVisible();
});

it('should replace text in an element', async () => {
await element(by.id('UniqueId006')).tap();
await element(by.id('UniqueId006')).replaceText('replaced_text');
await expect(element(by.label('Replace Working!!!'))).toBeVisible();
await expect(element(by.text('Replace Working!!!'))).toBeVisible();
});

// directions: 'up'/'down'/'left'/'right'
it('should scroll for a small amount in direction', async () => {
await expect(element(by.label('Text1'))).toBeVisible();
await expect(element(by.label('Text4'))).toBeNotVisible();
await expect(element(by.text('Text1'))).toBeVisible();
await expect(element(by.text('Text4'))).toBeNotVisible();
await expect(element(by.id('ScrollView161'))).toBeVisible();
await element(by.id('ScrollView161')).scroll(100, 'down');
await expect(element(by.label('Text1'))).toBeNotVisible();
await expect(element(by.label('Text4'))).toBeVisible();
await expect(element(by.text('Text1'))).toBeNotVisible();
await expect(element(by.text('Text4'))).toBeVisible();
await element(by.id('ScrollView161')).scroll(100, 'up');
await expect(element(by.label('Text1'))).toBeVisible();
await expect(element(by.label('Text4'))).toBeNotVisible();
await expect(element(by.text('Text1'))).toBeVisible();
await expect(element(by.text('Text4'))).toBeNotVisible();
});

it('should scroll for a large amount in direction', async () => {
await expect(element(by.label('Text6'))).toBeNotVisible();
await expect(element(by.text('Text6'))).toBeNotVisible();
await element(by.id('ScrollView161')).scroll(200, 'down');
await expect(element(by.label('Text6'))).toBeVisible();
await expect(element(by.text('Text6'))).toBeVisible();
});

// edges: 'top'/'bottom'/'left'/'right'
it('should scroll to edge', async () => {
await expect(element(by.label('Text8'))).toBeNotVisible();
await expect(element(by.text('Text8'))).toBeNotVisible();
await element(by.id('ScrollView161')).scrollTo('bottom');
await expect(element(by.label('Text8'))).toBeVisible();
await expect(element(by.text('Text8'))).toBeVisible();
await element(by.id('ScrollView161')).scrollTo('top');
await expect(element(by.label('Text1'))).toBeVisible();
await expect(element(by.text('Text1'))).toBeVisible();
});

// TODO - swipe is not good enough for triggering pull to refresh. need to come up with something better
// directions: 'up'/'down'/'left'/'right', speed: 'fast'/'slow'
xit('should swipe down until pull to reload is triggered', async () => {
await element(by.id('ScrollView799')).swipe('down', 'slow');
await expect(element(by.label('PullToReload Working!!!'))).toBeVisible();
await expect(element(by.text('PullToReload Working!!!'))).toBeVisible();
});

it('should wait for long timeout', async () => {
Expand Down
4 changes: 2 additions & 2 deletions detox/test/e2e/d-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('Assertions', () => {
});

beforeEach(async () => {
await element(by.label('Assertions')).tap();
await element(by.text('Assertions')).tap();
});

it('should assert an element is visible', async () => {
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('Assertions', () => {
});

it('should assert an element has (accessibility) id', async () => {
await expect(element(by.label('I contain some text'))).toHaveId('UniqueId204');
await expect(element(by.text('I contain some text'))).toHaveId('UniqueId204');
});

// for example, the value of a UISwitch in the "on" state is "1"
Expand Down
8 changes: 4 additions & 4 deletions detox/test/e2e/e-waitfor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('WaitFor', () => {
beforeEach(async() => {
await device.reloadReactNative();
await element(by.label('WaitFor')).tap();
await element(by.text('WaitFor')).tap();
});

it('should wait until an element is created and exists in layout', async () => {
Expand All @@ -23,9 +23,9 @@ describe('WaitFor', () => {
});

it('should find element by scrolling until it is visible', async() => {
await expect(element(by.label('Text5'))).toBeNotVisible();
await waitFor(element(by.label('Text5'))).toBeVisible().whileElement(by.id('ScrollView630')).scroll(50, 'down');
await expect(element(by.label('Text5'))).toBeVisible();
await expect(element(by.text('Text5'))).toBeNotVisible();
await waitFor(element(by.text('Text5'))).toBeVisible().whileElement(by.id('ScrollView630')).scroll(50, 'down');
await expect(element(by.text('Text5'))).toBeVisible();
});

});
38 changes: 19 additions & 19 deletions detox/test/e2e/f-device.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
describe('Device', () => {
it('reloadReactNative - should tap successfully', async () => {
await device.reloadReactNative();
await element(by.label('Sanity')).tap();
await element(by.label('Say Hello')).tap();
await expect(element(by.label('Hello!!!'))).toBeVisible();
await element(by.text('Sanity')).tap();
await element(by.text('Say Hello')).tap();
await expect(element(by.text('Hello!!!'))).toBeVisible();
});

it('relaunchApp - should tap successfully', async () => {
await device.relaunchApp();
await element(by.label('Sanity')).tap();
await element(by.label('Say Hello')).tap();
await expect(element(by.label('Hello!!!'))).toBeVisible();
await element(by.text('Sanity')).tap();
await element(by.text('Say Hello')).tap();
await expect(element(by.text('Hello!!!'))).toBeVisible();
});

it('relaunchApp({delete: true}) - should tap successfully', async () => {
await device.relaunchApp({delete: true});
await element(by.label('Sanity')).tap();
await element(by.label('Say Hello')).tap();
await expect(element(by.label('Hello!!!'))).toBeVisible();
await element(by.text('Sanity')).tap();
await element(by.text('Say Hello')).tap();
await expect(element(by.text('Hello!!!'))).toBeVisible();
});

it('uninstall() + install() + relaunch() - should tap successfully', async () => {
await device.uninstallApp();
await device.installApp();
await device.relaunchApp();
await element(by.label('Sanity')).tap();
await element(by.label('Say Hello')).tap();
await expect(element(by.label('Hello!!!'))).toBeVisible();
await element(by.text('Sanity')).tap();
await element(by.text('Say Hello')).tap();
await expect(element(by.text('Hello!!!'))).toBeVisible();
});

it('launchApp({newInstance: true}) + sendToHome() + launchApp() - should bring up previous instance', async () => {
await device.launchApp({newInstance: true});
await element(by.label('Sanity')).tap();
await element(by.label('Say Hello')).tap();
await element(by.text('Sanity')).tap();
await element(by.text('Say Hello')).tap();
await device.sendToHome();
await device.launchApp();

await expect(element(by.label('Hello!!!'))).toBeVisible();
await expect(element(by.text('Hello!!!'))).toBeVisible();
});

it('resetContentAndSettings() + install() + relaunch() - should tap successfully', async () => {
await device.resetContentAndSettings();
await device.installApp();
await device.launchApp({ newInstance: true });
await element(by.label('Sanity')).tap();
await element(by.label('Say Hello')).tap();
await expect(element(by.label('Hello!!!'))).toBeVisible();
await element(by.text('Sanity')).tap();
await element(by.text('Say Hello')).tap();
await expect(element(by.text('Hello!!!'))).toBeVisible();
});

describe('device orientation', () => {
beforeEach(async() => {
await device.reloadReactNative();
await element(by.label('Orientation')).tap();
await element(by.text('Orientation')).tap();

// Check if the element which input we will test actually exists
await expect(element(by.id('currentOrientation'))).toExist();
Expand Down
Loading