-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a series of UI tests for State Restoration
Task/Issue URL: https://app.asana.com/0/1199230911884351/1205717021705374/f Tech Design URL: CC: **Description**: Adds a series of UI tests for State Restoration **Steps to test this PR**: 1. Open the scheme **UI Tests** 2. Navigate to the test pane 3. Run `StateRestorationTests` **Note**: If this builds a `review` build that is treated as a first run on your system during every test (for instance, asking you where to put the application), please **build and run** the scheme once instead of running its tests, and go through the new app install first run steps once before running the tests, and answer any first install questions. **UI Tests general guidelines for everyone**: * It (unfortunately!) isn't possible to multitask while running UI tests on your local machine, because your mousing/interface usage will change or intercept screen interactions that the tests depend on. * Much as we all want UI testing to work on multi-monitor setups, we have noticed specific focus issues related to waiting for focus across two monitors simultaneously, so we have decided to test the tests on a single monitor. * We are currently testing with English as the app destination language. * If you experience test failures in your local environment, please always send the `xcresult` bundle so it is possible to view what happened differently on your machine, even if it seems like the same failure as a previous failure (it may be subtly different). Please give its screenshots or screen recording a look first before sending, just to rule out one-off failure causes like an unrelated app unexpectedly throwing up an update helper (or something similar) in front of where `XCUITest` is waiting for a UI element to exist. * Since the `xcresult` bundle will include a screen recording or screenshots, for your privacy, please consider things like your chats, calls, and open documents that you don't want to send to a contractor when you are running the tests. Thank you very much for your help!
- Loading branch information
Showing
3 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// | ||
// StateRestorationTests.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import XCTest | ||
|
||
class StateRestorationTests: XCTestCase { | ||
private var app: XCUIApplication! | ||
private var firstPageTitle: String! | ||
private var secondPageTitle: String! | ||
private var firstURLForBookmarksBar: URL! | ||
private var secondURLForBookmarksBar: URL! | ||
private let titleStringLength = 12 | ||
private var addressBarTextField: XCUIElement! | ||
private var settingsGeneralButton: XCUIElement! | ||
private var openANewWindowPreference: XCUIElement! | ||
private var reopenAllWindowsFromLastSessionPreference: XCUIElement! | ||
|
||
override func setUpWithError() throws { | ||
continueAfterFailure = false | ||
app = XCUIApplication() | ||
app.launchEnvironment["UITEST_MODE"] = "1" | ||
firstPageTitle = UITests.randomPageTitle(length: titleStringLength) | ||
secondPageTitle = UITests.randomPageTitle(length: titleStringLength) | ||
firstURLForBookmarksBar = UITests.simpleServedPage(titled: firstPageTitle) | ||
secondURLForBookmarksBar = UITests.simpleServedPage(titled: secondPageTitle) | ||
addressBarTextField = app.windows.textFields["AddressBarViewController.addressBarTextField"] | ||
settingsGeneralButton = app.buttons["PreferencesSidebar.generalButton"] | ||
openANewWindowPreference = app.radioButtons["PreferencesGeneralView.stateRestorePicker.openANewWindow"] | ||
reopenAllWindowsFromLastSessionPreference = app.radioButtons["PreferencesGeneralView.stateRestorePicker.reopenAllWindowsFromLastSession"] | ||
|
||
app.launch() | ||
app.typeKey("w", modifierFlags: [.command, .option, .shift]) // Let's enforce a single window | ||
app.typeKey("n", modifierFlags: .command) | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
app.terminate() | ||
} | ||
|
||
func test_tabStateAtRelaunch_shouldContainTwoSitesVisitedInPreviousSession_whenReopenAllWindowsFromLastSessionIsSet() { | ||
app.typeKey(",", modifierFlags: [.command]) // Open settings | ||
settingsGeneralButton.click(forDuration: 0.5, thenDragTo: settingsGeneralButton) | ||
reopenAllWindowsFromLastSessionPreference.clickAfterExistenceTestSucceeds() | ||
app.typeKey("w", modifierFlags: [.command, .option, .shift]) // Close windows | ||
app.typeKey("n", modifierFlags: .command) | ||
XCTAssertTrue( | ||
addressBarTextField.waitForExistence(timeout: UITests.Timeouts.elementExistence), | ||
"The address bar text field didn't become available in a reasonable timeframe." | ||
) | ||
addressBarTextField.typeURL(firstURLForBookmarksBar) | ||
XCTAssertTrue( | ||
app.windows.webViews[firstPageTitle].waitForExistence(timeout: UITests.Timeouts.elementExistence), | ||
"Site didn't load with the expected title in a reasonable timeframe." | ||
) | ||
app.typeKey("t", modifierFlags: [.command]) | ||
app.typeURL(secondURLForBookmarksBar) | ||
XCTAssertTrue( | ||
app.windows.webViews[secondPageTitle].waitForExistence(timeout: UITests.Timeouts.elementExistence), | ||
"Site didn't load with the expected title in a reasonable timeframe." | ||
) | ||
|
||
app.terminate() | ||
app.launch() | ||
|
||
XCTAssertTrue( | ||
app.windows.webViews[secondPageTitle].waitForExistence(timeout: UITests.Timeouts.elementExistence), | ||
"Second visited site wasn't found in a webview with the expected title in a reasonable timeframe." | ||
) | ||
app.typeKey("w", modifierFlags: [.command]) | ||
XCTAssertTrue( | ||
app.windows.webViews[firstPageTitle].waitForExistence(timeout: UITests.Timeouts.elementExistence), | ||
"First visited site wasn't found in a webview with the expected title in a reasonable timeframe." | ||
) | ||
} | ||
|
||
func test_tabStateAtRelaunch_shouldContainNoSitesVisitedInPreviousSession_whenReopenAllWindowsFromLastSessionIsUnset() { | ||
app.typeKey(",", modifierFlags: [.command]) // Open settings | ||
settingsGeneralButton.click(forDuration: 0.5, thenDragTo: settingsGeneralButton) | ||
openANewWindowPreference.clickAfterExistenceTestSucceeds() | ||
app.typeKey("w", modifierFlags: [.command, .option, .shift]) // Close windows | ||
app.typeKey("n", modifierFlags: .command) | ||
XCTAssertTrue( | ||
addressBarTextField.waitForExistence(timeout: UITests.Timeouts.elementExistence), | ||
"The address bar text field didn't become available in a reasonable timeframe." | ||
) | ||
addressBarTextField.typeURL(firstURLForBookmarksBar) | ||
XCTAssertTrue( | ||
app.windows.webViews[firstPageTitle].waitForExistence(timeout: UITests.Timeouts.elementExistence), | ||
"Site didn't load with the expected title in a reasonable timeframe." | ||
) | ||
app.typeKey("t", modifierFlags: [.command]) | ||
app.typeURL(secondURLForBookmarksBar) | ||
XCTAssertTrue( | ||
app.windows.webViews[secondPageTitle].waitForExistence(timeout: UITests.Timeouts.elementExistence), | ||
"Site didn't load with the expected title in a reasonable timeframe." | ||
) | ||
|
||
app.terminate() | ||
app.launch() | ||
|
||
XCTAssertTrue( | ||
app.windows.webViews[secondPageTitle].waitForNonExistence(timeout: UITests.Timeouts.elementExistence), | ||
"Second visited site from previous session should not be in any webview." | ||
) | ||
XCTAssertTrue( | ||
app.windows.webViews[firstPageTitle].waitForNonExistence(timeout: UITests.Timeouts.elementExistence), | ||
"First visited site from previous session should not be in any webview." | ||
) | ||
app.typeKey("w", modifierFlags: [.command]) | ||
XCTAssertTrue( | ||
app.windows.webViews[firstPageTitle].waitForNonExistence(timeout: UITests.Timeouts.elementExistence), | ||
"First visited site from previous session should not be in any webview." | ||
) | ||
XCTAssertTrue( | ||
app.windows.webViews[secondPageTitle].waitForNonExistence(timeout: UITests.Timeouts.elementExistence), | ||
"Second visited site from previous session should not be in any webview." | ||
) | ||
} | ||
} |