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

How to confirm system alert like allow notification #55

Closed
346285234 opened this issue Mar 24, 2016 · 35 comments
Closed

How to confirm system alert like allow notification #55

346285234 opened this issue Mar 24, 2016 · 35 comments

Comments

@346285234
Copy link

If the app is installed at the first time, need to allow notification, how can I confirm it? Is someone encountered?

thumb_img_0233_1024

@bootstraponline
Copy link
Contributor

EarlGrey cannot interact with system permission dialogs. We plan to implement this in the EarlGrey APIs, but in the meantime we recommend that you use other means to dismiss system permission dialogs in your test code.
https://github.com/google/EarlGrey/blob/master/docs/known-issues.md

@346285234
Copy link
Author

Thank you for your reply.
So EarlGrey cannot confirm the notification alert now, but what are the other means? As I am new to UI Test, can you give me some suggestions? Thanks.

@tirodkar
Copy link
Collaborator

@346285234, you should typically be mocking notifications and other data requests in order to prevent the dialogs from coming up. You could also accept the notification manually and re-run your tests. We experimented with using the private UIAutomation framework for this and saw we could achieve this with it. For example, for pressing the left alert button.

@interface SystemAlert : NSObject
- (void)tapLeftButton;
@end

@interface SystemAlert (ForMethodCompletionOnly)
+ (id)localTarget;
- (id)frontMostApp;
- (id)alert;
- (id)buttons;
@end

@implementation SystemAlert

+ (void)load {
  dlopen([@"/Developer/Library/PrivateFrameworks/UIAutomation.framework/UIAutomation" fileSystemRepresentation], RTLD_LOCAL);
}

- (void)tapLeftButton {
  id localTarget = [NSClassFromString(@"UIATarget") localTarget];
  id app = [localTarget frontMostApp];
  id alert = [app alert];
  id button = [[alert buttons] objectAtIndex:0];
  [button tap];
}

@end

@346285234
Copy link
Author

Thank you for your help. I'll have a try.

@tirodkar
Copy link
Collaborator

@346285234, were you able to find a solution for your issue?

@axi0mX
Copy link
Contributor

axi0mX commented Apr 3, 2016

@tirodkar @346285234's screenshot is not from an iOS simulator, so the code snippet above won't work (as far as I know) unless his iOS device is jailbroken, he adds entitlement com.apple.private.hid.client.event-dispatch to his app and uses fake code signing.

@346285234 Is your phone jailbroken?

@tirodkar
Copy link
Collaborator

tirodkar commented May 6, 2016

@346285234, were you able to test the solution out?

@bootstraponline
Copy link
Contributor

bootstraponline commented Jun 14, 2016

thoughts on integrating with Facebook's WebDriverAgentLib which provides alert methods, among other useful features?

@khandpur
Copy link
Collaborator

Briefly looked at the implementation. It's using XCUITest APIs. Doesn't that boil down to #63 ?

@bootstraponline
Copy link
Contributor

bootstraponline commented Jun 14, 2016

Briefly looked at the implementation. It's using XCUITest APIs. Doesn't that boil down to #63 ?

Kind of, the difference is they reimplemented a bunch of the APIs that are broken in XCUITest and have additional features.

@bootstraponline
Copy link
Contributor

I just got the Facebook lib working with EarlGrey and I think it's quite powerful.

  • Built WebDriverAgentLib.framework for release
  • Added to Link Binary with Libraries
  • Updated bridging header:
#import <EarlGrey/EarlGrey.h>

#import <WebDriverAgentLib/WebDriverAgentLib.h>
#import <WebDriverAgentLib/XCUIApplication.h>
  • Now I have full access to all the XCUITest APIs, including the Facebook versions (which are almost always better). Including the ability to deal with alerts.
let alert = FBAlert(application: XCUIApplication.init(privateWithPath: nil, 
                                                             bundleID: "my.app.bundle"))
alert.isPresent()

This is all within the unit testing target, no need for a multi-process model.

@AishSundar
Copy link

I am hitting the same issue where I am unable to automate interacting with SystemAlerts on a real device. It complains saying UIAutomation isn't enabled even though I have enabled it in settings. Looks like I need a jailbroken device to be able to change the setting.

@bootstraponline
Copy link
Contributor

I ended up using TCC.db modifications to prevent system alerts from showing up on simulators.

@khandpur
Copy link
Collaborator

neat. does that work for all types of system alerts?

@bootstraponline
Copy link
Contributor

I think it works for all of them? These are the ones calabash added:

{
      :calendar => "kTCCServiceCalendar",
      :camera => "kTCCServiceCamera",
      :contacts => "kTCCServiceAddressBook",
      :microphone => "kTCCServiceMicrophone",
      :motion => "kTCCServiceMotion",
      :photos => "kTCCServicePhotos",
      :reminders => "kTCCServiceReminders",
      :twitter => "kTCCServiceTwitter"
}

Updating to include new services is easy.

I also figured out how to auto configure the simulator keyboard to use the Facebook recommendations.

@AishSundar
Copy link

Thanks. But as you specified this also works only on a simulator. Any idea
of how to get this working on a real device (not jailbroken)?

On Wed, Jul 13, 2016 at 12:24 PM, bootstraponline notifications@github.com
wrote:

I think it works for all of them? These are the ones calabash added:

{
:calendar => "kTCCServiceCalendar",
:camera => "kTCCServiceCamera",
:contacts => "kTCCServiceAddressBook",
:microphone => "kTCCServiceMicrophone",
:motion => "kTCCServiceMotion",
:photos => "kTCCServicePhotos",
:reminders => "kTCCServiceReminders",
:twitter => "kTCCServiceTwitter"
}

