How to check if the NavigationBar navigation button is turned on in testing the user interface in iOS?

In my iOS application, I added user interface tests where I need to check if the NavigationBar navigation button is turned on at different times.

I am currently using:

XCUIElement* saveButton = self.app.navigationBars[@"TSSIDAddCardView"].buttons[@"Save"]; XCTAssertEqual(saveButton.hittable, YES); 

However, this always returns YES. The .exists test also returns YES.

Does anyone know how to do the right test?

+5
source share
3 answers

So, using @InsertWittyName, I found a solution:

 UIBarButtonItem *saveButton = self.app.navigationBars[@"TSSIDAddCardView"].buttons[@"Save"]; XCTAssertFalse(saveButton.enabled); 
+3
source

You can get the actual user interface component using the value property.

With this, you can check if it is turned on or not.

Sort of:

 UIBarButtonItem *saveButton = self.app.navigationBars[@"TSSIDAddCardView"].buttons[@"Save"].value; XCTAssertTrue(saveButton.enabled); 
+4
source

XCUIElement corresponds to XCUIElementAttributes , which provides @property(readonly, getter=isEnabled) BOOL enabled; .

So you can just do this on your XCUIElement* saveButton :

<sub> Objective-Csub>

 XCTAssertEqual(saveButton.enabled, YES); 

<sub> Swiftsub>

 XCTAssertEqual(saveButton.isEnabled, true) 
0
source

Source: https://habr.com/ru/post/1238552/


All Articles