# Design Patterns in XCUITest

[**Design Patterns in XCUITest**](https://docs.google.com/presentation/d/1Bkt3f23pXboI3UJXdEQxLtJU1YZU74QBleKXQueuEYo/mobilepresent?slide=id.p)

* Page Object&#x20;

![](/files/-M4Y03bS_VpL4PFxf7wP)

* Fluent Interface

![](/files/-M4Y03bEAjVzXLYfmN_w)

* Wait until page/element load &#x20;

![](/files/-M4Y03bhFD6ngdMDWxZQ)

![](/files/-M4Y03biHjf6OY0dkg9c)

* Using check() instead of grab & hope&#x20;

![](/files/-M4Y03bdCPDUav5KniY4)

* Use Launch Argument to Set Up &#x20;

![](/files/-M4Y03bPPKCHLV-ZeMDI)

![](/files/-M4Y03bQdIOcoiMMd913)

* [**Launch Arguments**](https://www.matrixprojects.net/p/ui-testing-with-user-defaults/)

### Launch Arguments

```swift
MyAppUITest.swift
...
override func setUp() {
  super.setUp()

  let app = XCUIApplication()
  app.launchArguments.append("ui-testing")
  app.launch()
}
...

MyAppDelegate.swift
...
func setupModel() -> Model {
  let uiTesting = NSProcessInfo.processInfo().arguments.contains("ui-testing")

  let model = uiTesting ? StubModel() : NetworkModel()

  return model
}
...
```

### NSUserDefaults

```swift
MyAppUITest.swift
...
override func setUp() {
  super.setUp()

  let app = XCUIApplication()
  app.launchArguments.appendContentsOf(["-ui-testing","YES"])
  app.launch()
}
...

MyAppDelegate.swift
...
func setupModel() -> Model {
  let defaults = NSUserDefaults.standardUserDefaults()
  let uiTesting = defaults.boolForKey("ui-testing")

  let model = uiTesting ? StubModel() : NetworkModel()

  return model
}
...
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jacky-chen.gitbook.io/jackychen/test/design-patterns-in-xcuitest.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
