How do I add a Global Tag in Axe DevTools (Attest)

77 Views Asked by At

I'm using Axe DevTools and I'm trying to figure out how to tag multiple scans with the same build information. Right now I have my tests running like this:

class MyTestCase : XCTestCase {
  func myTest() {
    Attest.that(view: view)
      .isAccessible({ result in })
      .andPushResult(withTags: [myBuild])
  }
}

How can I add the myBuild tag globally to all tests that I run?

1

There are 1 best solutions below

0
On BEST ANSWER

I would build my own class that utilizes the Axe DevTools (Attest) APIs. Then have my test cases interact with my own class instead of interacting with Attest itself!

class AccessibilityTestUtils {
  static let buildTag:String = Bundle.main.object(
    forInfoDictionaryKey: "CFBundleShortVersionString"
  ) as! String

  init(build: String) {
    self.buildTag = build
  }
    
  static func runAccessibilityTestOn(aView : View) {
    Attest.that(view: aView).isAccessible({ result in })
      .andPushResult(withTags: [buildTag])   
  } 
}

Example Usage

class YourTestClass {
    func yourTestCase() {
        AccessibilityTestUtils.runAccessibilityTestOn(aView)
    }
}

Note: This approach also protects you from future changes to the Attest library by making it so that you only have to change one line of code in the event of non backwards compatible changes.