GTXiLib with Swift examples

394 views
Skip to first unread message

Steve Rushby

unread,
Feb 24, 2020, 9:31:42 AM2/24/20
to ios-accessibility
Good afternoon,

I've been looking to integrate an accessibility library into our latest SwiftUI project.

It appears there's a lack of documentation and online discussion in places like SO regarding this library and its implementation.  I have a couple of questions:

1.  Does GTXiLib work with SwiftUI and XCTestCase?  The only conversations i found allude to requiring EarlGrey framework?
2.  Are there any Swift example projects that anyone is aware of that use this library?
3.  Is it as simple as adding the library, overriding the setUp function with required code and running test as normal?
4.  Is there a particular action required of the test to hit GTXiLib functionality?

I got to the point of using the following setUp code inside a test class:

class MyTest: XCTestCase {

    

    override class func setUp() {

        super.setUp()

        let checksToBeInstalled: [GTXChecking] = GTXChecksCollection.allGTXChecks()

        let tmp = GTXTestSuite(allTestsIn: self)

        GTXiLib.install(on: tmp ?? GTXTestSuite(), checks: checksToBeInstalled, elementBlacklists: [])

     }

}


But no matter what project i attempt to add this into it never reports any accessibility issues, even after removing labels etc.

One of the 2 GTXiLib questions on StackOverflow is unanswered, and is basically asking the same thing i am:  


I also noted a user asking how this was done here (but a fully working example was never posted for others):  


Thanks for reading - and it'd be really helpful if someone has an example of GTXiLib used with Swift!

Cheers

Steve



Deepthini Lansakara

unread,
Feb 17, 2021, 3:45:49 PM2/17/21
to ios-accessibility
Hi,

I am having the same issue as above. I don't get any errors even after removing labels.  Any suggestion ?

Thanks
Deepthi

Gautam J

unread,
Mar 1, 2021, 3:35:34 PM3/1/21
to ios-accessibility
Can one of you reply how you tried removing labels? Because what I noticed is that removing labels from the button still reports the title of the button as the label. To verify GTX can catch this, please remove the title of the button so that you have a button with empty title, this must trigger the failures I was able to verify this locally with a clean build on an empty project in ObjectiveC XCUITests.

Mary Martinez

unread,
Apr 6, 2021, 8:28:24 PM4/6/21
to ios-accessibility
Hi y'all,

I recently integrated this into Swift so I'll share what I learned. I also just posted this as an answer to the SO question.

The missing link is that in your test case you have to create the view and add it to the keyWindow (make sure your view's fame is >0).

This is because the library uses the keyWindow as it's root object and then traverses its subviews to run the checks on. https://github.com/google/GTXiLib/blob/d9161c0cefd07556cd97739fdc8862a2711bc1d3/Classes/GTXiLibCore.m#L159

Screen Shot 2021-04-06 at 5.25.40 PM.png

This is the error I get.

Screen Shot 2021-04-06 at 5.27.12 PM.png

I would also recommend doing some type of window management to support these tests. In my case, I saw some accessibility failures because other objects in the window were being tested that were not the view I was interested in testing.

Final note: I ended up integrating GTXiLib 3.1 because newer versions depend on c++ which requires importing protobuf. There was an issue we encountered with protobuf not playing well with Carthage. May only be an issue with Carthage though since the Google team appears to be using Cocoapods.

Hope this helps!

Mary

Reply all
Reply to author
Forward
0 new messages