diff --git a/VERSION b/VERSION index e94017a5..745e2a57 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1.5.dev0 +3.2.0.dev0 diff --git a/requirements.txt b/requirements.txt index 281ce90d..32034f00 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ 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 diff --git a/toolium/behave/environment.py b/toolium/behave/environment.py index b6f66f09..003597a6 100644 --- a/toolium/behave/environment.py +++ b/toolium/behave/environment.py @@ -20,6 +20,9 @@ import os import re +from behave.api.async_step import use_or_create_async_context +from playwright.async_api import async_playwright + from toolium.utils import dataset from toolium.config_files import ConfigFiles from toolium.driver_wrapper import DriverWrappersPool @@ -225,6 +228,12 @@ def after_scenario(context, scenario): DriverWrappersPool.close_drivers(scope='function', test_name=scenario.name, test_passed=scenario.status in ['passed', 'skipped'], context=context) + # Stop playwright + if context.toolium_config.get_optional('Driver', 'weblibrary') == 'playwright': + # TODO: reuse driver like in close_drivers + loop = context.async_context.loop + loop.run_until_complete(context.playwright.stop()) + # Save test status to be updated later if jira_test_status: add_jira_status(get_jira_key_from_scenario(scenario), jira_test_status, jira_test_comment) @@ -281,6 +290,22 @@ def start_driver(context, no_driver): :param context: behave context :param no_driver: True if this is an api test and driver should not be started """ - create_and_configure_wrapper(context) - if not no_driver: - connect_wrapper(context) + if context.toolium_config.get_optional('Driver', 'weblibrary') == 'playwright': + start_playwright(context) + else: + create_and_configure_wrapper(context) + if not no_driver: + connect_wrapper(context) + + +def start_playwright(context): + """Start playwright with configured values + + :param context: behave context + """ + use_or_create_async_context(context) + loop = context.async_context.loop + context.playwright = loop.run_until_complete(async_playwright().start()) + # TODO: select browser from config + context.browser = loop.run_until_complete(context.playwright.chromium.launch(headless=False)) + context.page = loop.run_until_complete(context.browser.new_page()) diff --git a/toolium/pageobjects/playwright_page_object.py b/toolium/pageobjects/playwright_page_object.py new file mode 100644 index 00000000..d4e33ea6 --- /dev/null +++ b/toolium/pageobjects/playwright_page_object.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +""" +Copyright 2024 Telefónica Innovación Digital, S.L. +This file is part of Toolium. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +from playwright.async_api import Page +from toolium.pageobjects.page_object import PageObject + + +class PlaywrightPageObject(PageObject): + """Class to represent a playwright web page""" + + def __init__(self, page: Page): + """Initialize page object properties + + :param page: playwright page instance + """ + self.page = page + super(PlaywrightPageObject, self).__init__()