fastlane-old / snapshot

Automate taking localized screenshots of your iOS app on every device
https://fastlane.tools
1.95k stars 141 forks source link

UITests failing because of push notification popup #418

Closed ilandbt closed 8 years ago

ilandbt commented 8 years ago

Hi, My UITests are failing so i cant get any screenshots. Its failing because of the push notification popup.

I tried disabling the registration with the "FASTLANE_SNAPSHOT" flag but its not working (the popup is still popping).

        if !NSUserDefaults.standardUserDefaults().boolForKey("FASTLANE_SNAPSHOT") {
            // runtime check that we are in snapshot mode

            let type: UIUserNotificationType = [UIUserNotificationType.Badge, UIUserNotificationType.Alert, UIUserNotificationType.Sound];
            let setting = UIUserNotificationSettings(forTypes: type, categories: nil);
            UIApplication.sharedApplication().registerUserNotificationSettings(setting);
            UIApplication.sharedApplication().registerForRemoteNotifications();
        }
ahknight commented 8 years ago

This is a regression, BTW. I just ran into this after updating the support file for the latest version from a version about three months ago.

KrauseFx commented 8 years ago

@ahknight That's because it's a different technology now, snapshot now uses UI Tests and not UI Testing anymore.

freynolds commented 8 years ago

Having the same issue! Would appreciate a workaround!

ahknight commented 8 years ago

What I wound up doing was Volkswagoning it and only asking for push permissions if I wasn't testing (I looked at the process arguments in my case).

freynolds commented 8 years ago

Ok, good workarround. thanks @ahknight

makadaw commented 8 years ago

I think it makes no sense to ask push notifications on simulator, you can use

if !(TARGET_IPHONE_SIMULATOR)

endif

ahknight commented 8 years ago

That's probably a better idea, as long as you're not automating devices as well (that is, snapshot is outside your normal UI tests).

ohayon commented 8 years ago

i agree with @makadaw that asking for push on the simulator is usually uncalled for. but if it is necessary, i would recommend using some sort of check to verify that you are not running a test before asking for push permissions.

ilandbt commented 8 years ago

@makadaw i added the code like you suggested but the alert is still popping.

        #if !(TARGET_IPHONE_SIMULATOR)
            let type: UIUserNotificationType = [UIUserNotificationType.Badge, UIUserNotificationType.Alert, UIUserNotificationType.Sound];
            let setting = UIUserNotificationSettings(forTypes: type, categories: nil);
            UIApplication.sharedApplication().registerUserNotificationSettings(setting);
            UIApplication.sharedApplication().registerForRemoteNotifications();
        #endif
makadaw commented 8 years ago

@ilandbt Do you check it on simulator? Can you add breakpoint before this block and check is this code actual run?

fastlanebot commented 8 years ago

This issue was migrated to https://github.com/fastlane/fastlane/issues/2499. Please post all further comments there.

fastlane is now a mono repo, you can read more about the change in our blog post. All tools are now available in the fastlane main repo :rocket: