kif-framework / KIF

Keep It Functional - An iOS Functional Testing Framework
Other
6.21k stars 912 forks source link

Cannot click on system alerts in Xcode 12 #1156

Open dostrander opened 4 years ago

dostrander commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

KIF uses the unit test framework by design. As long as I’ve used KIF we have not ever been able to interact with system prompts. If the UI test framework can, then I wonder if we can utilize the API there without compromising KIF?

Sent from my iPhone

On Sep 15, 2020, at 1:59 PM, Pierre-Jean Quilleré notifications@github.com wrote:

 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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

pquillere commented 3 years ago

@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 commented 3 years ago

Yes, a simulator does not have system UI barriers like an actual device does. Sorry I was not specific about that. I have always tested on a farm of real hardware. Never tested on simulators as the desktop on corporate machines, even in our labs, are required to be locked out.

Sent from my iPhone

On Sep 15, 2020, at 5:02 PM, Pierre-Jean Quilleré notifications@github.com wrote:

 @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?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

dostrander commented 3 years ago

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

kenji21 commented 3 years ago

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 commented 3 years ago

Any news or ideas on how to solve this issue?

gopito commented 3 years ago

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

sai-kishore-swaminathan commented 2 years ago

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 commented 2 years ago

AFAIK firebase uses real devices which you may be hitting this: https://github.com/kif-framework/KIF/issues/1156#issuecomment-693003450

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 commented 2 years ago

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 commented 1 year ago

@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 commented 1 year ago

Hey @evandorn essentially no we can't do this from KIF right this second. However if we can resolve https://github.com/kif-framework/KIF/issues/1267 and https://github.com/kif-framework/KIF/issues/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 🤞