Objective-C Support

Link to Objective-C Support copied to clipboard
Free Trial

Follow the Setup axeDevToolsXCUI.xcframework. All the features available on this page are fully supported in Objective-C. Import the header in any file you plan to use the XCUI framework in:

#import <axeDevToolsXCUI/axeDevToolsXCUI-Swift.h>

Utilize the setUp method in your UITests to initialize an AxeDevTools object to interact with available features. Generate an API key at axe.deque.com. If preferred, you can instead authenticate with a username and password.

@interface ObjcUITests : XCTestCase
@end

@implementation ObjcUITests
AxeDevTools* axeDevTools;

- (void)setUp {
    NSError* error;
    axeDevTools = [AxeDevTools loginWithAPIKey:@"API_KEY"
                                      toServer:@""
                                         error:&error];
}

Run a Scan

To run a scan on a screen in your application or on any XCUIElement in your application, create a new test case within your UITests and call the run method within your AxeDevTools object:

- (void)testAccessibilityOfFirstScreen {
    XCUIApplication *app = [[XCUIApplication alloc] init];
    [app launch];

    NSError* error;
    AxeResult* result = [axeDevTools runOnElement:app error:&error];
    XCTAssertEqual(result.failures.count, 0); // This allows you to assert if there are accessibility failures
}

Send Scan to the Dashboard

Once you have the scan, you can send it to the Dashboard by calling the postResult method from the AxeDevTools object:

NSError* error;
[axeDevTools postResult:result withTags:@[@"Build 10.6.1"] withScanName:@"" error:&error];

If you do not want to tag your scan, you can pass in an empty array to the withTags parameter. If you would like to give the scan a custom scan name, you can pass it into the withScanName parameter.

Full Example

#import <axeDevToolsXCUI/axeDevToolsXCUI-Swift.h>
#import <XCTest/XCTest.h>

@interface ObjcUITests : XCTestCase
@end

@implementation ObjcUITests
AxeDevTools* axeDevTools;

- (void)setUp {
    NSError* error;
    axeDevTools = [AxeDevTools loginWithAPIKey:@"API_KEY"
                                      toServer:@""
                                         error:&error];
}

- (void)testAccessibilityOfFirstScreen {
    XCUIApplication *app = [[XCUIApplication alloc] init];
    [app launch];

    NSError* error;
    AxeResult* result = [axeDevTools runOnElement:app error:&error];
    XCTAssertEqual(result.failures.count, 0);
    [axeDevTools postResult:result
                   withTags:@[@"Build 10.6.1"]
               withScanName:@""
                      error:&error];
}

@end

Features

Ignoring Views

Once you're logged in, use the AxeDevTools object to ignore rules for specific views. You can ignore all views of a specific class, or ignore a view with a specific Accessibility Identifier:

NSDictionary* ignoreRules = @{ @"UILabel": @[@"InScrollView"], // ignore InScrollView for all UILabels
                               @"LoginScreen.Button": @[@"TouchTargetSize"] // ignore TouchTargetSize for the view with this accessibility id
};
[[axeDevTools configuration] ignoreWithRulesFor: ignoreRules];

Ignoring Rules

Once you're logged in, use the AxeDevTools object to ignore any rules for an entire scan:

[[axeDevTools configuration] ignoreWithRules:@[@"A11yElementFocusBox"] :true];

You can also re-add rules to the configuration by changing the bool from true to false:

[[axeDevTools configuration] ignoreWithRules:@[@"A11yElementFocusBox"] :false];

Save Scans Locally

Save results locally to utilize the axe DevTools Reporter CLI to build an executive report off a set of scans within your CI/CD pipeline.

A scan will be saved as a .json file. Saving scans locally is only supported within automated testing. If the path and file name are not specified, the results will be named "(APPID)-(CURRENT_SCREEN_TITLE).json" and will be saved in a folder called "AxeDevToolsResults" within your User folder.

Once logged in, use the AxeDevTools object to save your scan as a JSON file. To use the default path and file name, send empty strings to the parameters:

NSError* error;
[axeDevTools saveResult:result toPath:@"" withName:@"" error:&error];