How to test the language from right to left in the unit tests of iOS XCTest?

Is there a way to switch the XCTest unit test from right to left to test the Arabic version of the application, where sentences are written from right to left of the screen? My application code logic behaves differently based on language direction. I would like to test this functionality in unit test. What I need to do is switch the application to right-to-left mode from the XCTest unit test case.

You can start the application in the right-to-left mode by changing the Scheme Language settings of the application to the Pseudo-Language from right to left . Is there a way to do this in unit test?

My imperfect decision

I ended up changing the semanticContentAttribute in view mode to .ForceRightToLeft . He does what I need. However, this is not a very clean approach. Firstly, it works only in iOS 9. Secondly, it seems that I am viewing low-level applications from unit test. Instead, I would rather switch the entire application language left or right, if possible.

 class MyTests: XCTestCase { func testRightToLeft() { if #available(iOS 9.0, *) { let view = UIView() view.semanticContentAttribute = .ForceRightToLeft // Test code involving the view } } } 
+5
source share
4 answers

There is no easy way to do this right now with testing / testing the user interface, other than passing environment flags or setting semanticContentAttribute , as you are doing now. Filing errors at Apple is highly recommended.

+3
source

What you are looking for, Automated user interface

In this example, the JavaScript code changes the orientation of the device, for example:

 var target = UIATarget.localTarget(); var app = target.frontMostApp(); //set orientation to landscape left target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPELEFT); UIALogger.logMessage("Current orientation now " + app.interfaceOrientation()); //reset orientation to portrait target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT); UIALogger.logMessage("Current orientation now " + app.interfaceOrientation()); 

For testing purposes, if your layout has changed to RTL or LTR, you can try to access certain elements of the user interface and check their contents for the expected content. So, here is another example to check the contents of TableViewCell from white papers:

The essence of testing is to verify that each test is completed and that it passed or failed. In this code example, test testName is run to determine if a recipe element of a valid element whose name begins with "Tarte" exists in the recipe table view. First, a local variable is used to determine the criteria of a cell:

 var cell = UIATarget.localTarget().frontMostApp().mainWindow() \ .tableViews()[0].cells().firstWithPredicate("name beginswith 'Tarte'"); 

Next, the script uses the isValid method to check for the presence of a valid element matching these criteria in the recipe table view.

 if (cell.isValid()) { UIALogger.logPass(testName); } else { UIALogger.logFail(testName); } 

If a valid cell is found, the code logs an error message for the testName test; if not, it logs an error message.

Note that this test defines firstWithPredicate and “name begins with“ Tart. ”These criteria provide a link to the cell for“ Tarte aux Fraises, ”which works for the default data already in the Recipes sample application. If, however, the user adds a recipe for "Tarte aux Framboises", this example may or may not produce the desired results.

If you want to test a specific circuit:

Running the script automation tool in Xcode After creating a custom automation template, you can run your script test from Xcode by following these steps: Open the project in Xcode. In the "Schema" pop-up menu (in the toolbar of the workspace window) select "Edit Schema" for the scheme with which you would like to use a script. Select Profile in the left column of the schematic editing dialog box. Select your application from the Executable Files pop-up menu. Select a custom automation tool template from the Tool pop-up menu. Click "OK" to confirm your changes and cancel the dialog of the circuit editor. Choose Product> Profile. Tools run and execute your test script.

0
source

You can determine the recording direction through

 let writingDirection = UIApplication.sharedApplication().userInterfaceLayoutDirection switch writingDirection { case .LeftToRight: // case .RightToLeft: // default: break // what now? You are obviously using iOS 11 topToBottom direction… } 

To install different languages ​​and locales at startup, this might be the right solution .

0
source

You can also change the device language and region in the diagram. This means that you will need separate circuits for the various LTR / RTL tests that you want to run:

Xcode language and region settings

Xcode even provides pseudo-languages ​​for testing long strings and RTL.

0
source

All Articles