Git Product home page Git Product logo

Comments (35)

bootstraponline avatar bootstraponline commented on April 27, 2024 8

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.

from earlgrey.

tirodkar avatar tirodkar commented on April 27, 2024 5

@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

from earlgrey.

bootstraponline avatar bootstraponline commented on April 27, 2024 3

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

from earlgrey.

tirodkar avatar tirodkar commented on April 27, 2024 1

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

from earlgrey.

bootstraponline avatar bootstraponline commented on April 27, 2024

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

from earlgrey.

346285234 avatar 346285234 commented on April 27, 2024

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.

from earlgrey.

346285234 avatar 346285234 commented on April 27, 2024

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

from earlgrey.

tirodkar avatar tirodkar commented on April 27, 2024

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

from earlgrey.

axi0mX avatar axi0mX commented on April 27, 2024

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

from earlgrey.

tirodkar avatar tirodkar commented on April 27, 2024

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

from earlgrey.

bootstraponline avatar bootstraponline commented on April 27, 2024

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

from earlgrey.

khandpur avatar khandpur commented on April 27, 2024

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

from earlgrey.

bootstraponline avatar bootstraponline commented on April 27, 2024

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.

from earlgrey.

AishSundar avatar AishSundar commented on April 27, 2024

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.

from earlgrey.

bootstraponline avatar bootstraponline commented on April 27, 2024

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

from earlgrey.

khandpur avatar khandpur commented on April 27, 2024

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

from earlgrey.

bootstraponline avatar bootstraponline commented on April 27, 2024

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.

from earlgrey.

AishSundar avatar AishSundar commented on April 27, 2024

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 [email protected]
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

from earlgrey.

bootstraponline avatar bootstraponline commented on April 27, 2024

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

from earlgrey.

AishSundar avatar AishSundar commented on April 27, 2024

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 [email protected]
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

from earlgrey.

bootstraponline avatar bootstraponline commented on April 27, 2024

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.

from earlgrey.

ArielSD avatar ArielSD commented on April 27, 2024

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

from earlgrey.

ashisht99xx avatar ashisht99xx commented on April 27, 2024

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

from earlgrey.

bootstraponline avatar bootstraponline commented on April 27, 2024

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.

from earlgrey.

tirodkar avatar tirodkar commented on April 27, 2024

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.

from earlgrey.

vbutzke avatar vbutzke commented on April 27, 2024

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?

from earlgrey.

vbutzke avatar vbutzke commented on April 27, 2024

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.

from earlgrey.

khandpur avatar khandpur commented on April 27, 2024

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

from earlgrey.

specc avatar specc commented on April 27, 2024

hi @khandpur

is handling system dialogs supported on the master branch now?

from earlgrey.

bootstraponline avatar bootstraponline commented on April 27, 2024

is handling system dialogs supported on the master branch now?

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

from earlgrey.

specc avatar specc commented on April 27, 2024

@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

from earlgrey.

khandpur avatar khandpur commented on April 27, 2024

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.

from earlgrey.

esusslin avatar esusslin commented on April 27, 2024

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

from earlgrey.

bootstraponline avatar bootstraponline commented on April 27, 2024

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

from earlgrey.

khandpur avatar khandpur commented on April 27, 2024

EarlGrey 2 is released!
https://github.com/google/EarlGrey/tree/earlgrey2

from earlgrey.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.