From 774f1704565d1366eb84ba499b913379c046ba82 Mon Sep 17 00:00:00 2001 From: Mina Nagy Zaki Date: Tue, 20 Aug 2019 19:01:01 +0200 Subject: [PATCH] e2e: add utils.readVisibleText until https://github.com/wix/detox/issues/445 is handled --- e2e/utils.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 e2e/utils.ts diff --git a/e2e/utils.ts b/e2e/utils.ts new file mode 100644 index 0000000000..8671fb1fbc --- /dev/null +++ b/e2e/utils.ts @@ -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; + } + } +}