Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions WordPress/Classes/System/WordPressAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class WordPressAppDelegate: UIResponder, UIApplicationDelegate {
setupBackgroundRefresh(application)
setupComponentsAppearance()
disableAnimationsForUITests(application)
logoutAtLaunchForUITests(application)

// This was necessary to properly load fonts for the Stories editor. I believe external libraries may require this call to access fonts.
let fonts = Bundle.main.urls(forResourcesWithExtension: "ttf", subdirectory: nil)
Expand Down Expand Up @@ -379,6 +380,12 @@ class WordPressAppDelegate: UIResponder, UIApplicationDelegate {
}
}

private func logoutAtLaunchForUITests(_ application: UIApplication) {
if CommandLine.arguments.contains("-logout-at-launch") {
AccountHelper.logOutDefaultWordPressComAccount()
}
}

var runningInBackground: Bool {
return UIApplication.shared.applicationState == .background
}
Expand Down
1 change: 0 additions & 1 deletion WordPress/UITests/Tests/DashboardTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class DashboardTests: XCTestCase {

override func tearDownWithError() throws {
takeScreenshotOfFailedTest()
removeApp()
}

func testFreeToPaidCardNavigation() throws {
Expand Down
1 change: 0 additions & 1 deletion WordPress/UITests/Tests/EditorAztecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class EditorAztecTests: XCTestCase {

override func tearDownWithError() throws {
takeScreenshotOfFailedTest()
removeApp()
}

// TODO: Re-enable Aztec tests but for editing an existing Aztec post.
Expand Down
1 change: 0 additions & 1 deletion WordPress/UITests/Tests/EditorGutenbergTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class EditorGutenbergTests: XCTestCase {

override func tearDownWithError() throws {
takeScreenshotOfFailedTest()
removeApp()
}

let title = "Rich post title"
Expand Down
25 changes: 10 additions & 15 deletions WordPress/UITests/Tests/LoginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,26 @@ class LoginTests: XCTestCase {

override func tearDownWithError() throws {
takeScreenshotOfFailedTest()
removeApp()
}

// Unified email login/out
func testWPcomLoginLogout() throws {
let prologueScreen = try PrologueScreen().selectContinue()
try PrologueScreen().selectContinue()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is not really necessary for this change but i decided to take advantage to standardize this since there was 1 test in this file that had to be updated to work with this new solution

.proceedWith(email: WPUITestCredentials.testWPcomUserEmail)
.proceedWithValidPassword()
.verifyEpilogueDisplays(username: WPUITestCredentials.testWPcomUsername, siteUrl: WPUITestCredentials.testWPcomSitePrimaryAddress)
.continueWithSelectedSite()
.dismissNotificationAlertIfNeeded()
.tabBar.goToMeScreen()
.logoutToPrologue()

XCTAssert(prologueScreen.isLoaded)
.verifyPrologueScreenLoaded()
}

/**
This test opens safari to trigger the mocked magic link redirect
*/
func testEmailMagicLinkLogin() throws {
let welcomeScreen = try WelcomeScreen().selectLogin()
try WelcomeScreen().selectLogin()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the above test

.selectEmailLogin()
.proceedWith(email: WPUITestCredentials.testWPcomUserEmail)
.proceedWithLink()
Expand All @@ -40,26 +38,23 @@ class LoginTests: XCTestCase {
.dismissNotificationAlertIfNeeded()
.tabBar.goToMeScreen()
.logout()

XCTAssert(welcomeScreen.isLoaded)
.verifyWelcomeScreenLoaded()
}

// Unified self hosted login/out
func testSelfHostedLoginLogout() throws {
let prologueScreen = try PrologueScreen()

try prologueScreen
try PrologueScreen()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the above test

.selectSiteAddress()
.proceedWith(siteUrl: WPUITestCredentials.selfHostedSiteAddress)
.proceedWithSelfHosted(username: WPUITestCredentials.selfHostedUsername, password: WPUITestCredentials.selfHostedPassword)
.removeSelfHostedSite()

XCTAssert(prologueScreen.isLoaded)
try PrologueScreen()
.verifyPrologueScreenLoaded()
}

// Unified WordPress.com email login failure due to incorrect password
func testWPcomInvalidPassword() throws {
_ = try PrologueScreen().selectContinue()
try PrologueScreen().selectContinue()
.proceedWith(email: WPUITestCredentials.testWPcomUserEmail)
.proceedWithInvalidPassword()
.verifyLoginError()
Expand All @@ -84,7 +79,7 @@ class LoginTests: XCTestCase {

// Login flow returns MySites modal, which needs to be closed.
.closeModal()

XCTAssert(MySiteScreen.isLoaded())
.verifyMySiteScreenLoaded()
.removeSelfHostedSite()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logOutDefaultWordPressComAccount works for WordPress accounts; needed to add this additional step for self-hosted sites for this work.

}
}
1 change: 0 additions & 1 deletion WordPress/UITests/Tests/MainNavigationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class MainNavigationTests: XCTestCase {

override func tearDownWithError() throws {
takeScreenshotOfFailedTest()
removeApp()
}

// We run into an issue where the People screen would crash short after loading.
Expand Down
1 change: 0 additions & 1 deletion WordPress/UITests/Tests/MenuNavigationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ final class MenuNavigationTests: XCTestCase {

override func tearDownWithError() throws {
takeScreenshotOfFailedTest()
removeApp()
}

// This test is JP only.
Expand Down
1 change: 0 additions & 1 deletion WordPress/UITests/Tests/ReaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ReaderTests: XCTestCase {

override func tearDownWithError() throws {
takeScreenshotOfFailedTest()
removeApp()
}

let expectedPostContent = "Aenean vehicula nunc in sapien rutrum, nec vehicula enim iaculis. Aenean vehicula nunc in sapien rutrum, nec vehicula enim iaculis. Proin dictum non ligula aliquam varius. Nam ornare accumsan ante, sollicitudin bibendum erat bibendum nec. Aenean vehicula nunc in sapien rutrum, nec vehicula enim iaculis."
Expand Down
1 change: 0 additions & 1 deletion WordPress/UITests/Tests/SignupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class SignupTests: XCTestCase {

override func tearDownWithError() throws {
takeScreenshotOfFailedTest()
removeApp()
}

func testEmailSignup() throws {
Expand Down
1 change: 0 additions & 1 deletion WordPress/UITests/Tests/StatsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class StatsTests: XCTestCase {

override func tearDownWithError() throws {
takeScreenshotOfFailedTest()
removeApp()
}

let insightsStats: [String] = [
Expand Down
1 change: 0 additions & 1 deletion WordPress/UITests/Tests/SupportScreenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class SupportScreenTests: XCTestCase {

override func tearDownWithError() throws {
takeScreenshotOfFailedTest()
removeApp()
}

func testSupportForumsCanBeLoadedDuringLogin() throws {
Expand Down
4 changes: 3 additions & 1 deletion WordPress/UITests/Utils/XCTest+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ extension XCTestCase {
removeBeforeLaunching: Bool = false,
crashOnCoreDataConcurrencyIssues: Bool = true
) {
// To ensure that the test starts with a new simulator launch each time
app.terminate()
super.setUp()

// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false

app.launchArguments = ["-wpcom-api-base-url", WireMock.URL().absoluteString, "-no-animations", "-ui-testing"]
app.launchArguments = ["-wpcom-api-base-url", WireMock.URL().absoluteString, "-no-animations", "-ui-testing", "-logout-at-launch"]

if crashOnCoreDataConcurrencyIssues {
app.launchArguments.append(contentsOf: ["-com.apple.CoreData.ConcurrencyDebug", "1"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class PasswordScreen: ScreenObject {
app.dismissSavePasswordPrompt()
}

@discardableResult
public func verifyLoginError() -> PasswordScreen {
let errorLabel = app.cells["Password Error"]
_ = errorLabel.waitForExistence(timeout: 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public class PrologueScreen: ScreenObject {
return try LoginSiteAddressScreen()
}

public func verifyPrologueScreenLoaded() {
XCTAssertTrue(isLoaded)
}

public static func isLoaded(app: XCUIApplication = XCUIApplication()) -> Bool {
(try? PrologueScreen(app: app).isLoaded) ?? false
}
Expand Down
4 changes: 4 additions & 0 deletions WordPress/UITestsFoundation/Screens/Login/WelcomeScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public class WelcomeScreen: ScreenObject {
return try WelcomeScreenLoginComponent()
}

public func verifyWelcomeScreenLoaded() {
XCTAssertTrue(isLoaded)
}

static func isLoaded() -> Bool {
(try? WelcomeScreen().isLoaded) ?? false
}
Expand Down
5 changes: 5 additions & 0 deletions WordPress/UITestsFoundation/Screens/MySiteScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ public class MySiteScreen: ScreenObject {
return try PeopleScreen()
}

public func verifyMySiteScreenLoaded() -> Self {
XCTAssertTrue(isLoaded)
return self
}

public static func isLoaded() -> Bool {
(try? MySiteScreen().isLoaded) ?? false
}
Expand Down