Objective-C Support

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard
Not for use with personal data

Follow the steps to get the axeDevToolsXCUI framework. 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 startScanSessionWithApiKey:@"API_KEY"
                                          axeAccountUrl:@""
                                          projectId:@"DEVHUB_PROJECT_ID"
                                          axeUploadResults:YES
                                          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 Axe Developer Hub

Once you have the scan, you can send it to Axe Developer Hub 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 ignoreRule:AxeRuleIdColorContrast onElementWithId:@"loginButton"]; <!-- one call per rule -->

Ignoring Rules

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

[axeDevTools ignoreRule:AxeRuleIdColorContrast];  <!-- one call per rule -->
note

If you opt to ignore a rule in your tests, you can not switch it back on. You should decide ignores before scanning and use a separate AxeDevTools instance for a different set.

Save Scans Locally

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];