-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
until wix/Detox#445 is handled
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |