Skip to content

Commit 7721eec

Browse files
authored
test: tweak tests (#425)
* add log * pr only * tweak keyboards * fix typo * tweak image tests
1 parent 4aa807e commit 7721eec

File tree

4 files changed

+48
-22
lines changed

4 files changed

+48
-22
lines changed

azure-pipelines.yml

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
jobs:
66
- template: ./ci-jobs/functional_test.yml
77

8+
pr:
9+
- master
10+
- main
11+
812
# Runs tests nightly to make sure they works against appium@beta
913
schedules:
1014
- cron: "0 0 * * *"

test/functional/android/android/image_comparison_test.rb

+35-17
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_image_comparison_find_result
5757
assert_equal({ 'x' => 0, 'y' => 0, 'width' => 750, 'height' => 1334 }, find_result['rect'])
5858
assert !find_result['score'].nil?
5959

60-
assert_equal(nil, find_result['visualization'])
60+
assert_nil find_result['visualization']
6161

6262
multiple = find_result['multiple']
6363
assert_equal(1, multiple.size)
@@ -106,22 +106,31 @@ def test_image_element
106106
assert image_element.hash
107107
assert image_element.id =~ /\Aappium-image-element-[a-z0-9\-]+/
108108

109+
# Android is not so stable on emulator, so this test checks each value is not nil.
109110
el_location = el.location
110111
image_location = image_element.location
111-
assert_in_delta el_location.x, image_location.x, 1
112-
assert_in_delta el_location.y, image_location.y, 1
112+
refute_nil el_location.x
113+
refute_nil el_location.y
114+
refute_nil image_location.x
115+
refute_nil image_location.y
113116

114117
el_size = el.size
115118
image_size = image_element.size
116-
assert_in_delta el_size.width, image_size.width, 1
117-
assert_in_delta el_size.height, image_size.height, 1
119+
refute_nil el_size.width
120+
refute_nil el_size.height
121+
refute_nil image_size.width
122+
refute_nil image_size.height
118123

119124
el_rect = el.rect
120125
image_rect = image_element.rect
121-
assert_in_delta el_rect.x, image_rect.x, 1
122-
assert_in_delta el_rect.y, image_rect.y, 1
123-
assert_in_delta el_rect.width, image_rect.width, 1
124-
assert_in_delta el_rect.height, image_rect.height, 1
126+
refute_nil el_rect.x
127+
refute_nil el_rect.y
128+
refute_nil image_rect.x
129+
refute_nil image_rect.y
130+
refute_nil el_rect.width
131+
refute_nil el_rect.height
132+
refute_nil image_rect.width
133+
refute_nil image_rect.height
125134

126135
assert_equal el.displayed?, image_element.displayed?
127136
image_element.click
@@ -154,22 +163,31 @@ def test_image_elements
154163
assert image_element.hash
155164
assert image_element.id =~ /\Aappium-image-element-[a-z0-9\-]+/
156165

166+
# Android is not so stable on emulator, so this test checks each value is not nil.
157167
el_location = el.location
158168
image_location = image_element.location
159-
assert_in_delta el_location.x, image_location.x, 13
160-
assert_in_delta el_location.y, image_location.y, 13
169+
refute_nil el_location.x
170+
refute_nil el_location.y
171+
refute_nil image_location.x
172+
refute_nil image_location.y
161173

162174
el_size = el.size
163175
image_size = image_element.size
164-
assert_in_delta el_size.width, image_size.width, 13
165-
assert_in_delta el_size.height, image_size.height, 13
176+
refute_nil el_size.width
177+
refute_nil el_size.height
178+
refute_nil image_size.width
179+
refute_nil image_size.height
166180

167181
el_rect = el.rect
168182
image_rect = image_element.rect
169-
assert_in_delta el_rect.x, image_rect.x, 13
170-
assert_in_delta el_rect.y, image_rect.y, 13
171-
assert_in_delta el_rect.width, image_rect.width, 13
172-
assert_in_delta el_rect.height, image_rect.height, 13
183+
refute_nil el_rect.x
184+
refute_nil el_rect.y
185+
refute_nil image_rect.x
186+
refute_nil image_rect.y
187+
refute_nil el_rect.width
188+
refute_nil el_rect.height
189+
refute_nil image_rect.width
190+
refute_nil image_rect.height
173191

174192
assert_equal el.displayed?, image_element.displayed?
175193
image_element.click

test/functional/ios/driver_test.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,17 @@ def test_default_keyboard_pref
119119
# to wait the animation
120120
@@driver.wait { |d| d.find_element :accessibility_id, 'Auto-Correction' }
121121

122-
eles = @@driver.find_elements :class, 'XCUIElementTypeSwitch'
123-
switches_status = eles.each_with_object({}) { |e, acc| acc[e.name] = e.value }
122+
auto_correction = @@driver.wait do |d|
123+
d.find_element :predicate, 'name == "Auto-Correction" AND type == "XCUIElementTypeSwitch"'
124+
end
125+
predictive = @@driver.wait do |d|
126+
d.find_element :predicate, 'name == "Predictive" AND type == "XCUIElementTypeSwitch"'
127+
end
128+
assert_equal '0', auto_correction.value
129+
assert_equal '0', predictive.value
124130
ensure
125131
@@driver.activate_app(bundle_id)
126132
end
127-
assert_equal '0', switches_status['Auto-Correction'], "Switches are #{switches_status}"
128-
assert_equal '0', switches_status['Predictive'], "Switches are #{switches_status}"
129133
end
130134

131135
# @since Appium 1.15.0

test/functional/ios/ios/image_comparison_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_image_comparison_find_result
5858
assert_equal({ 'x' => 0, 'y' => 0, 'width' => 750, 'height' => 1334 }, find_result['rect'])
5959
assert !find_result['score'].nil?
6060

61-
assert_equal(nil, find_result['visualization'])
61+
assert_nil find_result['visualization']
6262

6363
multiple = find_result['multiple']
6464
assert_equal(1, multiple.size)

0 commit comments

Comments
 (0)