XCTEST - How to extract text from the screenshot and compare it with a expected string

274 views Asked by At

Currently I am testing one iOS app for localization. Is there any way we can take a screenshot of the app screen and we extract a text from that screenshot to compare it with the text coming from the locale string file?

1

There are 1 answers

0
Roman Zakharov On

To assert texts use accessibility properties of XCUIElement (value and title) https://developer.apple.com/documentation/xctest/xcuielementattributes

Watch the example here https://github.com/rzakhar/xctest-assignment

To access translations in your tests refer to a Comparing localized UI texts tip from here https://www.vvse.com/blog/blog/2018/01/24/tips-for-using-xcodes-ui-testing-solution-xcuitest/

Make sure to write some extensions to reduce boilerplate code