luizyao / pytest-pyppeteer Goto Github PK
View Code? Open in Web Editor NEWA plugin to run pyppeteer in pytest.
License: MIT License
A plugin to run pyppeteer in pytest.
License: MIT License
occur error on python 3.7.6
pyee_compat.py:35: DeprecationWarning: pyee.EventEmitter is deprecated and will be removed in a future major version; you should instead use either pyee.AsyncIOEventEmitter, pyee.TwistedEventEmitter, pyee.ExecutorEventEmitter, pyee.TrioEventEmitter, or pyee.BaseEventEmitter.
All target function query element by selector:
For example:
async def get_value(
self,
elem_name: str,
custom_parameter: tuple = (),
timeout: Union[float, int] = 30000,
) -> str:
"""Get value with an element which matches ``elem_name``.
This method raises error if no element matched the ``elem_name``.
:param elem_name: Element name.
:param custom_parameter: The values used to replace "{}" in the locator.
:param timeout: Maximum time to wait for searching element in milliseconds.
Defaults to 30000 (30 seconds). Pass ``0`` to disable timeout.
:return:
"""
await self.wait_for_element(
elem_name, visible=True, timeout=timeout, custom_parameter=custom_parameter
)
locator: str = self._get_element_locator(elem_name, custom_parameter)
value: str = await self.tab.querySelectorEval(
locator, "(node => node.value || node.innerText)"
)
return value.strip()
But we can use xpath in desc
file:
@classmethod
def validate(cls, value: str) -> str:
"""Locator string must a valid css or xpath.
:param value: a locator string
:return:
"""
if not isinstance(value, str):
raise TypeError("Invalid parameter type, string required.")
if "{}" in value:
return cls(
value
) # TODO: Custom parameters need to be dynamically populated in use
# CSS
try:
cssselect.parse(value)
except cssselect.SelectorSyntaxError:
pass
else:
return cls(value)
# XPath
try:
etree.XPath(value)
except etree.XPathSyntaxError:
pass
else:
return cls(value)
raise ValueError("Invalid parameter format, neither a valid css nor xpath.")
install_requires=[
"pyppeteer==0.2.2",
"pytest-asyncio==0.14.0",
"pytest==6.0.2",
"pydantic==1.6.1",
"cssselect==1.1.0",
"lxml==4.5.2",
],
When i perform a setup for target, i want to record some info on target for later use.
e.g.
await target.get_values('elem_name')
return a list contains each value.
Like target.get_value(element)
, i want to get attribute from an element, such as target.get_attribute(element, 'class')
like pytest_pyppeteer_all_targets_teardown
hook function, i want to setup all targets before execute all test items. e.g. add allure environment parameters
Popup a el-dialog
when you click a button, but it's failed to popup now. actually element has been found successful.
When add a waiting time between found and click operator, popup successful:
if isinstance(element, str):
element: ElementHandle = await self.query_element(
element,
visible=True,
timeout=timeout,
custom_parameter=custom_parameter,
)
await asyncio.sleep(1)
await element.click(clickCount=click_count, button=button, delay=delay)
if dispose:
await element.dispose()
Use this
# Get the first result
await target.click("result", custom_parameter=1)
instead of
# Get the first result
await target.click("result", custom_parameter=(1,))
Format idea, CHANGES
# Changelog
## pytest-pyppeteer 0.3.1 - unreleased
- _Insert changes/features/fixes for next release here_
### Maintenance
- #32: docs: Add project description
## pytest-pyppeteer 0.3.0 (2022-01-27)
### Packaging
- Remove `Pipfile.lock`
### What's new
- Upgrade pyppeteer 0.2.3 -> 0.2.5 (#23)
### Documentation
- Document `--slow`
## pytest-pyppeteer 0.2.1 (2020-10-16)
<!---
# vim: set filetype=markdown:
-->
Then if you like #33
[tool.poetry.urls]
# ... the rest
Changes = "https://github.com/luizyao/pytest-pyppeteer/blob/master/CHANGES"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.