(WIP) Support regex in matchers
Describe your idea
Support regular expression in Detox matchers
Specifically in by.text(), by.label().
This can be useful since text and labels may include dynamic content (e.g. date).
Also, I suggest to change the current API, from: https://github.com/wix/Detox/blob/246317d3ee5b7587bb966c78204b5def5b72dfaf/detox/index.d.ts#L804
To:
text(text: string | RegExp): NativeMatcher;
Usage example
This code will find an element with the text "The year is 2023", if exists:
const someElement = element(by.text(/The year is: \d{4}/));
While this code won't:
const someElement = element(by.text('The year is: \d{4}'));
Why not dynamically recognize instanceof RegExp versus string?
Why not dynamically recognize
instanceof RegExpversus string?
Sounds great, let's do it this way.
@asafkorem the only pitfall I see is that we might need to standardize RegExp mechanisms between iOS/Android/JS...
|
|
@noomorph that is spot on. We've somehow manged to overcome that in the context of the URL's blacklist - we could revisit and hopefully replicate.
Nevertheless I'd like this kind of an API to come with a warning of some sort, that would explain that ideally, whichever text we trying to match should be deterministic to the point it can be predetermined down to the character. Of course, this is not always the case in unmocked tests, but generally this should be the preferred situation.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back.
Thank you for your contributions!
For more information on bots in this reporsitory, read this discussion.
The issue has been closed for inactivity.
This is super useful when working with iOS elements because you can't seem to expose testIDs (or equivalent) so I'm using accessibilityLabel to perform the function of both an identifier and additional state.
Is someone working on this enhancement?
Not really, @asafkorem 's been busy last months trying to release Detox 21 with XCUITest.
@asafkorem would you mind to take this issue to the final mile? Looks like there is demand for it, 10*👍 already
Side note (because I couldn't find it easily beforehand): The work that's been put into see is available in this old branch - optimize-app-fix-regression
This feature was released in version 20.11.0, thanks to @andrius-girdzius!