1

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?

Yucel
  • 11
  • 1

2 Answers2

1

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()
}
drunkencheetah
  • 354
  • 1
  • 8
  • I had a bug with the simulator which meant even if I was to clear the history manually, the history would not clear. I'd have to reset the simulator by erasing all settings and content instead. – Yucel Jun 22 '22 at 16:57
0

Simple solution: use Private mode in Safari

Roman Zakharov
  • 2,185
  • 8
  • 19