Skip to content

Commit

Permalink
feat: add initial integration of playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
rgonalo committed May 14, 2024
1 parent 1cee00e commit 7a663f5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
31 changes: 28 additions & 3 deletions toolium/behave/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
32 changes: 32 additions & 0 deletions toolium/pageobjects/playwright_page_object.py
Original file line number Diff line number Diff line change
@@ -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__()

0 comments on commit 7a663f5

Please sign in to comment.