Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ shared/test/test_credentials.json
/libs/MobileSync/build/
/libs/SalesforceSDKCommon/build/
/native/SampleApps/RestAPIExplorer/build/
/native/SampleApps/AuthFlowTester/AuthFlowTesterUITests/ui_test_config.json
node_modules/
.idea/
package-lock.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
4F5946272ED670C7003C5BDE /* Exceptions for "AuthFlowTesterUITests" folder in "AuthFlowTesterUITests" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
test_config.json.sample,
ui_test_config.json.sample,
);
target = 4F8E4AF02ED13CE800DA7B7A /* AuthFlowTesterUITests */;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import Foundation
import XCTest
import SalesforceSDKCore

// MARK: - Label Constants (mirroring the app's Labels structs for JSON parsing)

Expand Down Expand Up @@ -270,10 +271,9 @@ class AuthFlowTesterMainPageObject {
// Tap Change Key button to open the sheet
tap(bottomBarChangeKeyButton())

// Fill in the text fields
setTextField(consumerKeyTextField(), value: appConfig.consumerKey)
setTextField(callbackUrlTextField(), value: appConfig.redirectUri)
setTextField(scopesTextField(), value: scopesToRequest)
// Build JSON config and import it
let configJSON = buildConfigJSON(consumerKey: appConfig.consumerKey, redirectUri: appConfig.redirectUri, scopes: scopesToRequest)
importConfig(configJSON)

// Tap the migrate button
tap(migrateRefreshTokenButton())
Expand All @@ -289,6 +289,35 @@ class AuthFlowTesterMainPageObject {
return true
}

// MARK: - Config Import Helpers

private func buildConfigJSON(consumerKey: String, redirectUri: String, scopes: String) -> String {
let config: [String: String] = [
BootConfigJSONKeys.consumerKey: consumerKey,
BootConfigJSONKeys.redirectUri: redirectUri,
BootConfigJSONKeys.scopes: scopes
]
guard let jsonData = try? JSONSerialization.data(withJSONObject: config, options: []),
let jsonString = String(data: jsonData, encoding: .utf8) else {
return "{}"
}
return jsonString
}

private func importConfig(_ jsonString: String) {
tap(importConfigButton())

// Wait for alert to appear
let alert = importConfigAlert()
_ = alert.waitForExistence(timeout: timeout)

// Type into the alert's text field
let textField = importConfigTextField()
textField.typeText(jsonString)

tap(importAlertButton())
}

// MARK: - UI Element Accessors

private func navigationTitle() -> XCUIElement {
Expand Down Expand Up @@ -373,6 +402,25 @@ class AuthFlowTesterMainPageObject {
return buttons.matching(predicate).firstMatch
}

// Config import

private func importConfigButton() -> XCUIElement {
return app.buttons.matching(identifier: "importConfigButton").firstMatch
}

private func importConfigAlert() -> XCUIElement {
return app.alerts["Import Configuration"]
}

private func importConfigTextField() -> XCUIElement {
// Access text field through the alert - SwiftUI alert TextFields are accessed this way
return importConfigAlert().textFields.firstMatch
}

private func importAlertButton() -> XCUIElement {
return importConfigAlert().buttons["Import"]
}

// User switching

private func newUserButton() -> XCUIElement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ class LoginPageObject {
return loginNavigationBar().waitForExistence(timeout: timeout)
}

func switchToLSCIfShowingAdvancedAuthentication() -> Void {
if (isShowingAdvancedAuth()) {
tap(advancedAuthCloseButton())
tap(hostRow(host: "Production"))
}
}

func configureLoginHost(host: String) -> Void {
tap(settingsButton())
tap(changeServerButton())
Expand All @@ -60,7 +67,9 @@ class LoginPageObject {

func performLogin(username: String, password: String) {
setTextField(usernameField(), value: username)
tap(passwordFieldLabel()) // click on label to hide keyboard
setTextField(passwordField(), value: password)
tap(usernameFieldLabel()) // click on label to hide keyboard
tap(loginButton())
tapIfPresent(allowButton())
}
Expand Down Expand Up @@ -163,11 +172,19 @@ class LoginPageObject {
private func hostRow(host: String) -> XCUIElement {
return app.staticTexts[host].firstMatch
}

private func usernameFieldLabel() -> XCUIElement {
return app.staticTexts["Username"]
}

private func usernameField() -> XCUIElement {
return app.descendants(matching: .textField).element
}

private func passwordFieldLabel() -> XCUIElement {
return app.staticTexts["Password"]
}

private func passwordField() -> XCUIElement {
return app.descendants(matching: .secureTextField).element
}
Expand Down Expand Up @@ -239,6 +256,10 @@ class LoginPageObject {
return importConfigAlert().buttons["Import"]
}

private func advancedAuthCloseButton() -> XCUIElement {
return app.otherElements["TopBrowserBar"].buttons["Close"]
}

// MARK: - Actions

private func tap(_ element: XCUIElement) {
Expand Down Expand Up @@ -293,5 +314,9 @@ class LoginPageObject {
return row.waitForExistence(timeout: timeout)
}

private func isShowingAdvancedAuth() -> Bool {
return advancedAuthCloseButton().waitForExistence(timeout: timeout)
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
AdvancedAuthBeaconLoginTests.swift
AuthFlowTesterUITests

Copyright (c) 2025-present, salesforce.com, inc. All rights reserved.

Redistribution and use of this software in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of salesforce.com, inc. nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior written
permission of salesforce.com, inc.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import XCTest

/// Tests for login flows using Beacon app configurations with advanced authentication.
/// This class runs the same tests as BeaconLoginTests but uses the advanced_auth login host.
///
/// NB: Tests use the first user from ui_test_config.json (advanced_auth host)
///
class AdvancedAuthBeaconLoginTests: BeaconLoginTests {

// MARK: - Login Host Configuration

/// Override to use advanced authentication login host.
override func loginHostConfig() -> KnownLoginHostConfig {
return .advancedAuth
}

override func postLogoutCleanup() {
switchToLSCIfShowingAdvancedAuthentication()
}
}
Loading
Loading