Skip to content

Commit

Permalink
chore(e2e): add utils.readVisibleText
Browse files Browse the repository at this point in the history
until wix/Detox#445 is handled
  • Loading branch information
mnzaki committed Sep 12, 2019
1 parent aa6e4d5 commit 02cacad
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect } from 'detox'

// courtsey of https://github.com/wix/detox/issues/445#issuecomment-514801808
export const readVisibleText = async (testID: string) => {
try {
await expect(element(by.id(testID))).toHaveText('_you_cant_possible_have_this_text_')
throw 'are you kidding me?'
} catch (error) {
if (device.getPlatform() === 'ios') {
const start = `accessibilityLabel was "`
const end = '" on '
const errorMessage = error.message.toString()
const [, restMessage] = errorMessage.split(start)
const [label] = restMessage.split(end)
return label
} else {
const start = 'Got:';
const end = '}"';
const errorMessage = error.message.toString();
const [, restMessage] = errorMessage.split(start);
const [label] = restMessage.split(end);
const value = label.split(',');
var combineText = value.find((i: string) => i.includes('text=')).trim();
const [, elementText] = combineText.split('=');
return elementText;
}
}
}

0 comments on commit 02cacad

Please sign in to comment.