Skip to content

Commit 253c92e

Browse files
committed
add tests for find by image with scaled ratio
1 parent dfc4ca3 commit 253c92e

File tree

5 files changed

+79
-4
lines changed

5 files changed

+79
-4
lines changed

test/functional/android/android/device_test.rb

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def test_file_management
403403
end
404404

405405
def test_image_element
406-
skip 'Requres `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
406+
skip 'Requires `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
407407

408408
@driver.rotation = :portrait
409409

@@ -441,7 +441,7 @@ def test_image_element
441441
end
442442

443443
def test_image_elements
444-
skip 'Requres `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
444+
skip 'Requires `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
445445

446446
@driver.rotation = :landscape
447447

@@ -479,6 +479,42 @@ def test_image_elements
479479
@driver.back
480480
end
481481

482+
def test_template_scale_ratio
483+
skip 'Requires `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
484+
485+
@driver.rotation = :portrait
486+
487+
el = @driver.find_element :accessibility_id, 'NFC'
488+
@driver.save_element_screenshot el, 'test/functional/data/test_android_nfc.png'
489+
490+
@driver.update_settings({ defaultImageTemplateScale: 4 })
491+
492+
image_element = @driver.find_element_by_image AppiumLibCoreTest.path_of('test/functional/data/test_android_nfc_270.png')
493+
assert image_element.inspect
494+
assert image_element.hash
495+
assert image_element.ref =~ /\Aappium-image-element-[a-z0-9\-]+/
496+
497+
el_location = el.location
498+
image_location = image_element.location
499+
assert_in_delta el_location.x, image_location.x, 3
500+
assert_in_delta el_location.y, image_location.y, 3
501+
502+
el_size = el.size
503+
image_size = image_element.size
504+
assert_in_delta el_size.width, image_size.width, 3
505+
assert_in_delta el_size.height, image_size.height, 3
506+
507+
el_rect = el.rect
508+
image_rect = image_element.rect
509+
assert_in_delta el_rect.x, image_rect.x, 3
510+
assert_in_delta el_rect.y, image_rect.y, 3
511+
assert_in_delta el_rect.width, image_rect.width, 3
512+
assert_in_delta el_rect.height, image_rect.height, 3
513+
514+
assert_equal el.displayed?, image_element.displayed?
515+
image_element.click
516+
end
517+
482518
private
483519

484520
def scroll_to(text)
1.55 KB
Loading
-7.18 KB
Binary file not shown.
Loading

test/functional/ios/ios/device_test.rb

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def teardown
1616
end
1717

1818
def test_image_element
19-
skip 'Requres `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
19+
skip 'Requires `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
2020

2121
@@driver.update_settings({ fixImageTemplateScale: true })
2222

@@ -54,7 +54,7 @@ def test_image_element
5454
end
5555

5656
def test_image_elements
57-
skip 'Requres `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
57+
skip 'Requires `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
5858

5959
@@driver.update_settings({ fixImageTemplateScale: true })
6060

@@ -92,6 +92,45 @@ def test_image_elements
9292
@@driver.back
9393
end
9494

95+
def test_template_scale_ratio
96+
skip 'Requires `npm install -g appium opencv4nodejs`' unless `npm list -g opencv4nodejs`.include? 'opencv4nodejs'
97+
98+
el = @@driver.find_element :accessibility_id, 'Buttons'
99+
@@driver.save_element_screenshot el, 'test/functional/data/test_ios_button.png'
100+
101+
@@driver.update_settings({ fixImageTemplateScale: true, defaultImageTemplateScale: 4 })
102+
103+
image_element = @@driver.find_element_by_image(
104+
AppiumLibCoreTest.path_of('test/functional/data/test_button_image_ios_4.png')
105+
)
106+
assert image_element.inspect
107+
assert image_element.hash
108+
assert image_element.ref =~ /\Aappium-image-element-[a-z0-9\-]+/
109+
110+
el_location = el.location
111+
image_location = image_element.location
112+
assert_in_delta el_location.x, image_location.x, 10
113+
assert_in_delta el_location.y, image_location.y, 2
114+
115+
el_size = el.size
116+
image_size = image_element.size
117+
assert_in_delta el_size.width, image_size.width, 15
118+
assert_in_delta el_size.height, image_size.height, 2
119+
120+
el_rect = el.rect
121+
image_rect = image_element.rect
122+
assert_in_delta el_rect.x, image_rect.x, 10
123+
assert_in_delta el_rect.y, image_rect.y, 2
124+
assert_in_delta el_rect.width, image_rect.width, 15
125+
assert_in_delta el_rect.height, image_rect.height, 2
126+
127+
assert_equal el.displayed?, image_element.displayed?
128+
image_element.click
129+
130+
assert @@driver.find_element :accessibility_id, 'Gray'
131+
@@driver.back
132+
end
133+
95134
def test_window_size
96135
size = @@driver.window_size
97136
assert size.width

0 commit comments

Comments
 (0)