Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Fixes #1107: screenshot tests fail in certain locales (#1110)
Browse files Browse the repository at this point in the history
* Fixes #1107: screenshot tests fail in certain locales

* Remove whitespace
  • Loading branch information
oliviabrown9 authored Jul 19, 2018
1 parent 8ea1645 commit 2e69c0e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
38 changes: 31 additions & 7 deletions ScreenshotTests/SnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class SnapshotTests: XCTestCase {
super.setUp()
continueAfterFailure = false
let app = XCUIApplication()
app.launchArguments = ["testMode"]
setupSnapshot(app)
app.launch()
}
Expand All @@ -25,6 +26,7 @@ class SnapshotTests: XCTestCase {
snapshot("03Home")

snapshot("04LocationBarEmptyState")
app.textFields["URLBar.urlText"].tap()
app.textFields["URLBar.urlText"].typeText("bugzilla.mozilla.org")
snapshot("05SearchFor")

Expand All @@ -45,6 +47,7 @@ class SnapshotTests: XCTestCase {

func test02Settings() {
let app = XCUIApplication()
dismissFirstRunUI()
app.buttons["HomeView.settingsButton"].tap()
snapshot("09Settings")
app.swipeUp()
Expand All @@ -60,6 +63,7 @@ class SnapshotTests: XCTestCase {

func test03About() {
let app = XCUIApplication()
dismissFirstRunUI()
app.buttons["HomeView.settingsButton"].tap()
app.cells["settingsViewController.about"].tap()
snapshot("13About")
Expand All @@ -69,6 +73,8 @@ class SnapshotTests: XCTestCase {

func test04ShareMenu() {
let app = XCUIApplication()
dismissFirstRunUI()
app.textFields["URLBar.urlText"].tap()
app.textFields["URLBar.urlText"].typeText("bugzilla.mozilla.org\n")
waitForValueContains(element: app.textFields["URLBar.urlText"], value: "https://bugzilla.mozilla.org/")
app.buttons["BrowserToolset.sendButton"].tap()
Expand All @@ -77,37 +83,44 @@ class SnapshotTests: XCTestCase {

func test05SafariIntegration() {
let app = XCUIApplication()
dismissFirstRunUI()
app.buttons["HomeView.settingsButton"].tap()
app.tables.switches["BlockerToggle.Safari"].tap()
snapshot("16SafariIntegrationInstructions")
}

func test06OpenMaps() {
let app = XCUIApplication()
dismissFirstRunUI()
app.textFields["URLBar.urlText"].tap()
app.textFields["URLBar.urlText"].typeText("maps.apple.com\n")
waitForValueContains(element: app.textFields["URLBar.urlText"], value: "http://maps.apple.com")
snapshot("17OpenMaps")
}

func test07OpenAppStore() {
let app = XCUIApplication()
dismissFirstRunUI()
app.textFields["URLBar.urlText"].tap()
app.textFields["URLBar.urlText"].typeText("itunes.apple.com\n")
waitForValueContains(element: app.textFields["URLBar.urlText"], value: "http://itunes.apple.com")
snapshot("18OpenAppStore")
}

func test08PasteAndGo() {
let app = XCUIApplication()
dismissFirstRunUI()
// Inject a string into clipboard
let clipboardString = "Hello world"
UIPasteboard.general.string = clipboardString

// Enter 'mozilla' on the search field
// Enter 'bugzilla.mozilla.org' on the search field as its URL does not change for locale.
let searchOrEnterAddressTextField = app.textFields["URLBar.urlText"]
searchOrEnterAddressTextField.typeText("mozilla.org\n")
searchOrEnterAddressTextField.tap()
searchOrEnterAddressTextField.typeText("bugzilla.mozilla.org\n")

// Check the correct site is reached
waitForValueContains(element: searchOrEnterAddressTextField, value: "https://www.mozilla.org/")
waitForValueContains(element: searchOrEnterAddressTextField, value: "https://bugzilla.mozilla.org/")

// Tap URL field, check for paste & go menu
searchOrEnterAddressTextField.tap()
Expand All @@ -122,23 +135,26 @@ class SnapshotTests: XCTestCase {

func test09TrackingProtection() {
let app = XCUIApplication()
dismissFirstRunUI()

// Inject a string into clipboard
let clipboardString = "Hello world"
UIPasteboard.general.string = clipboardString

// Enter 'mozilla' on the search field
// Enter 'bugzilla.mozilla.org' on the search field as its URL does not change for locale.
let searchOrEnterAddressTextField = app.textFields["URLBar.urlText"]
searchOrEnterAddressTextField.typeText("mozilla.org\n")

searchOrEnterAddressTextField.tap()
searchOrEnterAddressTextField.typeText("bugzilla.mozilla.org\n")

// Check the correct site is reached
waitForValueContains(element: searchOrEnterAddressTextField, value: "https://www.mozilla.org/")
waitForValueContains(element: searchOrEnterAddressTextField, value: "https://bugzilla.mozilla.org/")
app.otherElements["URLBar.trackingProtectionIcon"].tap()
snapshot("20TrackingProtection")
}

func test10CustomSearchEngines() {
let app = XCUIApplication()
dismissFirstRunUI()

app.buttons["HomeView.settingsButton"].tap()
app.cells["SettingsViewController.searchCell"].tap()
Expand All @@ -148,6 +164,7 @@ class SnapshotTests: XCTestCase {

func test11AutocompleteURLs() {
let app = XCUIApplication()
dismissFirstRunUI()

app.buttons["HomeView.settingsButton"].tap()
app.cells["SettingsViewController.autocompleteCell"].tap()
Expand Down Expand Up @@ -180,4 +197,11 @@ class SnapshotTests: XCTestCase {
}
}
}

func dismissFirstRunUI() {
let firstRunUI = XCUIApplication().buttons["IntroViewController.button"]
if (firstRunUI.exists) {
firstRunUI.tap()
}
}
}
2 changes: 1 addition & 1 deletion Shared/AppInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ class AppInfo {
}

open class func testRequestsReset() -> Bool {
return ProcessInfo.processInfo.arguments.contains("RESET_PREFS")
return ProcessInfo.processInfo.arguments.contains("testMode")
}
}
2 changes: 1 addition & 1 deletion XCUITest/BaseTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BaseTestCase: XCTestCase {
override func setUp() {
super.setUp()
continueAfterFailure = false
app.launchArguments = ["testMode", "RESET_PREFS"]
app.launchArguments = ["testMode"]
app.launch()
}

Expand Down

0 comments on commit 2e69c0e

Please sign in to comment.