Skip to content

Commit

Permalink
Workflows: update versions and remove useless code (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirPodolian authored Dec 26, 2024
1 parent c343058 commit a03302b
Show file tree
Hide file tree
Showing 309 changed files with 247 additions and 94 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/playwright_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
Expand All @@ -43,7 +43,6 @@ jobs:
run: |
echo "HOME=/root" >> $GITHUB_ENV # Set HOME environment variable
- name: Run Playwright ${{ matrix.browser-name }} on py${{ matrix.python-version }} tests
id: tests
- name: Run Playwright ${{ matrix.browser-name }} tests with py${{ matrix.python-version }}
run: |
tox -e py${{ env.TOX_ENV }}-playwright-${{ matrix.browser-name }} -- --headless -v --sv
38 changes: 38 additions & 0 deletions .github/workflows/selenium_safari_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Selenium Safari Tests

on:
push:
branches:
- '**' # Trigger on push to any branch

jobs:
selenium-safari:
runs-on: macos-13

strategy:
fail-fast: false
matrix:
python-version: [ "3.8", "3.12" ]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'

- name: Setup tests
run: |
python -m pip install --upgrade pip
pip install tox==3.28.0
- name: Extract tox env
run: |
tox_env_variable=$(echo "${{ matrix.python-version }}" | sed 's/\.//g')
echo "TOX_ENV=${tox_env_variable}" >> $GITHUB_ENV
- name: Run Selenium Safari tests with py${{ matrix.python-version }}
run: |
tox -e py${{ env.TOX_ENV }}-selenium-safari -- --headless -v -k='not screenshot' --reruns=2
33 changes: 22 additions & 11 deletions .github/workflows/selenium_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,45 @@ on:

jobs:
selenium-selenoid:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

strategy:
fail-fast: false
matrix:
image: [ "selenoid/chrome:128.0", "selenoid/firefox:125.0"]
python-version: [ "3.8", "3.12" ]

services:
selenoid:
image: selenoid/vnc:chrome_112.0
image: ${{ matrix.image }}
options: --privileged --memory=4g
ports:
- 4444:4444

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.8'

- name: Setup tests
run: |
python -m pip install --upgrade pip
pip install tox==3.28.0
mkdir -p allure-report
chmod -R 777 allure-report
sudo apt-get update
sudo apt-get install -y allure
- name: Extract tox env
run: |
tox_env_variable=$(echo "${{ matrix.python-version }}" | sed 's/\.//g')
echo "TOX_ENV=${tox_env_variable}" >> $GITHUB_ENV
- name: Extract Browser Name
run: |
browser_name=$(echo "${{ matrix.image }}" | sed -E 's|.*/([^:]+):.*|\1|')
echo "BROWSER=${browser_name}" >> $GITHUB_ENV
- name: Run Selenium tests
id: tests
- name: Run Selenium ${{ env.BROWSER }} tests with py${{ matrix.python-version }}
run: |
tox -e py38-selenium-chrome -- --env remote --headless -v --sv
tox -e py${{ env.TOX_ENV }}-selenium-${{ env.BROWSER }} -- --env remote --headless -v --reruns=2
4 changes: 2 additions & 2 deletions .github/workflows/static_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
static:
runs-on: ubuntu-latest #'windows-latest' / 'macos-latest'
runs-on: ubuntu-24.04

strategy:
fail-fast: false
Expand All @@ -33,6 +33,6 @@ jobs:
tox_env_variable=$(echo "${{ matrix.python-version }}" | sed 's/\.//g')
echo "TOX_ENV=${tox_env_variable}" >> $GITHUB_ENV
- name: Run Tox on ${{ matrix.python-version }}
- name: Run Static tests with ${{ matrix.python-version }}
run: |
tox -e py${{ env.TOX_ENV }}-static
36 changes: 28 additions & 8 deletions dyatel/abstraction/driver_wrapper_abc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from abc import ABC
from functools import cached_property
from typing import List, Union, Any, Tuple

from dyatel.mixins.objects.cut_box import CutBox
Expand Down Expand Up @@ -38,6 +39,33 @@ class DriverWrapperABC(ABC):

browser_name = None

@cached_property
def is_safari(self) -> bool:
"""
Returns the status of whether the current driver is Safari
:return: :class:`bool`
"""
raise NotImplementedError()

@cached_property
def is_chrome(self) -> bool:
"""
Returns the status of whether the current driver is Chrome
:return: :class:`bool`
"""
raise NotImplementedError()

@cached_property
def is_firefox(self) -> bool:
"""
Returns the status of whether the current driver is Firefox
:return: :class:`bool`
"""
raise NotImplementedError()

def quit(self, silent: bool = False, trace_path: str = 'trace.zip'):
"""
Quit the driver instance
Expand Down Expand Up @@ -173,14 +201,6 @@ def switch_to_frame(self, frame: Any) -> DriverWrapperABC:
"""
raise NotImplementedError()

def switch_to_parent_frame(self) -> DriverWrapperABC:
"""
Appium/Selenium only: Switch to parent frame from child frame
:return: self
"""
raise NotImplementedError()

def switch_to_default_content(self) -> DriverWrapperABC:
"""
Appium/Selenium only: Switch to default content from frame
Expand Down
28 changes: 28 additions & 0 deletions dyatel/base/driver_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from functools import cached_property
from typing import Union, Type, List, Tuple, Any, Optional

from PIL import Image
Expand Down Expand Up @@ -154,6 +155,33 @@ def __init__(
self.is_desktop = False
self.is_mobile = True

@cached_property
def is_safari(self) -> bool:
"""
Returns the status of whether the current driver is Safari
:return: :class:`bool`
"""
return self.browser_name.lower() == 'safari'

@cached_property
def is_chrome(self) -> bool:
"""
Returns the status of whether the current driver is Chrome
:return: :class:`bool`
"""
return self.browser_name.lower() == 'chrome'

@cached_property
def is_firefox(self) -> bool:
"""
Returns the status of whether the current driver is Firefox
:return: :class:`bool`
"""
return self.browser_name.lower() == 'firefox'

def quit(self, silent: bool = False, trace_path: str = 'trace.zip'):
"""
Quit the driver instance
Expand Down
3 changes: 1 addition & 2 deletions dyatel/dyatel_play/play_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ def text(self) -> str:
:return: element text
"""
element = self._first_element
return element.text_content() if element.text_content() else element.input_value()
return self.inner_text

@property
def inner_text(self) -> str:
Expand Down
9 changes: 0 additions & 9 deletions dyatel/dyatel_sel/core/core_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,6 @@ def switch_to_frame(self, frame: Any) -> CoreDriver:
self.driver.switch_to.frame(frame.element)
return self

def switch_to_parent_frame(self) -> CoreDriver:
"""
Switch to parent frame from child frame
:return: self
"""
self.driver.switch_to.parent_frame()
return self

def switch_to_default_content(self) -> CoreDriver:
"""
Switch to default content from frame
Expand Down
14 changes: 12 additions & 2 deletions dyatel/dyatel_sel/core/core_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from dyatel.abstraction.element_abc import ElementABC
from dyatel.dyatel_sel.sel_utils import ActionChains
from dyatel.js_scripts import get_element_size_js, get_element_position_on_screen_js
from dyatel.js_scripts import get_element_size_js, get_element_position_on_screen_js, js_click
from dyatel.keyboard_keys import KeyboardKeys
from dyatel.mixins.objects.location import Location
from dyatel.mixins.objects.scrolls import ScrollTo, ScrollTypes, scroll_into_view_blocks
Expand Down Expand Up @@ -102,7 +102,13 @@ def click(self, force_wait: bool = True, *args, **kwargs) -> CoreElement:
start_time = time.time()
while time.time() - start_time < HALF_WAIT_EL:
try:
self.wait_enabled(silent=True).element.click()
element = self.wait_enabled(silent=True).element

if self.driver_wrapper.is_safari:
self.execute_script(js_click)
else:
element.click()

return self
except (
SeleniumElementNotInteractableException,
Expand Down Expand Up @@ -358,6 +364,10 @@ def text(self) -> str:
:return: element text
"""
element = self._get_element(wait=self.wait_availability)

if self.driver_wrapper.is_safari:
return element.get_attribute('innerText')

return element.text

@property
Expand Down
10 changes: 6 additions & 4 deletions dyatel/js_scripts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
get_inner_height_js = 'return window.innerHeight'
get_inner_width_js = 'return window.innerWidth'
js_click = 'arguments[0].click();'

get_element_position_on_screen_js = """
function getPositionOnScreen(elem) {
Expand Down Expand Up @@ -46,15 +47,16 @@
dyatel_obj.style.zIndex=9999999;
dyatel_obj.setAttribute("class","dyatel-visual-comparison-support-element");
document.body.appendChild(dyatel_obj);
dyatel_obj.style.position = "fixed";
dyatel_obj.style.position = "absolute";
dyatel_obj.style.backgroundColor = "#000";
dyatel_obj.style.width = given_obj.width + "px";
dyatel_obj.style.height = given_obj.height + "px";
dyatel_obj.style.top = given_obj.y + "px";
dyatel_obj.style.left = given_obj.x + "px";
dyatel_obj.style.top = (given_obj.top + window.scrollY) + "px";
dyatel_obj.style.left = (given_obj.left + window.scrollX) + "px";
document.body.appendChild(dyatel_obj);
};
return appendElement(arguments[0]);
Expand Down
9 changes: 6 additions & 3 deletions dyatel/visual_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import re
import shutil
import time
import math
import json
Expand Down Expand Up @@ -167,7 +168,9 @@ def assert_screenshot(
self._assert_same_images(output_file, reference_file, diff_file, threshold)
except AssertionError as exc:
if self.soft_visual_reference_generation:
self._save_screenshot(reference_file, **screenshot_params)
if os.path.exists(reference_file):
os.remove(reference_file)
shutil.move(output_file, reference_file)
else:
raise exc

Expand Down Expand Up @@ -201,12 +204,12 @@ def _appends_dummy_elements(self, remove_data: list) -> VisualComparison:
for obj in remove_data:

try:
obj.wait_visibility()
obj.wait_visibility(silent=True)
except TimeoutException:
msg = f'Cannot find {obj.name} while removing background from screenshot. {get_element_info(obj)}'
raise TimeoutException(msg)

self.driver_wrapper.execute_script(add_element_over_js, obj)
obj.execute_script(add_element_over_js)
return self

def _remove_dummy_elements(self) -> VisualComparison:
Expand Down
20 changes: 15 additions & 5 deletions tests/adata/drivers/selenium_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,26 @@ class SeleniumDriver:
@staticmethod
def create_selenium_driver(entities: DriverEntities):
driver_name = entities.driver_name
if driver_name == 'safari' and DriverWrapperSessions.is_connected():
driver_name = 'chrome' # Cannot create second selenium driver
options = None
remote_url = "http://127.0.0.1:4444"

if driver_name == 'safari':
if DriverWrapperSessions.is_connected():
driver_name = 'chrome' # Cannot create second selenium driver
elif driver_name == 'chrome':
options = entities.selenium_chrome_options
elif driver_name == 'firefox':
options = entities.selenium_firefox_options
remote_url += '/wd/hub'
else:
raise Exception('Unknown driver: %s' % driver_name)

if entities.env == 'remote':
driver = Remote(options=entities.selenium_chrome_options)
driver = Remote(remote_url, options=options)
elif driver_name == 'chrome':
driver = ChromeWebDriver(options=entities.selenium_chrome_options, service=ChromeService())
driver = ChromeWebDriver(options=options, service=ChromeService())
elif driver_name == 'firefox':
driver = GeckoWebDriver(options=entities.selenium_firefox_options, service=FirefoxService())
driver = GeckoWebDriver(options=options, service=FirefoxService())
elif driver_name == 'safari':
driver = SafariWebDriver(service=SafariService())
else:
Expand Down
Loading

0 comments on commit a03302b

Please sign in to comment.