Skip to content

Commit 0e4e8fa

Browse files
committed
Add UI test setup on CI with Fastlane
1 parent e6efb0d commit 0e4e8fa

File tree

4 files changed

+149
-16
lines changed

4 files changed

+149
-16
lines changed

.circleci/config.yml

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ orbs:
44
# Using 1.0 of the Orbs means it will use the latest 1.0.x version from https://github.com/wordpress-mobile/circleci-orbs
55
ios: wordpress-mobile/[email protected]
66
git: wordpress-mobile/[email protected]
7+
slack: circleci/[email protected]
78

89
commands:
910
fix-circleci:
@@ -32,22 +33,74 @@ jobs:
3233
root: ./
3334
paths:
3435
- DerivedData/Build/Products
36+
- vendor/bundle
3537

3638
Unit Tests:
3739
executor:
3840
name: ios/default
3941
xcode-version: "11.2.1"
4042
steps:
43+
- git/shallow-checkout
4144
- ios/boot-simulator:
4245
xcode-version: "11.2.1"
4346
device: iPhone 11
4447
- attach_workspace:
4548
at: ./
49+
- run:
50+
name: Prepare Bundle
51+
command: bundle --path vendor/bundle
4652
- ios/wait-for-simulator
47-
- ios/xcodebuild:
48-
command: test-without-building
49-
arguments: -xctestrun DerivedData/Build/Products/WooCommerce_UnitTests_iphonesimulator13.2-x86_64.xctestrun -destination "platform=iOS Simulator,id=$SIMULATOR_UDID"
50-
- ios/save-xcodebuild-artifacts
53+
- run:
54+
name: Run Unit Tests
55+
command: bundle exec fastlane test_without_building xctestrun:DerivedData/Build/Products/WooCommerce_UnitTests_iphonesimulator13.2-x86_64.xctestrun destination:"platform=iOS Simulator,id=$SIMULATOR_UDID" try_count:3
56+
- ios/save-xcodebuild-artifacts:
57+
result-bundle-path: build/results
58+
UI Tests:
59+
parameters:
60+
device:
61+
type: string
62+
post-to-slack:
63+
description: Post to Slack when tests fail. SLACK_WEBHOOK ENV variable must be set.
64+
type: boolean
65+
default: false
66+
executor:
67+
name: ios/default
68+
xcode-version: "11.2.1"
69+
steps:
70+
- git/shallow-checkout
71+
- ios/boot-simulator:
72+
xcode-version: "11.2.1"
73+
device: << parameters.device >>
74+
- attach_workspace:
75+
at: ./
76+
- run:
77+
name: Prepare Bundle
78+
command: bundle --path vendor/bundle
79+
- run:
80+
name: Run mocks
81+
command: ./WooCommerce/WooCommerceUITests/Mocks/scripts/start.sh 8282
82+
background: true
83+
- ios/wait-for-simulator
84+
- run:
85+
name: Run UI Tests
86+
command: bundle exec fastlane test_without_building xctestrun:DerivedData/Build/Products/WooCommerce_UITests_iphonesimulator13.2-x86_64.xctestrun destination:"platform=iOS Simulator,id=$SIMULATOR_UDID" try_count:3
87+
- ios/save-xcodebuild-artifacts:
88+
result-bundle-path: build/results
89+
- when:
90+
condition: << parameters.post-to-slack >>
91+
steps:
92+
- run:
93+
name: Prepare Slack message
94+
when: always
95+
command: |
96+
# Get the name of the device that is running. Using "<< parameters.device >>" can cause slack formatting errors.
97+
DEVICE_NAME=$(xcrun simctl list -j | jq -r --arg UDID $SIMULATOR_UDID '.devices[] | .[] | select(.udid == "\($UDID)") | .name')
98+
echo "export SLACK_FAILURE_MESSAGE=':red_circle: WooCommerce iOS UI tests failed on ${DEVICE_NAME} in \`${CIRCLE_BRANCH}\` branch by ${CIRCLE_USERNAME}.\n\nPlease reach out in #platform9 if you think this failure is not caused by your changes, so we can investigate.'" >> $BASH_ENV
99+
- slack/status:
100+
fail_only: true
101+
include_job_number_field: false
102+
include_project_field: false
103+
failure_message: '${SLACK_FAILURE_MESSAGE}'
51104
Installable Build:
52105
executor:
53106
name: ios/default
@@ -105,6 +158,44 @@ workflows:
105158
- Build Tests
106159
- Unit Tests:
107160
requires: [ "Build Tests" ]
161+
# Always run UI tests on develop and release branches
162+
- UI Tests:
163+
name: UI Tests (iPhone 11)
164+
device: iPhone 11
165+
post-to-slack: true
166+
requires: [ "Build Tests" ]
167+
filters:
168+
branches:
169+
only:
170+
- develop
171+
- /^release.*/
172+
- UI Tests:
173+
name: UI Tests (iPad Air 3rd generation)
174+
device: iPad Air \\(3rd generation\\)
175+
post-to-slack: true
176+
requires: [ "Build Tests" ]
177+
filters:
178+
branches:
179+
only:
180+
- develop
181+
- /^release.*/
182+
#Optionally run UI tests on PRs
183+
- Optional Tests:
184+
type: approval
185+
requires: [ "Build Tests" ]
186+
filters:
187+
branches:
188+
ignore:
189+
- develop
190+
- /^release.*/
191+
- UI Tests:
192+
name: Optional UI Tests (iPhone 11)
193+
device: iPhone 11
194+
requires: [ "Optional Tests" ]
195+
- UI Tests:
196+
name: Optional UI Tests (iPad Air 3rd generation)
197+
device: iPad Air \\(3rd generation\\)
198+
requires: [ "Optional Tests" ]
108199
Installable Build:
109200
jobs:
110201
- Hold:

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ GEM
7373
cocoapods-try (1.1.0)
7474
colored (1.2)
7575
colored2 (3.1.2)
76+
colorize (0.8.1)
7677
commander-fastlane (4.4.6)
7778
highline (~> 1.7.2)
7879
concurrent-ruby (1.1.5)
@@ -135,6 +136,12 @@ GEM
135136
xcpretty-travis-formatter (>= 0.0.3)
136137
fastlane-plugin-appcenter (1.6.0)
137138
fastlane-plugin-sentry (1.6.0)
139+
fastlane-plugin-test_center (3.10.2)
140+
colorize
141+
json
142+
plist
143+
xcodeproj
144+
xctest_list (>= 1.1.8)
138145
ffi (1.12.2)
139146
fourflusher (2.3.1)
140147
fuzzy_match (2.0.4)
@@ -262,6 +269,7 @@ GEM
262269
rouge (~> 2.0.7)
263270
xcpretty-travis-formatter (1.0.0)
264271
xcpretty (~> 0.2, >= 0.0.7)
272+
xctest_list (1.1.8)
265273

