Is is possible to test the result of an user action with automated test in ios? For example how can i check that the app created a file, if the user clicked on save button. I have tried Appium and Apple-made XCUITesting but i just cant figure it out.
Asked
Active
Viewed 128 times
1 Answers
0
With Apple's XCUITesting the test app lives in a separate process and has no direct access to your app's sandbox, so, unless your app's UI gives some sort of visual feedback that the file was created, there's no way to check that using the official tools.
You could use SBTUITestTunnel (disclaimer, I'm the author of the library) that extends UI Tests capabilities allowing to write such a test. Assuming, for ex., that your app saves a test_file.txt in the apps' Document folder you could write the following test:
func testThatFileExistsAfterTap() {
// launch app
app = SBTUITunneledApplication()
app.launchTunnelWithOptions([SBTUITunneledApplicationLaunchOptionResetFilesystem]) {
// do additional setup before the app launches, if needed
}
app.buttons["action"].tap() // button that triggers file save
// add some expectation on the UI to wait for the write to complete (UIActivity indicator, etc)
let fileData = app.downloadItemFromPath("test_file.txt", relativeTo: .DocumentDirectory)
// XCTAssert() that fileData contains the expected data
}
Note how you can pass the SBTUITunneledApplicationLaunchOptionResetFilesystem
which resets the app's file system on startup. This options allows you to write a test that is independent of previous sessions.

Tomas Camin
- 9,996
- 2
- 43
- 62
-
Could you help me with this please, I have added the files to the project manual, and chosen the target in each file, but the building always fails with error: linker command failed, symbol not found for architecture arm64, so I can't launch the tunnel in the app. – Peter F. Jul 27 '16 at 08:03
-
Did you try using CocoaPods? It's by far the easiest way to add the library. – Tomas Camin Jul 27 '16 at 08:07
-
Sorry for being such an idiot, but I just can't make it work. I tried with CocoaPods, installed the pod file (I used the one in the example project, but rewrote the targets), then used the workspace generated by CocoaPods, and I have stuck here. – Peter F. Jul 27 '16 at 12:22
-
Well, I tried the library with an empty project, and it worked well, but the project I'm working on is generated by Unity. Do you have any idea how could I make it work? – Peter F. Jul 28 '16 at 14:09
-
I've never used Unity, however I would expect it to just work, When adding files manually did you made sure to add the files in the `Server` folder to the app target, the files in the `Client` to the UI Test target, and the `Common` to both? – Tomas Camin Jul 28 '16 at 14:12
-
I think it was, but the problem was the same with CocoaPods and manually, that even though the app target saw the files in the `Server` folder, couldn't see the classes in it, since the `DEBUG` directive. – Peter F. Jul 28 '16 at 15:04
-
Well, I can't make it run yet, but I am wondering if this framework can work with KIF framework together. – Peter F. Aug 02 '16 at 14:44