Updating to include new services is easy.

I also figured out how to auto configure the simulator keyboard
https://github.com/bootstraponline/run_loop/commit/984bb22474cf9fa4518d42883568bb5ef7d2a27e
to use the Facebook recommendations.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#55 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ATSuNSV0cCTMP1znHmsr5MsVgvbMrpspks5qVTt2gaJpZM4H3pTM
.

Aishwarya Sundar

@bootstraponline
Copy link
Contributor

I'd expect WebDriverAgentLib to work on real non-jailbroken devices. I haven't verified that though.

@AishSundar
Copy link

It didnt not work the last time I tried to get this going on a device. So
please let me know if you are successful.

On Wed, Jul 13, 2016 at 2:13 PM, bootstraponline notifications@github.com
wrote:

I'd expect WebDriverAgentLib to work on real non-jailbroken devices. I
haven't verified that though.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#55 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ATSuNYhFxcudxDS-Zojv-yUUhwkAB3qGks5qVVUMgaJpZM4H3pTM
.

Aishwarya Sundar

@bootstraponline
Copy link
Contributor

I only test on simulators since physical devices don't scale. If WebDriverAgentLib isn't working on physical devices then you might want to open an issue on their repo since Facebook tests on physical devices.

@ArielSD
Copy link

ArielSD commented Feb 8, 2017

@tirodkar Which private UIAutomation framework, Apple's private UIAutomation framework? How do you access it?

@tirodkar
Copy link
Collaborator

@ArielSD Yes the same. It is still available in Xcode. You'd need to import the headers as is shown in the comment here.

#55 (comment)

I'd prefer waiting on this feature though, since we plan to have it as part of EarlGrey's next major release version, which should support XCUITest.

@ashisht99xx
Copy link

ashisht99xx commented Mar 9, 2017

@bootstraponline I tried integrating WebDriverAgentLib into my project. But control never returns from 2nd line of code.
EarlGrey.select(elementWithMatcher:grey_accessibilityID("continue_as_guest")).perform(grey_tap())
let alert = FBAlert(application: XCUIApplication.init(privateWithPath: nil,bundleID: "com.myapp.dev"))
if alert.isPresent() {
print("**** alert present ")
} else {
print("
alert not present ***")
}

The test completes but none of the print statements get executed. Did you also face such issue ?

@bootstraponline
Copy link
Contributor

WebDriverAgentLib has changed quite a bit since last year. It wouldn't surprise me if this no longer works. Each Xcode release seems to break things. I recommend posting an issue to their tracker and asking if this is a supported use case or not.

UIAutomation.framework should still work. And as @tirodkar mentioned, EG 2.0 should support this use case.

@tirodkar
Copy link
Collaborator

tirodkar commented Mar 9, 2017

Also, this might seem a little hacky but in iOS 10+, you need to have "Privacy - Locations Usage Description" in your Info Plist or so added to be able to throw up System Dialogs. You could remove these keys for your test rig and see what the result is.

@bootstraponline
Copy link
Contributor

https://github.com/wix/AppleSimulatorUtils looks interesting.

@vbutzke
Copy link

vbutzke commented Jun 24, 2017

Has anyone found a consistent solution for this? Requiring someone to click on the button every time the resources are reloaded to execute tests as well as modifying production code to do so do not sound as a very good solution for automated testing... I know those are workarounds but still... This just makes UI testing kind of impossible if you're trying to follow best practices and building a consistent app where testing should not influence the core architecture. I'll keep my research but isn't there any other known solution for this?

@vbutzke
Copy link

vbutzke commented Jun 26, 2017

I found a solution for automated UI testing using Appium:
https://discuss.appium.io/t/ios-alerts-handle-system-alerts-in-ios-simulator/5816/2
If it may help anyone.

@khandpur
Copy link
Collaborator

@vbutzke Happy that you found a solution. Sounds like what you're looking for is a pure black-box testing framework. A white-box framework like EarlGrey gives the test author more control over the AUT by running inside app under test so we usually advise using fakes (or mocks in certain cases) and encourage designing the app with testability in mind.

Just as a quick heads up -- we've already added support for handling system dialogs in EarlGrey 2.0 (based off of XCUITest) which is being developed internally until we've alpha tested it next month.

@specc
Copy link

specc commented Jan 14, 2018

hi @khandpur

is handling system dialogs supported on the master branch now?

@bootstraponline
Copy link
Contributor

is handling system dialogs supported on the master branch now?

Not yet, will be in 2.0 (estimated for Q1 2018).

@specc
Copy link

specc commented Jan 14, 2018

@bootstraponline i see. Any work around for the moment? I see that there is a XCUITest's addUIInterruptionMonitor(withDescription:handler:)
https://developer.apple.com/documentation/xctest/xctestcase/1496273-adduiinterruptionmonitor

@khandpur
Copy link
Collaborator

As @bootstraponline we're planning to open source EarlGrey 2.0 very soon. In the mean time you could work around the system dialog issue either through mocking or accepting it manually on the device which you should only need to do once.

@esusslin
Copy link

Any progress with this? Looking for a robust solution to dismissing UIAlerts for notification requests for all EarlGrey tests - any help is appreciated!

@bootstraponline
Copy link
Contributor

I don't think there will be a great solution until EarlGrey 2 is released.

@khandpur
Copy link
Collaborator

khandpur commented Dec 5, 2018

@khandpur khandpur closed this as completed Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests