Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot click on system alerts in Xcode 12 #1156

Open
dostrander opened this issue Jul 7, 2020 · 14 comments
Open

Cannot click on system alerts in Xcode 12 #1156

dostrander opened this issue Jul 7, 2020 · 14 comments

Comments

@dostrander
Copy link
Contributor

In Xcode12 it seems that UIAutomation has been removed which is the mechanism we use to click on system alerts.

We need to look into another mechanism to click on system alerts in Xcode12.

@pquillere
Copy link

Hi @dostrander! Did you have a chance to look into this issue?

I had a quick look at it yesterday, but the only other way I know of to access alerts is through XCUIApplication which is only available in a UI Test Target. But KIF is using a Unit Test Target to drive the UI.

@dostrander
Copy link
Contributor Author

@pquillere I have not unfortunately. Hopefully going to have time in the coming weeks. Might have to think of another way to go about this.

If we can't find a way we may have to deprecate clicking on system alerts and resort to exposing a suppression of the system alerts rather than a mechanism to click on them. Open to suggestions on this!

@mikelupo
Copy link
Contributor

mikelupo commented Sep 15, 2020 via email

@pquillere
Copy link

@mikelupo We've been able to use it for the push notification authorization alert. That would only work on a simulator though. What work around have you been using to interact with system alerts during UI testing?

@dostrander How would the "suppression of the system alerts" work?

@mikelupo
Copy link
Contributor

mikelupo commented Sep 15, 2020 via email

@dostrander
Copy link
Contributor Author

@pquillere To possibly swizzle the asking of permissions of system alerts to automatically give the permission. Need to look into it more

@kenji21
Copy link
Contributor

kenji21 commented Nov 25, 2020

Running -[SystemAlertTests testAuthorizingLocationServicesAndNotificationsScheduling] make 100% cpu due to this loop:

    UIATarget *target = nil;
    while (!target) {
        @try {
            target = [self target];
        }
        @catch (NSException *exception) { }
        @finally { }
    }

as [self target] is:

- (UIATarget *)target {
    return [NSClassFromString(@"UIATarget") localTarget];
}

Because class UIATarget doesn't exists as UIAutomation framework not available on iOS 14

From what I looked at, after viewing APIs offered for UI Tests (https://developer.apple.com/documentation/xctest/xctestcase/handling_ui_interruptions)

Your app performs an action that causes the operating system to present a modal UI. An example is an action that presents a photo picker, which may make the system request access to photos if the user hasn’t already granted it.

is coded in XCTest framework, so I tried to use it:

    [self addUIInterruptionMonitorWithDescription:@"somedesc" handler:^BOOL(XCUIElement * _Nonnull interruptingElement) {
        NSLog(@"UIInterruptionMonitor : %@", interruptingElement);
        return false;
    }];

But the handler never gets executed

As it works on UI Test bundle, not Unit Test one, I think it is related to how the UI tested app is launched (and you can launch your app multiple times per test)

@SOSwifty
Copy link

SOSwifty commented Mar 1, 2021

Any news or ideas on how to solve this issue?

@gopito
Copy link

gopito commented Mar 25, 2021

I have used https://github.com/wix/AppleSimulatorUtils in Test Pre-Action as WorkAround

@sai-kishore-swaminathan

Any news on this issue ? Until now I was using XCUI to dismiss the system alerts, But I started running the tests on firebase testlab and the app gets stuck on the alert sometimes.

@dostrander
Copy link
Contributor Author

AFAIK firebase uses real devices which you may be hitting this: #1156 (comment)

However, i have not been able to look into this issue yet. It is likely going to require some reverse engineering into what XCUI does to dismiss alerts

@sai-kishore-swaminathan

Thank you @dostrander . Looking forward to this. Currently we are running KIF on firebase using flank.

Also, Im curious how others run KIF tests.

  1. Does everybody use simulators or run it on their local machine only ?
  2. Or do they run it on their CI ? If yes, how do they get reports and logs on failing tests?
  3. Is there another service that people use commonly (other than Firebase) to run KIF tests on simulators?

It would be super useful for us to learn about what others follow because the only issue with running them on firebase is that its run on real device and we can't close the alerts.

@evandorn
Copy link

@sai-kishore-swaminathan I'm moving my tests over to the same setup (KIF on firebase with Flank). Also being hit by failures with permissions alerts. Were you able to resolve this?

@dostrander
Copy link
Contributor Author

Hey @evandorn essentially no we can't do this from KIF right this second. However if we can resolve #1267 and #1266 we should be also able to get this to work again.

These dialogs (along with the other issues) are out of process and since we are an in process test we can't access them currently. We need to do some reverse engineering on how XCUI works and see if we can mimic that behavior using private APIs. Once we do that I think we will be able to resolve these types of issues 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants