Testing Facebook Connect Button #137

staufman opened this Issue Jul 24, 2012 · 5 comments


None yet

4 participants


I'm not sure there is a way to do this but in order to test my login procedure, I need Facebook Connect for authentication. The problem is that FB Connect bounces the user through Safari on the simulator (or the Facebook app on the device) and once this happens, it doesn't look like there is a way for KIF to automate button presses in the app that the user gets bounced to.

Is there any way to make this work? My fallback is to hardcode my FB access token for testing purposes but this of course leaves one big area of my app untested: login/authentication.


I would be interested in this as well.


I'm just not sure there is a good way to handle this case. As a workaround, I am now hardcoding the Facebook access token for my unit test user into the app and short-circuiting the Facebook button code so that it goes directly into my sign up process. No, this isn't ideal because aside from the obvious issue that the unit test is not testing the Facebook button, the access token will also expire at some point necessitating a code change.

But this workaround gives me a little more UI coverage.


I was thinking about combining Frank testing with KIF. Frank is much more than I want for most things, but it may work in combination.. or it may not at all.. lol I haven't looked into it yet, but that's what I was thinking.


I had the same issue. I ended up by testing everything with KIF, and mocking just the part where the apps switch, so I could fake the switching process.

The following code uses OCMock to intercept any attempt to switch application, and set a boolean flag when the switch attempt has been detected (and blocked).

__block id applicationMock;
__block BOOL appDidReceiveOpenURLMessage = NO;

[scenario addStep:[KIFTestStep stepWithDescription:@"Setup mock for FB login" executionBlock:^KIFTestStepResult(KIFTestStep *step, NSError *__autoreleasing *error) {
    applicationMock = [OCMockObject partialMockForObject:[UIApplication sharedApplication]];
    [[[[applicationMock stub] andDo:^(NSInvocation *inv) {
        [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidEnterBackgroundNotification object:[UIApplication sharedApplication]];
        appDidReceiveOpenURLMessage = YES;

    return KIFTestStepResultSuccess;

[scenario addStep:[KIFTestStep stepWithDescription:@"Wait for openURL" executionBlock:^KIFTestStepResult(KIFTestStep *step, NSError *__autoreleasing *error) {
    KIFTestWaitCondition(appDidReceiveOpenURLMessage, error, @"");
    return KIFTestStepResultSuccess;

You can then send a application:openURL:sourceApplication:annotation: message yourself, with the URL Facebook or Safari would have send — and the Facebook login process will resume.

bnickel commented Sep 11, 2013

KIF's boundaries are inside the app so this kind of dependency has to be mocked. I believe, however, I have seen app that think they are logged out bounce over to Facebook for authentication and get immediately bounced back to the app because the app is recognized as approved. You could explore this option.

Closing since this is not a resolvable issue inside KIF. Feel free to discuss this sort of think in the Google Group.

@bnickel bnickel closed this Sep 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment