Skip to content

Commit df7542b

Browse files
authored
Merge pull request #31 from LambdaTest/stage
Release lambdatest-playwright-driver support
2 parents a2a85b7 + 75b198d commit df7542b

File tree

16 files changed

+215
-14
lines changed

16 files changed

+215
-14
lines changed

.github/workflows/publish.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
options:
1111
- lambdatest-utils
1212
- lambdatest-selenium-driver
13+
- lambdatest-playwright-driver
1314
default: 'lambdatest-utils'
1415

1516
jobs:
@@ -44,4 +45,13 @@ jobs:
4445
run: |
4546
cd selenium
4647
python setup.py sdist bdist_wheel
48+
twine upload dist/*
49+
- name: Build and publish lambdatest-playwright-driver
50+
if: github.event.inputs.package-name == 'lambdatest-playwright-driver'
51+
env:
52+
TWINE_USERNAME: __token__
53+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
54+
run: |
55+
cd playwright
56+
python setup.py sdist bdist_wheel
4757
twine upload dist/*
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from lambdatest_playwright_driver.version import __version__
2+
from lambdatest_playwright_driver.smartui import smartui_snapshot
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from lambdatest_sdk_utils import is_smartui_enabled, fetch_dom_serializer, post_snapshot # type: ignore
2+
from lambdatest_sdk_utils import setup_logger, get_logger # type: ignore
3+
from playwright.async_api import Page # type: ignore
4+
5+
def smartui_snapshot(page: Page, name: str, options={}):
6+
# setting up logger
7+
setup_logger()
8+
logger = get_logger('lambdatest-playwright-driver')
9+
10+
11+
if not page:
12+
raise ValueError('A Playwright `page` object is required.')
13+
if not name:
14+
raise ValueError('The `snapshotName` argument is required.')
15+
if is_smartui_enabled() is False:
16+
raise Exception("Cannot find SmartUI server.")
17+
18+
try:
19+
resp = fetch_dom_serializer()
20+
page.evaluate(resp['data']['dom'])
21+
22+
dom = dict()
23+
dom['name'] = name
24+
dom['url'] = page.url
25+
dom['dom'] = page.evaluate("([options]) => SmartUIDOM.serialize(options)",[options])
26+
27+
res = post_snapshot(dom, 'lambdatest-playwright-driver', options=options)
28+
29+
if res and res.get('data') and res['data'].get('warnings') and len(res['data']['warnings']) != 0:
30+
for warning in res['data']['warnings']:
31+
logger.warning(warning)
32+
33+
logger.info(f'Snapshot captured {name}')
34+
except Exception as e:
35+
logger.error(f"SmartUI snapshot failed '{name}'")
36+
logger.error(e)
37+
38+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = '1.0.0'

playwright/readme.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# lambdatest-playwright-driver
2+
[![SmartUI-Testing](https://smartui.lambdatest.com/static/media/LTBadge.64a05e73.svg)](https://smartui.lambdatest.com)
3+
4+
SmartUI SDK for python playwright
5+
- [Installation](#installation)
6+
- [Methods](#methods)
7+
- [Usage](#usage)
8+
9+
## Installation
10+
11+
Install Smart UI cli
12+
13+
```sh-session
14+
$ npm install -g @lambdatest/smartui-cli
15+
```
16+
17+
Install Python Playwright Package
18+
19+
```sh-session
20+
$ pip3 install lambdatest-playwright-driver
21+
```
22+
23+
## Methods
24+
``` python
25+
smartui_snapshot(page,"snapshotName")
26+
```
27+
28+
- `page` (**required**) - A page object instance from playwright is required.
29+
- `snapshotName` (**required**) - Name of the screenshot
30+
31+
## Usage
32+
33+
Example playwright test using `smartui_snapshot`
34+
35+
``` python
36+
from playwright.sync_api import sync_playwright, Playwright
37+
from lambdatest_playwright_driver import smartui_snapshot
38+
39+
def run(playwright: Playwright):
40+
webkit = playwright.webkit
41+
browser = webkit.launch()
42+
context = browser.new_context()
43+
page = context.new_page()
44+
45+
try:
46+
page.goto("https://www.lambdatest.com")
47+
smartui_snapshot(page, "example_snapshot", options={})
48+
except Exception as e:
49+
print(f"Error occurred during SmartUI snapshot: {e}")
50+
finally:
51+
browser.close()
52+
53+
with sync_playwright() as playwright:
54+
run(playwright)
55+
```
56+
57+
58+
Copy the project token from [SmartUI Dashboard](https://smartui.lambdatest.com/) and set on CLI via comman
59+
<b>For Linux/macOS:</b>
60+
61+
```sh-session
62+
export PROJECT_TOKEN="****-****-****-************"
63+
```
64+
65+
<b>For Windows:</b>
66+
67+
```sh-session
68+
set PROJECT_TOKEN="****-****-****-************"
69+
```
70+
71+
Running test
72+
```sh-session
73+
$ npx smartui exec [python test command]
74+
```
75+
This will create new build and upload snapshot to Smart UI Project.
76+
77+
Executing above test
78+
79+
```sh-session
80+
$ npx smartui exec python test.py
81+
✔ Authenticated with SmartUI
82+
→ using project token '******#ihcjks'
83+
✔ SmartUI started
84+
→ listening on port 8080
85+
✔ Fetched git information
86+
→ branch: main, commit: 7e336e6, author: Sushobhit Dua
87+
✔ SmartUI build created
88+
→ build id: ee2cb6c5-9541-494a-9c75-a74629396b80
89+
✔ Execution of 'python3 test.py' completed; exited with code 0
90+
→ INFO:@lambdatest/python-selenium-driver:Snapshot captured name
91+
✔ Finalized build
92+
93+
```
94+
95+
## Contribute
96+
97+
#### Reporting bugs
98+
99+
Our GitHub Issue Tracker will help you log bug reports.
100+
101+
Tips for submitting an issue:
102+
Keep in mind, you don't end up submitting two issues with the same information. Make sure you add a unique input in every issue that you submit. You could also provide a "+1" value in the comments.
103+
104+
Always provide the steps to reproduce before you submit a bug.
105+
Provide the environment details where you received the issue i.e. Browser Name, Browser Version, Operating System, Screen Resolution and more.
106+
Describe the situation that led to your encounter with bug.
107+
Describe the expected output, and the actual output precisely.
108+
109+
#### Pull Requests
110+
111+
We don't want to pull breaks in case you want to customize your LambdaTest experience. Before you proceed with implementing pull requests, keep in mind the following.
112+
Make sure you stick to coding conventions.
113+
Once you include tests, ensure that they all pass.
114+
Make sure to clean up your Git history, prior your submission of a pull-request. You can do so by using the interactive rebase command for committing and squashing, simultaneously with minor changes + fixes into the corresponding commits.
115+
116+
## About LambdaTest
117+
118+
[LambdaTest](https://www.lambdatest.com/) is a cloud based selenium grid infrastructure that can help you run automated cross browser compatibility tests on 2000+ different browser and operating system environments. LambdaTest supports all programming languages and frameworks that are supported with Selenium, and have easy integrations with all popular CI/CD platforms. It's a perfect solution to bring your [selenium automation testing](https://www.lambdatest.com/selenium-automation) to cloud based infrastructure that not only helps you increase your test coverage over multiple desktop and mobile browsers, but also allows you to cut down your test execution time by running tests on parallel.

playwright/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
playwright==1.30.0
2+
aiohttp==3.8.1
3+
lambdatest-sdk-utils==1.*

playwright/setup.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from setuptools import setup, find_packages
2+
from os import path
3+
4+
cwd = path.abspath(path.dirname(__file__))
5+
with open(path.join(cwd, 'README.md'), encoding='utf-8') as f:
6+
long_description = f.read()
7+
8+
setup(
9+
name="lambdatest-playwright-driver",
10+
version="1.0.0",
11+
author="LambdaTest <[email protected]>",
12+
description="Python Playwright SDK for visual testing with Smart UI",
13+
long_description=long_description,
14+
long_description_content_type="text/markdown",
15+
url="https://github.com/LambdaTest/lambdatest-python-sdk",
16+
keywords="lambdatest python playwright sdk visual testing",
17+
packages=find_packages(),
18+
license="MIT",
19+
install_requires=[
20+
"playwright>=1.12",
21+
"lambdatest-sdk-utils",
22+
],
23+
python_requires='>=3.7', # Playwright requires Python 3.7 or newer
24+
classifiers=[
25+
"Development Status :: 5 - Production/Stable",
26+
"Programming Language :: Python :: 3",
27+
"Natural Language :: English",
28+
"License :: OSI Approved :: MIT License",
29+
"Topic :: Software Development :: Testing",
30+
],
31+
)

selenium/lambdatest_selenium_driver/smartui.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import json
22
from lambdatest_sdk_utils import is_smartui_enabled,fetch_dom_serializer,post_snapshot
3-
from lambdatest_sdk_utils import get_pkg_name,setup_logger,get_logger
3+
from lambdatest_sdk_utils import setup_logger,get_logger
44

55

66
def smartui_snapshot(driver, name,options={}):
77
# setting up logger
88
setup_logger()
9-
logger = get_logger()
9+
logger = get_logger('lambdatest-selenium-driver')
1010

1111
if not name:
1212
raise Exception('The `snapshotName` argument is required.')
@@ -29,7 +29,7 @@ def smartui_snapshot(driver, name,options={}):
2929

3030
# Post the dom to smartui endpoint
3131
dom['name'] = name
32-
res = post_snapshot(dom,get_pkg_name(),options=options)
32+
res = post_snapshot(dom,'lambdatest-selenium-driver',options=options)
3333

3434
if res and res.get('data') and res['data'].get('warnings') and len(res['data']['warnings']) != 0:
3535
for warning in res['data']['warnings']:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.0.3'
1+
__version__ = '1.0.4'

selenium/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name="lambdatest-selenium-driver",
10-
version="1.0.3",
10+
version="1.0.4",
1111
author="LambdaTest <[email protected]>",
1212
description="Python Selenium SDK for testing with Smart UI",
1313
long_description=long_description,

0 commit comments

Comments
 (0)