skip to Main Content

How can I clear my Safari history and data for the iPhone simulator in an XCUITest before running the test?

I am trying to test the login features of an app and would like the login credentials not to be saved i.e. google sign in. For this I need to clear the safari history and data in the iPhone simulator settings. Is there a way of doing this in code in the setup or tear down methods?

2

Answers


  1. Simple solution: use Private mode in Safari

    Login or Signup to reply.
  2. You could do that by having a setup function that wipes the Safari data through Settings. Something like this:

    func clearSafariData() {
      let settingsApp = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
      settingsApp.launch()
      settingsApp.cells["Safari"].tap()
      settingsApp.cells["Clear History and Website Data"]
      settingsApp.buttons["Clear History and Data"].tap()
      settingsApp.terminate()
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search