Skip to content
Merged
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
21 changes: 17 additions & 4 deletions selenium/lambdatest_selenium_driver/smartui.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
from lambdatest_sdk_utils import is_smartui_enabled,fetch_dom_serializer,post_snapshot
from lambdatest_sdk_utils import get_pkg_name,setup_logger,get_logger


def smartui_snapshot(driver, name,**kwargs):
def smartui_snapshot(driver, name,options={}):
# setting up logger
setup_logger()
logger = get_logger()
Expand All @@ -11,16 +12,28 @@ def smartui_snapshot(driver, name,**kwargs):
if not name:
raise Exception('The `snapshotName` argument is required.')
if is_smartui_enabled() is False:
raise Exception("SmartUI server is not running.")
raise Exception("Cannot find SmartUI server.")

resp = fetch_dom_serializer()
driver.execute_script(resp['data']['dom'])

# Serialize and capture the DOM
dom = driver.execute_script("return {'dom':SmartUIDOM.serialize()}")
dom = driver.execute_script(
f"""
return {{
dom: SmartUIDOM.serialize({json.dumps(options)}),
url: document.URL
}}
"""
)

# Post the dom to smartui endpoint
post_snapshot(dom,name,get_pkg_name())
dom['name'] = name
res = post_snapshot(dom,get_pkg_name(),options=options)

if res and res.get('data') and res['data'].get('warnings') and len(res['data']['warnings']) != 0:
for warning in res['data']['warnings']:
logger.warn(warning)

logger.info(f'Snapshot captured {name}')
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion selenium/lambdatest_selenium_driver/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.1'
__version__ = '1.0.2'
4 changes: 2 additions & 2 deletions selenium/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="lambdatest-selenium-driver",
version="1.0.1",
version="1.0.2",
author="LambdaTest <keys@lambdatest.com>",
description="Python Selenium SDK for testing with Smart UI",
long_description=long_description,
Expand All @@ -18,7 +18,7 @@
license="MIT",
install_requires=[
"selenium>=3",
"lambdatest-sdk-utils==1.*"
"lambdatest-sdk-utils"
],
python_requires='>=3.6',
classifiers=[
Expand Down
4 changes: 3 additions & 1 deletion utils/lambdatest_sdk_utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os

def get_smart_ui_server_address():
return os.getenv('SMARTUI_SERVER_ADDRESS', 'http://localhost:8080')
if not os.getenv('SMARTUI_SERVER_ADDRESS'):
raise Exception('SmartUI server address not found')
return os.getenv('SMARTUI_SERVER_ADDRESS')

def get_pkg_name():
return "@lambdatest/python-selenium-driver"
16 changes: 8 additions & 8 deletions utils/lambdatest_sdk_utils/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

logger = get_logger()

SMART_UI_API = get_smart_ui_server_address()

def is_smartui_enabled():
try:
response = requests.get(f'{SMART_UI_API}/healthcheck')
response = requests.get(f'{get_smart_ui_server_address()}/healthcheck')
response.raise_for_status()
return True
except Exception as e:
Expand All @@ -17,7 +15,7 @@ def is_smartui_enabled():

def fetch_dom_serializer():
try:
response = requests.get(f'{SMART_UI_API}/domserializer')
response = requests.get(f'{get_smart_ui_server_address()}/domserializer')
response.raise_for_status()
return response.json()
except requests.exceptions.HTTPError as e:
Expand All @@ -30,12 +28,14 @@ def fetch_dom_serializer():
raise Exception(f'fetch DOMSerializer failed')


def post_snapshot(dom,snaphshotname,pkg):
def post_snapshot(snapshot,pkg,**kwargs):
try:
response = requests.post(f'{SMART_UI_API}/snapshot', json={
response = requests.post(f'{get_smart_ui_server_address()}/snapshot', json={
'snapshot': {
'dom' : dom['dom']['html'],
'name' : snaphshotname
'dom' : snapshot['dom'],
'name' : snapshot['name'],
'url' : snapshot['url'],
**kwargs
},
'testType': pkg
})
Expand Down
2 changes: 1 addition & 1 deletion utils/lambdatest_sdk_utils/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.0'
__version__ = '1.0.1'
2 changes: 1 addition & 1 deletion utils/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="lambdatest-sdk-utils",
version="1.0.0",
version="1.0.1",
author="LambdaTest <keys@lambdatest.com>",
description="SDK utils",
long_description="SDK utils for lambdatest",
Expand Down