Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions WordPress/UITests/JetpackUITests-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSPrincipalClass</key>
<string>${PRODUCT_NAME}.TestObserver</string>
</dict>
</plist>
21 changes: 0 additions & 21 deletions WordPress/UITests/Utils/XCTest+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ extension XCTestCase {
removeBeforeLaunching: Bool = false,
crashOnCoreDataConcurrencyIssues: Bool = true
) {
// To avoid handling 'Save Password' prompts after login.
disableAutoFillPasswords()

// To ensure that the test starts with a new simulator launch each time
app.terminate()
super.setUp()
Expand All @@ -35,24 +32,6 @@ extension XCTestCase {
systemAlertHandler(alertTitle: "“WordPress” Would Like to Access Your Photos", alertButton: alertButtonTitle)
}

public func disableAutoFillPasswords() {
let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
settings.activate()
settings.staticTexts["Passwords"].tap()

let enterPasscodeScreen = XCUIApplication(bundleIdentifier: "com.apple.springboard")
enterPasscodeScreen.secureTextFields["Passcode field"].typeText(" ")
enterPasscodeScreen.buttons["done"].tap()

settings.staticTexts["Password Options"].tap()

let autoFillPasswordsSwitch = settings.switches["AutoFill Passwords"]
if autoFillPasswordsSwitch.value as? String == "1" {
autoFillPasswordsSwitch.tap()
}
settings.terminate()
}

public func takeScreenshotOfFailedTest() {
guard let failuresCount = testRun?.failureCount, failuresCount > 0 else { return }

Expand Down
2 changes: 2 additions & 0 deletions WordPress/UITests/WordPressUITests-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSPrincipalClass</key>
<string>${PRODUCT_NAME}.TestObserver</string>
</dict>
</plist>
55 changes: 55 additions & 0 deletions WordPress/UITestsFoundation/TestObserver.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import XCTest

class TestObserver: NSObject, XCTestObservation {
override init() {
super.init()
XCTestObservationCenter.shared.addTestObserver(self)
}

func testBundleWillStart(_ testBundle: Bundle) {
// Code added here will run only once before all the tests
executeWithRetries(disableAutoFillPasswords)
}

func testBundleDidFinish(_ testBundle: Bundle) {
XCTestObservationCenter.shared.removeTestObserver(self)
}

func executeWithRetries(_ operation: () -> Bool) {
var retryCount = 3

while !operation() && retryCount > 0 {
retryCount -= 1
}
}
Comment on lines +18 to +24
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Retrying to be on the safer side as all the tests would fail in case this is not disabled. I have seen it happening a couple times in a week.
I tried to make it reusable as we might need to change other setting in the future.


func disableAutoFillPasswords() -> Bool {
let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
// Terminating Settings in case of a retry.
settings.terminate()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this .terminate() here? If this will be run once at the start of the test run, is this necessary? I'm thinking there's nothing to terminate at that point but I could be missing something.

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 is needed in a retry case if something goes wrong in the first execution and also to make our lives easier when running multiple times locally. =]

I added a comment in 798de02.

settings.activate()

let passwordsMenuItem = settings.staticTexts["Passwords"]
passwordsMenuItem.waitForIsHittable()
passwordsMenuItem.tap()

let enterPasscodeScreen = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let passwordField = enterPasscodeScreen.secureTextFields["Passcode field"]
passwordField.waitForIsHittable()
passwordField.typeText(" \r")

let passwordOptions = settings.staticTexts["Password Options"]
passwordOptions.waitForIsHittable()
passwordOptions.tap()

let autoFillPasswordsSwitch = settings.switches["AutoFill Passwords"]
autoFillPasswordsSwitch.waitForIsHittable()

if autoFillPasswordsSwitch.value as? String == "1" {
autoFillPasswordsSwitch.tap()
}

settings.terminate()
return true
}
}
6 changes: 6 additions & 0 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3461,6 +3461,8 @@
EA14533829AD874C001F3143 /* UITestsFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3FA640572670CCD40064401E /* UITestsFoundation.framework */; };
EA14533929AD874C001F3143 /* BuildkiteTestCollector in Frameworks */ = {isa = PBXBuildFile; productRef = EA14532529AD874C001F3143 /* BuildkiteTestCollector */; };
EA78189427596B2F00554DFA /* ContactUsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA78189327596B2F00554DFA /* ContactUsScreen.swift */; };
EA85B7AF2A688AB00096E097 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA85B7A92A6860370096E097 /* TestObserver.swift */; };
EA85B7B02A688B1C0096E097 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA85B7A92A6860370096E097 /* TestObserver.swift */; };
EAB10E4027487F5D000DA4C1 /* ReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB10E3F27487F5D000DA4C1 /* ReaderTests.swift */; };
EAD08D0E29D45E23001A72F9 /* CommentsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD08D0D29D45E23001A72F9 /* CommentsScreen.swift */; };
EAD2BF4227594DAB00A847BB /* StatsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD2BF4127594DAB00A847BB /* StatsTests.swift */; };
Expand Down Expand Up @@ -8901,6 +8903,7 @@
EA14534229AD874C001F3143 /* JetpackUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JetpackUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
EA14534629AEF479001F3143 /* JetpackUITests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = JetpackUITests.xctestplan; sourceTree = "<group>"; };
EA78189327596B2F00554DFA /* ContactUsScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactUsScreen.swift; sourceTree = "<group>"; };
EA85B7A92A6860370096E097 /* TestObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestObserver.swift; sourceTree = "<group>"; };
EAB10E3F27487F5D000DA4C1 /* ReaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReaderTests.swift; sourceTree = "<group>"; };
EAD08D0D29D45E23001A72F9 /* CommentsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentsScreen.swift; sourceTree = "<group>"; };
EAD2BF4127594DAB00A847BB /* StatsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatsTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -11635,6 +11638,7 @@
3F762E9226784A950088CD45 /* Logger.swift */,
3FE39A4326F8391D006E2B3A /* Screens */,
3FA640592670CCD40064401E /* UITestsFoundation.h */,
EA85B7A92A6860370096E097 /* TestObserver.swift */,
3F762E9426784B540088CD45 /* WireMock.swift */,
3F107B1829B6F7E0009B3658 /* XCTestCase+Utils.swift */,
3F6A8CDF2A246357009DBC2B /* XCUIApplication+SavePassword.swift */,
Expand Down Expand Up @@ -23874,6 +23878,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EA85B7AF2A688AB00096E097 /* TestObserver.swift in Sources */,
EA14532929AD874C001F3143 /* MainNavigationTests.swift in Sources */,
80379C6F2A5C0D8F00D924AC /* PostTests.swift in Sources */,
EA14532A29AD874C001F3143 /* ReaderTests.swift in Sources */,
Expand Down Expand Up @@ -25839,6 +25844,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EA85B7B02A688B1C0096E097 /* TestObserver.swift in Sources */,
FFA0B7D71CAC1F9F00533B9D /* MainNavigationTests.swift in Sources */,
80379C6E2A5C0D8F00D924AC /* PostTests.swift in Sources */,
EAB10E4027487F5D000DA4C1 /* ReaderTests.swift in Sources */,
Expand Down