pywright-cucumber/features/environment.py

66 lines
1.5 KiB
Python
Raw Normal View History

2024-07-24 20:25:00 +00:00
# pylint: disable=no-name-in-module,unused-argument,comparison-of-constants
import os
from datetime import datetime
import logging
from playwright.sync_api import sync_playwright
def before_all(context):
p = sync_playwright().start()
browser = p.chromium.launch(headless=True, slow_mo=1000, channel="chrome")
context.page = browser.new_page()
def get_page(context):
return context.page
def after_all(context):
context.page.close()
def before_feature(context, feature):
"""
Method will execute prior to each feature
:param context:
:param feature:
:return:
"""
# Create logger
context.logger = logging.getLogger('automation_tests')
context.logger.setLevel(logging.DEBUG)
def after_feature(context, feature):
"""
Method will execute after each feature
:param context:
:param feature:
:return:
"""
def before_scenario(context, scenario):
"""
:param context:
:param scenario:
:return:
"""
def after_scenario(context, scenario):
if scenario.status == 'failed':
timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
screenshot_path = os.path.join('screenshots', f'{scenario.name}_{timestamp}', '.png')
context.page.screenshot(path=screenshot_path)
def before_step(context, step):
# run before each step
pass
def after_step(context, step):
# run after each step
pass