Skip to content

Commit

Permalink
Resolve unit test failure in Xcode 12 (#255)
Browse files Browse the repository at this point in the history
* Resolve unit test failure in Xcode 12 related to URLSessionDataTask private method being called too late

* Mark a test as iOS only, since the Mac tests don't have a host app context

* Dismiss the first-launch Quick-Swipe keyboard tutorial if present

* Attempt to work around a race condition in XCUI tests with fresh iPhone simulator instances

* Ensure the XCUI query isn't resolved before the element arrives, to fix flapper test failures on slow CI nodes
  • Loading branch information
mikenachbaur-okta authored Dec 2, 2020
1 parent 80afc37 commit e82bd15
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
17 changes: 15 additions & 2 deletions Tests/Common/URLSessionMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@

import Foundation

class URLSessionDataTaskMock: URLSessionDataTask {
private let completion: () -> Void

init(completion: @escaping () -> Void) {
self.completion = completion
}

override func resume() {
completion()
}
}

class URLSessionMock: URLSession {

var request: URLRequest? = nil
Expand All @@ -24,7 +36,8 @@ class URLSessionMock: URLSession {
httpVersion: nil,
headerFields: nil
)
completionHandler(Data(), response, nil)
return URLSessionDataTask()
return URLSessionDataTaskMock() {
completionHandler(Data(), response, nil)
}
}
}
2 changes: 1 addition & 1 deletion Tests/OktaOidcTests/OktaOidcTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class OktaOidcTests: XCTestCase {
authStateManager.restAPI = apiMock
}

#if !SWIFT_PACKAGE
#if os(iOS) && !SWIFT_PACKAGE
/// **Note:** Tests run in Swift Package Manager do not have access to a common application host, so the Okta.plist file is not accessible.
func testCreationWithNil() {
// Depends on whether Okta.plist is configured or not
Expand Down
10 changes: 9 additions & 1 deletion UITests/UITestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public struct UITestUtils {
}

func allowBrowserLaunch() {
let allowButton = springboard.buttons["Continue"].firstMatch
let allowButton = springboard.buttons["Continue"]
if allowButton.waitForExistence(timeout: 5) {
allowButton.tap()
} else {
Expand Down Expand Up @@ -67,6 +67,14 @@ public struct UITestUtils {
uiElementUsername.tap()
uiElementUsername.typeText(username)

// If the "Swipe-to-type" keyboard is shown (e.g. this is the first launch of the
// device after an Erase & Restart), dismiss the keyboard onboarding view to reveal
// the regular software keyboard.
let continueButton = testApp.buttons["Continue"]
if continueButton.exists {
continueButton.tap()
}

let nextButton = testApp.toolbars["Toolbar"].buttons["Next"]
if nextButton.exists {
nextButton.tap()
Expand Down

0 comments on commit e82bd15

Please sign in to comment.