Skip to content
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
37 changes: 37 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: TestUI CI integration tests workflow

on:
push:
branches:
- master
pull_request:
branches:
- master

workflow_dispatch:

jobs:
integration_test:
runs-on: ubuntu-latest
continue-on-error: true

steps:
- uses: actions/checkout@v3
- name: setup python
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- name: install requirements
run: python -m pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
- name: Remove Chrome
run: sudo apt purge google-chrome-stable
- name: Remove default Chromium
run: sudo apt purge chromium-browser
- name: Install a new Chromium
run: sudo apt install -y chromium-browser
- name: Integration browser test with Pytest
run: python -m pytest tests/selenium_tests.py
3 changes: 3 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ extension-pkg-whitelist=
# paths.
ignore=

# Specify a score threshold to be exceeded before program exits with error.
fail-under=8.0

# Add files or directories matching the regex patterns to the blacklist. The
# regex matches against base names, not paths.
ignore-patterns=
Expand Down
3 changes: 2 additions & 1 deletion tests/appium_ios_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def appium_driver(self):
NewDriver()
.set_bundle_id("com.apple.Preferences")
.set_platform("ios")
.set_udid("CC69C1D7-352E-4856-BFD0-B3E908747170") # Change UDID for iOS device
# Change UDID for iOS device
.set_udid("CC69C1D7-352E-4856-BFD0-B3E908747170")
.set_logger()
.set_appium_driver()
)
Expand Down
6 changes: 5 additions & 1 deletion tests/appium_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def test_screenshot_methods(self, selenium_driver: TestUIDriver):
)
selenium_driver.start_recording_screen()
time.sleep(1)
selenium_driver.stop_recording_and_compare("./resources/comp.png", fps_reduction=30, keep_image_as="./logs/v-image.png")
selenium_driver.stop_recording_and_compare(
"./resources/comp.png",
fps_reduction=30,
keep_image_as="./logs/v-image.png",
)
selenium_driver.find_image_match(
"./resources/comp.png", 0.9, True, image_match="./logs/image.png"
)
Expand Down
7 changes: 3 additions & 4 deletions tests/selenium_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from selenium.webdriver.chrome.options import Options

from tests.screens.landing import LandingScreen
from testui.support import logger
from testui.support.appium_driver import NewDriver
from testui.support.testui_driver import TestUIDriver
Expand All @@ -26,19 +25,19 @@ def selenium_driver(self):
@pytest.mark.signup
def test_template_matching(self, selenium_driver: TestUIDriver):
logger.log_test_name("T92701: Create an account")
selenium_driver.get_driver().set_window_size(1000, 1100)
selenium_driver.get_driver.set_window_size(1000, 1200)
selenium_driver.navigate_to(
"https://github.com/testdevlab/Py-TestUI#image-recognition"
)
selenium_driver.find_image_match(
"resources/comp.png", 0.9, True, image_match="./logs/image.png"
"resources/comp.png", 0.1, True, image_match="./logs/image.png"
)
selenium_driver.raise_errors()

@pytest.mark.signup
def test_get_dimensions(self, selenium_driver: TestUIDriver):
logger.log_test_name("T92701: Create an account")
selenium_driver.get_driver().set_window_size(1000, 1100)
selenium_driver.get_driver.set_window_size(1000, 1100)
selenium_driver.navigate_to(
"https://github.com/testdevlab/Py-TestUI#image-recognition"
)
Expand Down
54 changes: 50 additions & 4 deletions testui/elements/testui_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,36 @@


class Error(Exception):
"""Base class for exceptions in this module."""
"""Base class for exceptions in this module"""


# pylint: disable=super-init-not-called
class CollectionException(Error):
"""Exception raised for errors in the input"""

def __init__(self, message, expression=""):
self.message = message
self.expression = expression


class Collections:
"""
Class for working with collections of elements
"""

def __init__(self, args):
"""
:param args: list of elements
"""
self.args = args
self.__errors = []

def wait_until_all_visible(self, seconds=10.0, log=True):
"""
Wait until all elements in collection are visible
:param seconds: timeout
:param log: log to console
"""
start = time.time()
threads = []
for arg in self.args:
Expand Down Expand Up @@ -51,6 +66,12 @@ def wait_until_all_visible(self, seconds=10.0, log=True):
)

def find_visible(self, seconds=10, return_el_number=False):
"""
Find first visible element in collection
:param seconds: timeout
:param return_el_number: return element number
:return: element
"""
start = time.time()
arg: Elements
i = 0
Expand All @@ -64,15 +85,21 @@ def find_visible(self, seconds=10, return_el_number=False):
)
if return_el_number:
return arg, i
else:
return arg

return arg
i += 1
self.__show_error(
f"{self.args[0].device_name}: No element within the collection was "
f"found visible after {time.time() - start}s:"
)

def wait_until_attribute(self, attr_type: list, attr: list, seconds=10):
"""
Wait until all elements in collection have the correct attribute
:param attr_type: list of attribute types
:param attr: list of attributes
:param seconds: timeout
"""
start = time.time()
if len(attr_type) != len(self.args) or len(attr_type) != len(attr):
raise Exception(
Expand Down Expand Up @@ -112,18 +139,34 @@ def wait_until_attribute(self, attr_type: list, attr: list, seconds=10):
)

def get(self, index: int):
"""
Get element by index
:param index: element index
:return: element
"""
element: Elements = self.args[index]
return element

def __wait_until_attribute(
self, element: Elements, attr_type, attr, seconds
):
"""
Wait until element has the correct attribute
:param element: element
:param attr_type: attribute type
:param attr: attribute
:param seconds: timeout
"""
try:
element.wait_until_attribute(attr_type, attr, seconds)
except Exception as err:
self.__errors.append(err)

def __show_error(self, exception) -> None:
"""
Show error for provided expectation
:param exception: exception
"""
driver = self.args[0].testui_driver
config: Configuration = driver.configuration

Expand All @@ -145,7 +188,8 @@ def __show_error(self, exception) -> None:

def ee(*args) -> Collections:
"""
locator types:
Create collection of elements
Available locator types:
id,
css,
className,
Expand All @@ -155,5 +199,7 @@ def ee(*args) -> Collections:
uiautomator,
classChain,
predicate
:param args: list of elements
:return: collection of elements
"""
return Collections(args)
Loading