1

As of Xcode 9 there is a new launch argument -StartFromCleanState that I assume launches the app after a clean install. However it doesn't seem to work and googling -StartFromCleanState doesn't yield any results so no documentation to go off of.

source

My goal is to launch my app using a deeplink. The flow of my test is like so:

  1. The UITest begins by launching the app
  2. UITest opens safari
  3. UITest enters the webpage that has the deeplink link
  4. UITest clicks the link and the App opens up

Step for opens the app by bringing it from background state to foreground state. which means application:didFinishLaunchingWithOptions: only gets called once on step 1.

func test_deeplink() {
    programmaticallyTapDeepLink()
    XCUIApplication().launchArguments = ["-StartFromCleanState", "YES"]
}

Ideally I would like to test the deeplink when the app is fresh/clean installed.

I have tried setting the launch arguments before/after I Programmatically tap the deeplink but it doesn't seem to work the way I would like it to.

Are there any solutions available for this?

DerrickHo328
  • 4,664
  • 7
  • 29
  • 50

1 Answers1

1

In the document you specify as the source, the writer provides sample code:

XCTContext.runActivity(named: "Given I have launched app in clean state") { _ in {
    XCUIApplication().launch()
    XCUIApplication().launchArguments = ["-StartFromCleanState", "YES"]
}}

-StartFromCleanState is not a "new launch argument". It's a key and a value being provided to the XCUIApplication().launchArguments method, and it's up to the developer of the application under test (the XCUIApplication) to process the passed launch arguments (["-StartFromCleanState", "YES"]).

This stack overflow answer has some examples:

You might also want to consider reading up on userDefaults; you might want to trigger a reset on them based on the passed launchArguments in one of these two lifecyle methods:

Launch time:

application(_:willFinishLaunchingWithOptions:)
application(_:didFinishLaunchingWithOptions:)

See this apple doc for more info on the Application life cycle states and delegate methods available to you during each state:

ablarg
  • 2,400
  • 1
  • 24
  • 32