Skip to content
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

feat: support playwright tests #390

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ v3.1.5
*Release date: In development*

- Fix `export_poeditor_project` method allowing empty export response
- Add `key=value` expressions for selecting elements in the context storage
- Upgrade Faker version to 25.9.*
- Fix result for action before the feature with error and background to fail scenarios

v3.1.4
------
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.5.dev0
3.2.0.dev0
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
requests~=2.27 # api tests
selenium~=4.0 # web tests
playwright~=1.43 # web tests
Appium-Python-Client~=2.3 # mobile tests
Pillow~=10.1 # visual testing
screeninfo~=0.8
lxml~=5.1
Faker~=18.3
Faker~=25.9
phonenumbers~=8.13
17 changes: 15 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,21 @@ def get_long_description():
setup(
name='toolium',
version=read_file('VERSION').strip(),
packages=['toolium', 'toolium.pageobjects', 'toolium.pageelements', 'toolium.behave', 'toolium.utils'],
package_data={'': ['resources/VisualTestsTemplate.html', 'resources/VisualTests.js', 'resources/VisualTests.css']},
packages=[
'toolium',
'toolium.pageobjects',
'toolium.pageelements',
'toolium.pageelements.playwright',
'toolium.behave',
'toolium.utils',
],
package_data={
'': [
'resources/VisualTestsTemplate.html',
'resources/VisualTests.js',
'resources/VisualTests.css',
]
},
install_requires=read_file('requirements.txt').splitlines(),
setup_requires=['pytest-runner'],
tests_require=read_file('requirements_dev.txt').splitlines(),
Expand Down
19 changes: 13 additions & 6 deletions toolium/behave/env_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def execute_after_scenario_steps(self, context):
self.scenario_error = False
self.before_error_message = None
context.scenario.reset()
self.fail_first_step_precondition_exception(context.scenario)
self.fail_first_step_precondition_exception(context.scenario, error_message)
raise Exception(f'Before scenario steps have failed: {error_message}')

def execute_after_feature_steps(self, context):
Expand All @@ -298,18 +298,25 @@ def execute_after_feature_steps(self, context):
context.feature.reset()
for scenario in context.feature.walk_scenarios():
if scenario.should_run(context.config):
self.fail_first_step_precondition_exception(scenario)
self.fail_first_step_precondition_exception(scenario, error_message)
if len(scenario.background_steps) > 0:
context.logger.warn('Background from scenario status udpated to fail')
raise Exception(f'Before feature steps have failed: {error_message}')

def fail_first_step_precondition_exception(self, scenario):
def fail_first_step_precondition_exception(self, scenario, error_message):
"""
Fail first step in the given Scenario and add exception message for the output.
This is needed because xUnit exporter in Behave fails if there are not failed steps.
:param scenario: Behave's Scenario
:param error_message: Exception message
"""
# Behave is an optional dependency in toolium, so it is imported here
from behave.model_core import Status
if len(scenario.steps) > 0:
# Behave is an optional dependency in toolium, so it is imported here
from behave.model_core import Status
scenario.steps[0].status = Status.failed
scenario.steps[0].exception = Exception('Preconditions failed')
scenario.steps[0].error_message = str(self.before_error_message)
scenario.steps[0].error_message = str(error_message)
if len(scenario.background_steps) > 0:
scenario.background_steps[0].status = Status.failed
scenario.background_steps[0].exception = Exception('Preconditions failed')
scenario.background_steps[0].error_message = str(error_message)
8 changes: 8 additions & 0 deletions toolium/behave/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import os
import re

from behave.api.async_step import use_or_create_async_context

from toolium.utils import dataset
from toolium.config_files import ConfigFiles
from toolium.driver_wrapper import DriverWrappersPool
Expand Down Expand Up @@ -154,6 +156,12 @@ def create_and_configure_wrapper(context):
# Configure wrapper
context.driver_wrapper.configure(context.config_files, behave_properties=behave_properties)

# Activate behave async context to execute playwright
if (context.driver_wrapper.config.get_optional('Driver', 'web_library') == 'playwright'
and context.driver_wrapper.async_loop is None):
use_or_create_async_context(context)
context.driver_wrapper.async_loop = context.async_context.loop

# Copy config object
context.toolium_config = context.driver_wrapper.config

Expand Down
Loading
Loading