How to do automatic user interface testing for a system button on Xcode7?

My Storyboard has only one user interface, and it has a navigation bar with one UIBarButtonItem with a system element: Add. He also has other UIButton information. When testing the user interface in English, everything works well without any problems. But if you switch the language to another, it always fails. Here is a snippet of testing code:

app.navigationBars["My Product"].buttons["Add"].tap() app.buttons["More Info"].tap() 

According to the error log, Xcode finds it in another language. Here he is:

Confirmation error: UI testing error - no matches were found for the "Additional Information" button

The request input was

 Button 0x7fa4ca65a1d0: traits: 8724152321, {{8.0, 31.5}, {21.0, 21.0}}, label: 'ζˆ»γ‚‹', Button 0x7fa4ca657700: traits: 8589934593, {{330.5, 26.0}, {40.0, 30.0}}, label: '追加', Button 0x7fa4ca4658d0: traits: 8589934593, {{312.0, 605.0}, {22.0, 22.0}}, label: 'θ©³η΄°ζƒ…ε ±' 

However, I did not create a single localized string for it, since this is just an image created by the iOS system. Does anyone know how to fix this? Many thanks.

+3
ios objective-c uibutton xcode-ui-testing uibarbuttonitem
source share
3 answers

Option 1: set the default language

Create a new UI test circuit and set the default application language. This will lock the application into one localized file so that you can write all your tests for this language.

Set the option from the product β†’ Schema β†’ Schema Management or βŒ˜β‡§,. Then select the Options tab and set the language.

Xcode - set default application language

Advantages : simple one-time change.

Cons It is not possible to use localized screenshots with snapshot (a tool that launches your application through UI Testing and creates screenshots in the App Store along the way).

Option 2: use -accessibilityIdentifier for localized strings

Instead of accessing items through display text or value, use accessibilityIdentifier . This is read using the user interface testing platform, but is never displayed or read to users (even when accessibility is enabled). In older UIAutomation documents, Apple mentions using this for developer functionality, which seems like a good use case.

Then you can continue to set accessibilityLabel and accessibilityValue , as usual, with localized versions.

Pros . It can be used for more general solutions, such as automatic screenshots.

Cons You may need more work to change each label that you need to be "non-localized" for testing.

+3
source share

Have you considered using

 [[app.buttons elementBoundByIndex: 0] tap]; //0-2 

instead of trying to identify the button by its label? This is a less than perfect solution to your problem, but it can do the job.

+1
source share

With quick three you can use BarButtons with the code below

app.navigationBars.buttons.element (boundBy: 0) .tap ()

you can change the index according to your needs

0
source share

All Articles