Here is my use case...
My application has a number of menu items that have their state toggled between on and off based on a boolean that is also tied to a user default. That is, when the user clicks the menu item it not only toggles the state, it also saves that in the user defaults.
This is all working well but I'm trying to add tests to my XCUIApplication tests to check that the state is indeed saved from one application run to another. However I am unable to determine how to actually test the state of the menu item.
I find the menu item and confirm that it exists, has the correct title, and is enabled, as seen here:
let item = app.menuItems["viewHighlightChanges"]
XCTAssertTrue(item.exists)
XCTAssertEqual(item.title, "Highlight Changes")
XCTAssertTrue(item.isEnabled)
I can then toggle the item by clicking it:
item.click()
And I can confirm visually that this is all working.
But what I cannot figure out is how to determine if the menu item is check (state is on) or not checked (state is off). I had thought that it may be encoded in item.value
but that is returning nil
both before and after the click. I also thought it may be in item.isSelected
but selected is not the same as state and in this case is always false
both before and after the click.
My goal is to record the state after clicking, then exit and restart the app, and test the state again to see that it properly retained itself. I know that it is working because I can verify the state visually as the test runs, but the whole purpose of an automated test is that the computer should tell me if it worked.
Any ideas?