266274
PLATFORMS
267275
ruby
@@ -272,6 +280,7 @@ DEPENDENCIES
272280
fastlane (~> 2)!
273281
fastlane-plugin-appcenter (= 1.6.0)
274282
fastlane-plugin-sentry
283+
fastlane-plugin-test_center
275284
fastlane-plugin-wpmreleasetoolkit!
276285
rake!
277286
rmagick (~> 3.2.0)

fastlane/Fastfile

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@ def get_required_env(key)
1313
ENV[key]
1414
end
1515

16-
before_all do
17-
# Check that the env files exist
18-
unless is_ci || File.file?(USER_ENV_FILE_PATH)
19-
UI.user_error!("~/.wcios-env.default not found: Please copy env/user.env-example to #{USER_ENV_FILE_PATH} and fill in the values")
20-
end
21-
unless File.file?(PROJECT_ENV_FILE_PATH)
22-
UI.user_error!("project.env not found: Make sure your configuration is up to date with `rake dependencies`")
23-
end
16+
before_all do |lane|
17+
# Skip these checks/steps for test lane (not needed for testing)
18+
unless lane == :test_without_building
19+
# Check that the env files exist
20+
unless is_ci || File.file?(USER_ENV_FILE_PATH)
21+
UI.user_error!("~/.wcios-env.default not found: Please copy env/user.env-example to #{USER_ENV_FILE_PATH} and fill in the values")
22+
end
23+
unless File.file?(PROJECT_ENV_FILE_PATH)
24+
UI.user_error!("project.env not found: Make sure your configuration is up to date with `rake dependencies`")
25+
end
2426

25-
# This allows code signing to work on CircleCI
26-
# It is skipped if this isn't running on CI
27-
# See https://circleci.com/docs/2.0/ios-codesigning/
28-
setup_circle_ci
27+
# This allows code signing to work on CircleCI
28+
# It is skipped if this isn't running on CI
29+
# See https://circleci.com/docs/2.0/ios-codesigning/
30+
setup_circle_ci
31+
end
2932
end
3033

3134
platform :ios do
@@ -646,4 +649,33 @@ end
646649

647650
def simulator_version()
648651
return '13.3'
652+
end
653+
654+
########################################################################
655+
# Test Lanes
656+
########################################################################
657+
#####################################################################################
658+
# test_without_building
659+
# -----------------------------------------------------------------------------------
660+
# This lane runs tests without building the app.
661+
# It requires a prebuilt xctestrun file and simulator destination where the tests will be run.
662+
# -----------------------------------------------------------------------------------
663+
# Usage:
664+
# bundle exec fastlane test_without_building [xctestrun:<Path to xctestrun file>] [destination:<Simulator>] [try_count:<Number of times to try tests>]
665+
#
666+
# Example:
667+
# bundle exec fastlane test_without_building xctestrun:WooCommerce_UITests_iphonesimulator13.2-x86_64.xctestrun destination:"platform=iOS Simulator,id=$SIMULATOR_UDID" try_count:3
668+
#####################################################################################
669+
desc "Run tests without building"
670+
lane :test_without_building do | options |
671+
multi_scan(
672+
workspace: "WooCommerce.xcworkspace",
673+
scheme: "WooCommerce",
674+
test_without_building: true,
675+
xctestrun: "#{options[:xctestrun]}",
676+
destination: options[:destination],
677+
try_count: options[:try_count],
678+
output_directory: "build/results",
679+
result_bundle: true
680+
)
649681
end

fastlane/Pluginfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ end
99
gem 'fastlane-plugin-wpmreleasetoolkit', git: 'https://github.com/wordpress-mobile/release-toolkit', tag: '0.9.2'
1010
gem 'fastlane-plugin-sentry'
1111
gem 'fastlane-plugin-appcenter', '1.6.0'
12+
gem 'fastlane-plugin-test_center'

0 commit comments

Comments
 (0)