Skip to content

Commit 33d6f1b

Browse files
authored
Merge pull request #2214 from woocommerce/add/ui-test-ci-setup
Testing: Add UI test setup on CI with Fastlane
2 parents 53ddce0 + 035c1c5 commit 33d6f1b

File tree

4 files changed

+147
-5
lines changed

4 files changed

+147
-5
lines changed

.circleci/config.yml

Lines changed: 104 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,80 @@ 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: >
56+
bundle exec fastlane test_without_building
57+
xctestrun:DerivedData/Build/Products/WooCommerce_UnitTests_iphonesimulator13.2-x86_64.xctestrun
58+
destination:"platform=iOS Simulator,id=$SIMULATOR_UDID" try_count:3
59+
- ios/save-xcodebuild-artifacts:
60+
result-bundle-path: build/results
61+
UI Tests:
62+
parameters:
63+
device:
64+
type: string
65+
post-to-slack:
66+
description: Post to Slack when tests fail. SLACK_WEBHOOK ENV variable must be set.
67+
type: boolean
68+
default: false
69+
executor:
70+
name: ios/default
71+
xcode-version: "11.2.1"
72+
steps:
73+
- git/shallow-checkout
74+
- ios/boot-simulator:
75+
xcode-version: "11.2.1"
76+
device: << parameters.device >>
77+
- attach_workspace:
78+
at: ./
79+
- run:
80+
name: Prepare Bundle
81+
command: bundle --path vendor/bundle
82+
- run:
83+
name: Run mocks
84+
command: ./WooCommerce/WooCommerceUITests/Mocks/scripts/start.sh 8282
85+
background: true
86+
- ios/wait-for-simulator
87+
- run:
88+
name: Run UI Tests
89+
command: >
90+
bundle exec fastlane test_without_building
91+
xctestrun:DerivedData/Build/Products/WooCommerce_UITests_iphonesimulator13.2-x86_64.xctestrun
92+
destination:"platform=iOS Simulator,id=$SIMULATOR_UDID" try_count:3
93+
- ios/save-xcodebuild-artifacts:
94+
result-bundle-path: build/results
95+
- when:
96+
condition: << parameters.post-to-slack >>
97+
steps:
98+
- run:
99+
name: Prepare Slack message
100+
when: always
101+
command: |
102+
# Get the name of the device that is running. Using "<< parameters.device >>" can cause slack formatting errors.
103+
DEVICE_NAME=$(xcrun simctl list -j | jq -r --arg UDID $SIMULATOR_UDID '.devices[] | .[] | select(.udid == "\($UDID)") | .name')
104+
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
105+
- slack/status:
106+
fail_only: true
107+
include_job_number_field: false
108+
include_project_field: false
109+
failure_message: '${SLACK_FAILURE_MESSAGE}'
51110
Installable Build:
52111
executor:
53112
name: ios/default
@@ -105,6 +164,47 @@ workflows:
105164
- Build Tests
106165
- Unit Tests:
107166
requires: [ "Build Tests" ]
167+
# Always run UI tests on develop and release branches
168+
- UI Tests:
169+
name: UI Tests (iPhone 11)
170+
device: iPhone 11
171+
post-to-slack: true
172+
requires: [ "Build Tests" ]
173+
filters:
174+
branches:
175+
only:
176+
- develop
177+
- /^release.*/
178+
- UI Tests:
179+
name: UI Tests (iPad Air 3rd generation)
180+
device: iPad Air \\(3rd generation\\)
181+
post-to-slack: true
182+
requires: [ "Build Tests" ]
183+
filters:
184+
branches:
185+
only:
186+
- develop
187+
- /^release.*/
188+
#Optionally run UI tests on PRs
189+
Optional Tests:
190+
jobs:
191+
- Hold:
192+
type: approval
193+
filters:
194+
branches:
195+
ignore:
196+
- develop
197+
- /^release.*/
198+
- Build Tests:
199+
requires: [ "Hold" ]
200+
- UI Tests:
201+
name: Optional UI Tests (iPhone 11)
202+
device: iPhone 11
203+
requires: [ "Build Tests" ]
204+
- UI Tests:
205+
name: Optional UI Tests (iPad Air 3rd generation)
206+
device: iPad Air \\(3rd generation\\)
207+
requires: [ "Build Tests" ]
108208
Installable Build:
109209
jobs:
110210
- 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: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def get_required_env(key)
1313
ENV[key]
1414
end
1515

16-
before_all do
16+
before_all do |lane|
17+
# Skip these checks/steps for test lane (not needed for testing)
18+
next if lane == :test_without_building
19+
1720
# Check that the env files exist
1821
unless is_ci || File.file?(USER_ENV_FILE_PATH)
1922
UI.user_error!("~/.wcios-env.default not found: Please copy env/user.env-example to #{USER_ENV_FILE_PATH} and fill in the values")
@@ -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)