Skip to content

Commit b95776d

Browse files
authored
chore: Fix find_by_images_tests.py (appium#495)
* chore: Fix find_by_images_tests.py * Add installation opencv4nodejs * Fix typo * Add taking screen record to find_by_image_test * Fix errors on the emulator * Remove unused imports
1 parent 4d269f8 commit b95776d

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

ci-jobs/functional/run_android_test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ jobs:
77
CI: ${{ parameters.ci }}
88
steps:
99
- template: ./run_appium.yml
10+
parameters:
11+
OPENCV: ${{ parameters.opencv }}
1012
- script: bash ci-jobs/functional/start-emulator.sh
1113
displayName: Create and run Emulator
1214
- script: |

ci-jobs/functional/run_appium.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ steps:
55
displayName: Install Node 11.x
66
- script: npm install -g appium@beta --chromedriver_version='2.44'
77
displayName: Install appium
8+
- script: npm install -g opencv4nodejs
9+
condition: and(succeeded(), eq('${{ parameters.opencv }}', true))
10+
displayName: Install opencv4nodejs
811
- task: UsePythonVersion@0
912
inputs:
1013
versionSpec: '3.x'

ci-jobs/functional_test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
testFiles: 'device_time_tests.py search_context/find_by_*.py'
3333
sdkVer: ${{ parameters.androidSdkVer }}
3434
CI: ${{ parameters.ci }}
35+
OPENCV: true
3536
- template: ./functional/run_android_test.yml
3637
parameters:
3738
name: 'func_test_android2'
-1.09 KB
Loading

test/functional/android/search_context/find_by_image_tests.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
import base64
1616
import unittest
1717

18-
import pytest
1918
from selenium.common.exceptions import NoSuchElementException, TimeoutException
20-
from selenium.webdriver.common.by import By
2119
from selenium.webdriver.support import expected_conditions as EC
2220
from selenium.webdriver.support.ui import WebDriverWait
2321

2422
from appium import webdriver
23+
from appium.webdriver.common.mobileby import MobileBy
2524
from test.functional.android.helper import desired_capabilities
2625

26+
from ..helper.test_helper import wait_for_element
27+
2728

28-
@pytest.mark.skip(reason="Need to fix broken test")
2929
class FindByImageTests(unittest.TestCase):
3030

3131
def setUp(self):
32-
desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk')
32+
desired_caps = desired_capabilities.get_desired_capabilities('ApiDemos-debug.apk.zip')
3333
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
3434

3535
# relax template matching
@@ -42,13 +42,10 @@ def tearDown(self):
4242

4343
def test_find_based_on_image_template(self):
4444
image_path = desired_capabilities.PATH('file/find_by_image_success.png')
45-
print(image_path)
4645
with open(image_path, 'rb') as png_file:
4746
b64_data = base64.b64encode(png_file.read()).decode('UTF-8')
4847

49-
el = WebDriverWait(self.driver, 3).until(
50-
EC.presence_of_element_located((By.IMAGE, b64_data))
51-
)
48+
el = wait_for_element(self.driver, MobileBy.IMAGE, b64_data)
5249
size = el.size
5350
self.assertIsNotNone(size['width'])
5451
self.assertIsNotNone(size['height'])
@@ -62,16 +59,14 @@ def test_find_based_on_image_template(self):
6259
self.assertIsNotNone(rect['y'])
6360
self.assertTrue(el.is_displayed())
6461
el.click()
65-
self.driver.find_element_by_accessibility_id("Alarm")
62+
wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, "Alarm")
6663

6764
def test_find_multiple_elements_by_image_just_returns_one(self):
68-
WebDriverWait(self.driver, 3).until(
69-
EC.presence_of_element_located((By.ACCESSIBILITY_ID, "App"))
70-
)
65+
wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, "App")
7166
image_path = desired_capabilities.PATH('file/find_by_image_success.png')
7267
els = self.driver.find_elements_by_image(image_path)
7368
els[0].click()
74-
self.driver.find_element_by_accessibility_id("Alarm")
69+
wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, "Alarm")
7570

7671
def test_find_throws_no_such_element(self):
7772
image_path = desired_capabilities.PATH('file/find_by_image_failure.png')
@@ -80,7 +75,7 @@ def test_find_throws_no_such_element(self):
8075

8176
with self.assertRaises(TimeoutException):
8277
WebDriverWait(self.driver, 3).until(
83-
EC.presence_of_element_located((By.IMAGE, b64_data))
78+
EC.presence_of_element_located((MobileBy.IMAGE, b64_data))
8479
)
8580
with self.assertRaises(NoSuchElementException):
8681
self.driver.find_element_by_image(image_path)

0 commit comments

Comments
 (0)