iosxcodeunit-testingxcode-ui-testingios-ui-automation

How to get to Authorized part in Xcode UI Tests


I have the app with login screen and the screen that appear after login (authorized part).

What is the best approach to test these screens from Authorized part?

I have several ideas:

1) Somehow I need to remove all the data from keychain before each test and then I go through the entire flow each time to get to the first screen after login. When I need to send a request to backend to login, I wait for the main screen using

let nextGame = self.app.staticTexts["Main Screen Text"]
let exists = NSPredicate(format: "exists == true")
expectation(for: exists, evaluatedWithObject: nextGame, handler: nil)
waitForExpectations(timeout: 5, handler: nil)

2) I pass some arguments here

app = XCUIApplication(bundle:….)
    app.launchArguments = [“notEmptyArguments”:”value”]
    app.launch()

So I can pass a fake token and out backend will accept this token, so that my app will know that it has to route me to the Main Screen and all the requests will be successful because my Network Service has this fake token

But I fill that it's a not vary safe way.

Do you have any ideas what is the best approach and may be you can give advice of a better approach?


Solution

  • The second idea you mentioned is a good way to skip login screen in tests. Furthermore, implementing token passing will be helpful to developer team as well. Those launch arguments can be stored at running schemes settings.

    Also, if you implement deep linking in the same manner it will bring even more speed enhancements for both QA and developer team.

    Surely, these "shortcuts" shall be only accessible while running a debug configuration (using #if DEBUG...)