Skip to content

Commit

Permalink
update opencv and fix test scenarios (#105)
Browse files Browse the repository at this point in the history
Co-authored-by: Alvaro Laserna <[email protected]>
  • Loading branch information
alvarolaserna and Alvaro Laserna authored Sep 30, 2024
1 parent c5de90f commit adc43ea
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build
# lib
pytest<=8.0.1
Appium-Python-Client~=4.0.0
opencv-python~=4.8.1
opencv-python~=4.10.0.84
geckodriver-autoinstaller==0.1.0
pytest-xdist~=2.5.0
pytest-testrail~=2.9.0
Expand Down
16 changes: 8 additions & 8 deletions tests/appium_app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ def test_appium_app(self, appium_driver: TestUIDriver):
# appium_driver.touch_actions().press(x=500, y=10)\
# .move_to(x=500, y=1000).release().perform()

appium_driver.actions().w3c_actions = ActionBuilder(
actions = ActionBuilder(
appium_driver.get_driver(),
mouse=PointerInput(interaction.POINTER_TOUCH, "touch"))
mouse=PointerInput(interaction.POINTER_TOUCH, "touch")
)

actions = appium_driver.actions()
actions.w3c_actions.pointer_action.move_to_location(x=500, y=10)
actions.w3c_actions.pointer_action.pointer_down()
actions.w3c_actions.pointer_action.pause(1)
actions.w3c_actions.pointer_action.move_to_location(x=500, y=1000)
actions.w3c_actions.pointer_action.release()
actions.pointer_action.move_to_location(x=500, y=10)
actions.pointer_action.pointer_down()
actions.pointer_action.pause(1)
actions.pointer_action.move_to_location(x=500, y=1000)
actions.pointer_action.release()
actions.perform()

appium_driver.raise_errors()
15 changes: 9 additions & 6 deletions tests/appium_tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import time

import os
import pytest

from testui.support import logger
from testui.support.appium_driver import NewDriver
from testui.support.testui_driver import TestUIDriver

test_dir = os.path.dirname(__file__)

class TestStringMethods:
@pytest.yield_fixture(autouse=True)
Expand All @@ -17,7 +18,7 @@ def selenium_driver(self):
.set_soft_assert(True)
.set_appium_driver()
)
driver.configuration.save_full_stacktrace
driver.configuration.save_full_stacktrace = True
yield driver
driver.quit()

Expand All @@ -29,17 +30,19 @@ def test_screenshot_methods(self, selenium_driver: TestUIDriver):
selenium_driver.navigate_to(
"https://github.com/testdevlab/Py-TestUI#image-recognition"
)
selenium_driver.click_by_image("./resources/comp.png", threshold=0.6, ratio=0.5, webview=True)
image_compare = os.path.join(test_dir, "..", "resources", "comp.png")
selenium_driver.click_by_image(image=image_compare, threshold=0.6, ratio=0.5, webview=True)
selenium_driver.start_recording_screen()
time.sleep(1)
image_result = os.path.join(test_dir, "..", "logs", "v-image.png")
selenium_driver.stop_recording_and_compare(
"./resources/comp.png",
comparison=image_compare,
fps_reduction=30,
keep_image_as="./logs/v-image.png",
keep_image_as=image_result,
threshold=0.6
)
selenium_driver.find_image_match(
"./resources/comp.png", 0.6, True, image_match="./logs/image.png"
comparison=image_compare, threshold=0.6, assertion=True, image_match="./logs/image.png"
)

time.sleep(110)
Expand Down
7 changes: 6 additions & 1 deletion tests/selenium_tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import pytest
import os
from selenium.webdriver.chrome.options import Options

from testui.support import logger
from testui.support.appium_driver import NewDriver
from testui.support.testui_driver import TestUIDriver


test_dir = os.path.dirname(__file__)

class TestStringMethods:
@pytest.yield_fixture(autouse=True)
def selenium_driver(self):
Expand All @@ -29,8 +32,10 @@ def test_template_matching(self, selenium_driver: TestUIDriver):
selenium_driver.navigate_to(
"https://github.com/testdevlab/Py-TestUI#image-recognition"
)
image_result = os.path.join(test_dir, "..", "logs", "image.png")
image_compare = os.path.join(test_dir, "..", "resources", "comp.png")
selenium_driver.find_image_match(
"resources/comp.png", 0.1, True, image_match="./logs/image.png"
image_compare, 0.1, True, image_match=image_result
)
selenium_driver.raise_errors()

Expand Down

0 comments on commit adc43ea

Please sign in to comment.