Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add first UI test #151

Closed
wants to merge 3 commits into from
Closed
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
13 changes: 13 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ jobs:
CLIENT_TOKEN: ${{ secrets.CONFIDENCE_CLIENT_TOKEN }}
run: scripts/run_tests.sh $CLIENT_TOKEN

UITests:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v3
- name: webfactory/ssh-agent
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SDK_REPO_PRIVATE_KEY }}
- name: Build and UITest
env:
CLIENT_TOKEN: ${{ secrets.CONFIDENCE_CLIENT_TOKEN }}
run: ConfidenceDemoApp/scripts/run_tests.sh $CLIENT_TOKEN

SwiftLint:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
/.build
ConfidenceDemoApp/build/XCBuildData/**
/Packages
/**/*.xcodeproj
xcuserdata/
Expand Down
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ excluded:
- ${PWD}/.build
- ${PWD}/Tools/*/.build
- ${PWD}/Sources/ConfidenceProvider/FlagResolver/
- ${PWD}/ConfidenceDemoApp/

disabled_rules:
- discarded_notification_center_observer
Expand Down
371 changes: 128 additions & 243 deletions ConfidenceDemoApp/ConfidenceDemoApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct ContentView: View {
.foregroundColor(color.color)
.padding(10)
Text(text.text)
.accessibilityIdentifier("flag_text")
Button("Get remote flag value") {
text.text = confidence.getValue(key: "swift-demoapp.color", defaultValue: "ERROR")
if text.text == "Green" {
Expand All @@ -31,7 +32,7 @@ struct ContentView: View {
} else {
color.color = .red
}
}
}.accessibilityIdentifier("flag_button")
Button("Flush 🚽") {
confidence.flush()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import XCTest

@testable import ConfidenceDemoApp

final class ConfidenceDemoAppUITests: XCTestCase {
override func setUpWithError() throws {
try super.setUpWithError()
continueAfterFailure = false

let app = XCUIApplication()
app.launchEnvironment = ["CLIENT_SECRET": ProcessInfo.processInfo.environment["CLIENT_SECRET"] ?? ""]
app.launch()
}

override func tearDownWithError() throws {
try super.tearDownWithError()
}

func testGetFlagValue() {
let app = XCUIApplication()
let button = app.buttons["flag_button"]
button.tap()
let flag = app.staticTexts["flag_text"]
XCTAssertEqual(flag.label, "Yellow")
}
Comment on lines +19 to +25
Copy link
Member Author

Choose a reason for hiding this comment

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

The actual test logic


func testLaunchPerformance() throws {
if #available(macOS 10.15, iOS 17.0, tvOS 13.0, watchOS 7.0, *) {
// This measures how long it takes to launch your application.
measure(metrics: [XCTApplicationLaunchMetric()]) {
XCUIApplication().launch()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import XCTest

@testable import ConfidenceDemoApp

final class ConfidenceDemoAppUITestsLaunchTests: XCTestCase {
override class var runsForEachTargetApplicationUIConfiguration: Bool {
true
}

override func setUpWithError() throws {
try super.setUpWithError()
continueAfterFailure = false
}

func testLaunch() throws {
let app = XCUIApplication()
app.launch()

// Insert steps here to perform after app launch but before taking a screenshot,
// such as logging into a test account or navigating somewhere in the app

let attachment = XCTAttachment(screenshot: app.screenshot())
attachment.name = "Launch Screen"
attachment.lifetime = .keepAlways
add(attachment)
}
}
21 changes: 21 additions & 0 deletions ConfidenceDemoApp/scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e

script_dir=$(dirname $0)
root_dir="$script_dir/../"

# Set the client token in your local keychain using the following command:
# security add-generic-password -s 'swift-provider-e2e' -a 'confidence-test' -w 'TOKEN'
# You can then run the script with no arguments - you will need to allow access the first time only.
test_runner_client_token=$1
if [[ -z "${test_runner_client_token// }" ]]; then
test_runner_client_token=$(security find-generic-password -w -s 'swift-provider-e2e' -a 'confidence-test')
fi

(cd $root_dir &&
TEST_RUNNER_CLIENT_TOKEN=$test_runner_client_token TEST_RUNNER_TEST_FLAG_NAME=$2 xcodebuild \
-quiet \
-scheme ConfidenceDemoApp \
-destination 'platform=iOS Simulator,name=iPhone 15,OS=17.2' \
test)
Loading