Not getting accessibility errors in unit test
Hi I have tried using this framework in swift project. I have setup the test case like this
override static func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
var gTXChecking : [GTXChecking] = []
guard let checkForAXLabelPresent = GTXChecksCollection.checkForAXLabelPresent() else {
fatalError("Fatal Error")
}
guard let checkForAXLabelNotPunctuated = GTXChecksCollection.checkForAXLabelNotPunctuated() else {
fatalError("Fatal Error")
}
gTXChecking.append(checkForAXLabelPresent)
let newCheck = GTXCheckBlock.gtxCheck(withName: "label don't have accessibility") { (element, error) -> Bool in
if (element as AnyObject).accessibilityLabel == nil {
return false
}
return true
}
gTXChecking.append(checkForAXLabelNotPunctuated)
gTXChecking.append(newCheck)
GTXiLib.install(on: GTXTestSuite(allTestsIn: self), checks: gTXChecking, elementBlacklists: [])
}
When I am running test cases it is not throwing any error(even if I have not set accessibility labels and text to UILable or UIButton.)
Hey @sishuiOS ! Can you find any solution for this? I have similar case with UI testing. And I do not get any errors for my UI tests.
@sishuiOS is this an XCTest or XCUITest? see this comment for more details
@niksawtschuk this is Unit test(XCTest) .
class testGtxiLibTests: XCTestCase {
private var sut: ViewController!
override static func setUp() {
super.setUp()
var checkArr: [GTXChecking] = []
guard let checkFirst = GTXChecksCollection.checkForAXLabelPresent() else {
fatalError()
}
guard let checkSecond = GTXChecksCollection.checkForAXLabelNotPunctuated() else {
fatalError()
}
guard let checkThird = GTXChecksCollection.checkForMinimumTappableArea() else {
fatalError()
}
checkArr.append(checkFirst)
checkArr.append(checkSecond)
checkArr.append(checkThird)
GTXiLib.install(on: GTXTestSuite(allTestsIn: self), checks: checkArr, elementBlacklists: [])
}
override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
if let sut = storyBoard.instantiateViewController(withIdentifier: "ViewController") as? ViewController {
self.sut = sut
_ = self.sut.view
}
}
func testController() {
XCTAssertNotNil(sut.view)
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
sut = nil
}
}
This is my sample code for Unit test and following is the code for viewController
class ViewController: UIViewController {
private let button = UIButton(frame: CGRect(x: 100, y: 100, width: 10, height: 10))
private let label = UILabel(frame: CGRect(x: 100, y: 300, width: 100, height: 50))
@IBOutlet weak private var buttonInterface: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
button.backgroundColor = .green
button.isAccessibilityElement = true
button.setTitle("Test Button", for: .normal)
self.view.addSubview(button)
button.accessibilityLabel = "button"
label.backgroundColor = .orange
label.isAccessibilityElement = true
label.text = "Lable text"
self.view.addSubview(button)
self.view.addSubview(label)
label.accessibilityLabel = "label."
buttonInterface.isAccessibilityElement = true
}
}
You can see clearly in ViewController label has incorrect accessibility identifier(as . is appended in the end) and button has incorrect size (10*10), But still this class pass the test cases. Am i missing something???
@sishuiOS What do you see on the simulator screen when you run this test? Does that view controller actually appear? Try setting the window's view controller to be the one you want to test before each test.
Yes view controller appears on simulator on running the tests and tests are passed. 😔 If a sample app is provided with the framework with explanation how to implement unit test would be a great help 🙏
Hey @sishuiOS, could you please try : 'override class func setUp()' (which ensures to call setUp() only once!) Thank you!
@sishuiOS do you mind trying to use EarlGrey to perform a simple action on an element in the view? e.g. assert that your button is visible
I have not tried using GTXi in a test that didn't use EarlGrey, so I don't know what is expected here
@selin194 override class func setUp() is already implemented in my code see here
I am not getting any accessibility errors in the unit test class as above. Any idea ?
super.tearDown() is missing in your test tearDown, GTXiLib expects that the test tearDowns are properly invoked to execute checks. Could you please add it and give it a try.
On Mon, Feb 15, 2021 at 1:55 PM deepthinil [email protected] wrote:
I am not getting any accessibility errors in the unit test class as above. Any idea ?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/GTXiLib/issues/12#issuecomment-779464989, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4R5XA3HXSZMGYXRGM44KTS7GJ4ZANCNFSM4ILL2KUQ .