Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not getting accessibility errors in unit test #12

Open
aloksinha18 opened this issue Aug 13, 2019 · 11 comments
Open

Not getting accessibility errors in unit test #12

aloksinha18 opened this issue Aug 13, 2019 · 11 comments

Comments

@aloksinha18
Copy link

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.)

@aloksinha18 aloksinha18 changed the title Not getting accessibility errors on unit test Not getting accessibility errors in unit test Aug 13, 2019
@selin194
Copy link

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.

@niksawtschuk
Copy link
Contributor

@sishuiOS is this an XCTest or XCUITest? see this comment for more details

@aloksinha18
Copy link
Author

@niksawtschuk this is Unit test(XCTest) .

@aloksinha18
Copy link
Author

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???

@niksawtschuk
Copy link
Contributor

@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.

@aloksinha18
Copy link
Author

aloksinha18 commented Sep 8, 2019

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 🙏

@selin194
Copy link

selin194 commented Sep 9, 2019

Hey @sishuiOS, could you please try : 'override class func setUp()' (which ensures to call setUp() only once!) Thank you!

@niksawtschuk
Copy link
Contributor

@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

@aloksinha18
Copy link
Author

@selin194 override class func setUp() is already implemented in my code see here

@deepthinil
Copy link

I am not getting any accessibility errors in the unit test class as above. Any idea ?

@j-sid
Copy link
Collaborator

j-sid commented Mar 4, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants