Skip to content

chore: Fix find_by_images_tests.py #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci-jobs/functional/run_android_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
CI: ${{ parameters.ci }}
steps:
- template: ./run_appium.yml
parameters:
OPENCV: ${{ parameters.opencv }}
- script: bash ci-jobs/functional/start-emulator.sh
displayName: Create and run Emulator
- script: |
Expand Down
3 changes: 3 additions & 0 deletions ci-jobs/functional/run_appium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ steps:
displayName: Install Node 11.x
- script: npm install -g appium@beta --chromedriver_version='2.44'
displayName: Install appium
- script: npm install -g opencv4nodejs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how much longer the tests take now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This installation step takes 8m46s.
In total, it's 20min.
https://dev.azure.com/ki4070ma/python-client/_build/results?buildId=1046&view=logs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the previous value (before enabling opencv)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's 10m30s previously.
Almost just added installation time.
https://dev.azure.com/ki4070ma/python-client/_build/results?buildId=1047

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with the change if such increase in tests execution duration works for you

condition: and(succeeded(), eq('${{ parameters.opencv }}', true))
displayName: Install opencv4nodejs
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
Expand Down
1 change: 1 addition & 0 deletions ci-jobs/functional_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
testFiles: 'device_time_tests.py search_context/find_by_*.py'
sdkVer: ${{ parameters.androidSdkVer }}
CI: ${{ parameters.ci }}
OPENCV: true
- template: ./functional/run_android_test.yml
parameters:
name: 'func_test_android2'
Expand Down
Binary file modified test/functional/android/file/find_by_image_success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 9 additions & 14 deletions test/functional/android/search_context/find_by_image_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
import base64
import unittest

import pytest
from selenium.common.exceptions import NoSuchElementException, TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from test.functional.android.helper import desired_capabilities

from ..helper.test_helper import wait_for_element


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

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

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

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

el = WebDriverWait(self.driver, 3).until(
EC.presence_of_element_located((By.IMAGE, b64_data))
)
el = wait_for_element(self.driver, MobileBy.IMAGE, b64_data)
size = el.size
self.assertIsNotNone(size['width'])
self.assertIsNotNone(size['height'])
Expand All @@ -62,16 +59,14 @@ def test_find_based_on_image_template(self):
self.assertIsNotNone(rect['y'])
self.assertTrue(el.is_displayed())
el.click()
self.driver.find_element_by_accessibility_id("Alarm")
wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, "Alarm")

def test_find_multiple_elements_by_image_just_returns_one(self):
WebDriverWait(self.driver, 3).until(
EC.presence_of_element_located((By.ACCESSIBILITY_ID, "App"))
)
wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, "App")
image_path = desired_capabilities.PATH('file/find_by_image_success.png')
els = self.driver.find_elements_by_image(image_path)
els[0].click()
self.driver.find_element_by_accessibility_id("Alarm")
wait_for_element(self.driver, MobileBy.ACCESSIBILITY_ID, "Alarm")

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

with self.assertRaises(TimeoutException):
WebDriverWait(self.driver, 3).until(
EC.presence_of_element_located((By.IMAGE, b64_data))
EC.presence_of_element_located((MobileBy.IMAGE, b64_data))
)
with self.assertRaises(NoSuchElementException):
self.driver.find_element_by_image(image_path)
Expand Down