objective-cxctest

How to open safari using XCTest


I am new to XCTest and am trying open the Safari app in my iPhone but it's not working. Is there any way to achieve this?

Here's what I've tried.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.ggogle.com"]];

Solution

  • It is not possible to open safari using XCTest. I have tried the following, it gives error "App accessibility isn't loaded".

    Declare the XCUIApplication private methods interface in Brigding-Header.h:

    @interface XCUIApplication (Private)
    - (id)initPrivateWithPath:(NSString *)path bundleID:(NSString *)bundleID;
    - (void)resolve;
    @end
    

    Then try to open safari:

    let safari : XCUIApplication = XCUIApplication(privateWithPath: nil, bundleID: "com.apple.safari")
    safari.launch();