Reputation: 11
I'm working on adding OS dialog handling to iOS e2e tests with Detox. There is however an issue where an OS permission dialog sometimes stays open after a test fails, which in turn causes any subsequent tests to fail because of the OS dialog blocking visibility of elements.
I added a workaround function that's run on beforeAll
during setupAfterEnv
, but while it works locally the beforeAll
hook times out most of the time when being run in a pipeline environment. The function simply tries to dismiss any leftover OS dialogs with try-catch to allow the test run to continue.
Here's the code:
// Close open OS dialogs without throwing an error if not found
export const closePreviousOSDialogs = async () => {
try {
await expect(system.element(by.system.label('Ask App Not to Track'))).toExist();
await system.element(by.system.label('Ask App Not to Track')).tap();
} catch {
// Do nothing
}
try {
await expect(system.element(by.system.label('Don’t Allow'))).toExist();
await system.element(by.system.label('Don’t Allow')).tap();
} catch {
// Do nothing
}
};
beforeAll(async () => {
await closePreviousOSDialogs();
});
The error we get in the pipeline
thrown: "Exceeded timeout of 60000 ms for a hook.
Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."
> 9 | beforeAll(async () => {
| ^
10 | await closePreviousOSDialogs();
11 | }, 60000);
Is there something wrong with the code that causes it to time out in the pipeline, or could there be a different solution for closing all OS dialogs?
The app is using detox: 20.27.2
and react-native: 0.75.4
.
Upvotes: 0
Views: 46