PyPOM is a Python Page Object Model library for Selenium and Splinter tests.
mozilla / pypom Goto Github PK
View Code? Open in Web Editor NEWPython page object model for Selenium
License: Other
Python page object model for Selenium
License: Other
Currently, there is confirmed support only for python 2.7 and 3.6.
What about python 3.7 ?
If you install pypom 1.1.0 you get an import error:
Type "help", "copyright", "credits" or "license" for more information.
>>> import pypom
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-x86_64/egg/pypom/__init__.py", line 1, in <module>
File "build/bdist.linux-x86_64/egg/pypom/page.py", line 8, in <module>
File "build/bdist.linux-x86_64/egg/pypom/view.py", line 7, in <module>
ImportError: No module named interfaces
Hi,
Am using the below code provided in the documentation am getting the following error when I ran it. How to resolve this issue.
# mozilla.py
from pypom import Page, Region
from splinter import Browser
executable_path = {'executable_path':'C:/Users/tester/.webdrivers/chromedriver.exe'}
class Mozilla(Page):
URL_TEMPLATE = 'https://www.mozilla.org/'
@property
def newsletter(self):
return Newsletter(self)
class Newsletter(Region):
_root_locator = ('id', 'newsletter-form')
_submit_locator = ('id', 'footer_email_submit')
def sign_up(self):
self.find_element(*self._submit_locator).click()
driver = Browser('chrome', **executable_path)
page = Mozilla(driver).open()
page.newsletter.sign_up()
Traceback (most recent call last):
File "mozilla.py", line 22, in <module>
page.newsletter.sign_up()
File "mozilla.py", line 11, in newsletter
return Newsletter(self)
NameError: name 'Newsletter' is not defined
Hi!
pluggy v0.7.1 has deprecated the implprefix
argument:
Treeherder marks warnings as errors, which causes the following failures from PyPOM:
DeprecationWarning: Support for the `implprefix` arg is now deprecated and
will be removed in an upcoming release. Please use HookimplMarker.
(Full log: https://travis-ci.org/mozilla/treeherder/jobs/409417404#L901)
The usage within PyPOM is here:
Line 20 in 697ae6a
We can temporarily ignore this DeprecationWarning
via pytest's filterwarnings
, however it would be good to fix upstream at some point.
As of January 1 2019, Mozilla requires that all GitHub projects include this CODE_OF_CONDUCT.md file in the project root. The file has two parts:
If you have any questions about this file, or Code of Conduct policies and procedures, please see Mozilla-GitHub-Standards or email [email protected].
(Message COC001)
I would like to use Selenium driver with event firing support, but PyPOM seems to fail at initialization with such configuration:
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.support.events import EventFiringWebDriver, \
AbstractEventListener
from pypom import Page
class Qwant(Page):
_search_input_locator = (By.XPATH, '//input[@name="q"]')
def wait_for_page_to_load(self):
search_input = self.find_element(*self._search_input_locator)
self.wait.until(lambda _: search_input.is_enabled())
class ExceptionListener(AbstractEventListener):
def on_exception(self, exc, driver):
driver.get_screenshot_as_file('exception.png')
def main():
driver = Chrome()
ef_driver = EventFiringWebDriver(driver, ExceptionListener())
page = Qwant(ef_driver, base_url='https://www.qwant.com/')
page.open()
if __name__ == '__main__':
main()
Here's the resulting traceback:
Traceback (most recent call last):
File "PyPOM_EventFiringWebDriver.py", line 30, in <module>
main()
File "PyPOM_EventFiringWebDriver.py", line 26, in main
Qwant(ef_driver, base_url='https://www.qwant.com/')
File "/home/damienlebourdonnec/.virtualenvs/tmp-41cf2100534a6a0/local/lib/python2.7/site-packages/pypom/page.py", line 72, in __init__
super(Page, self).__init__(driver, timeout)
File "/home/damienlebourdonnec/.virtualenvs/tmp-41cf2100534a6a0/local/lib/python2.7/site-packages/pypom/view.py", line 14, in __init__
self.driver_adapter = IDriver(driver)
File "/home/damienlebourdonnec/.virtualenvs/tmp-41cf2100534a6a0/local/lib/python2.7/site-packages/zope/component/hookable.py", line 33, in __call__
return self.__implementation(*args, **kw)
File "/home/damienlebourdonnec/.virtualenvs/tmp-41cf2100534a6a0/local/lib/python2.7/site-packages/zope/component/_api.py", line 156, in adapter_hook
return sitemanager.queryAdapter(object, interface, name, default)
File "/home/damienlebourdonnec/.virtualenvs/tmp-41cf2100534a6a0/local/lib/python2.7/site-packages/zope/interface/registry.py", line 348, in queryAdapter
return self.adapters.queryAdapter(object, interface, name, default)
File "/home/damienlebourdonnec/.virtualenvs/tmp-41cf2100534a6a0/local/lib/python2.7/site-packages/zope/interface/adapter.py", line 539, in _uncached_lookup
order)
File "/home/damienlebourdonnec/.virtualenvs/tmp-41cf2100534a6a0/local/lib/python2.7/site-packages/zope/interface/adapter.py", line 672, in _lookup
for spec in specs[i].__sro__:
AttributeError: 'function' object has no attribute '__sro__'
Is there a trick to support EventFiringWebDriver like a normal Selenium Driver ?
Thx
Hi!
Currently the deprecation warning here doesn't set a stacklevel
:
Line 29 in 9cbbb36
So results in:
@property
def selenium(self):
"""Backwards compatibility attribute"""
> warn('use driver instead', DeprecationWarning)
E DeprecationWarning: use driver instead
(For example: https://travis-ci.org/mozilla/treeherder/jobs/364313209#L736)
If the warn()
also passed stacklevel=2
, then it would show the caller instead, making it easier to know where to fix.
Many thanks :-)
I am following the example Repeating Regions in order to fill a repeated region in a page:
from pypom import Page, Region
from selenium.webdriver.common.by import By
class Results(Page):
_result_locator = (By.CLASS_NAME, 'result')
@property
def results(self):
results = self.find_elements(*self._result_locator)
return [self.Result(el) for el in results]
class Result(Region):
_name_locator = (By.CLASS_NAME, 'name')
@property
def name(self):
return self.find_element(*self._name_locator).text
but end up in this error:
def __init__(self, page, root=None):
> super(Region, self).__init__(page.driver, page.timeout)
E AttributeError: 'WebElement' object has no attribute 'driver'
This is because in the list comprehension that creates the individual region instances a WebElement
is passed to the initializer.
Is this a documentation issue?
First of all thanks for the great library to share, but I am facing the minor issue by using XPATH locator within Region.
When using XPATH locator in the Region class, over there its giving me the first element found with that XPATH throughout the page, instead it should provide me the element found with that XPATH specific to that Region.
here is what I tried
result.html
<ol>
<li class="result">
<span class="name">Result 1</span>
<a href="./detail/1/">detail</a>
</li>
<li class="result">
<span class="name">Result 2</span>
<a href="./detail/2/">detail</a>
</li>
<li class="result">
<span class="name">Result 3</span>
<a href="./detail/3/">detail</a>
</li>
<li class="result">
<span class="name">Result 4</span>
<a href="./detail/4/">detail</a>
</li>
</ol>
results_page.py
class Results(Page):
_result_locator = (By.CLASS_NAME, 'result')
@property
def results(self):
return [self.Result(self, el) for el in self.find_elements(*self._result_locator)]
class Result(Region):
_name_locator = **(By.XPATH, '//span')**
_detail_locator = **(By.TAG_NAME, '//a')**
@property
def name(self):
return self.find_element(*self._name_locator).text
@property
def detail_link(self):
return self.find_element(*self._detail_locator).get_property("href")
main.py
result_page = Results(browser, base_url).open()
for el in (result_page.results):
print el.name
The final output:
Result 1
Result 1
Result 1
Result 1
I tried to run the example you have shared in documentation that works great, but that is with CLASS_NAME and TAG_NAME.
Use collections.abc for Python 3 and collections for Python 2.
src/pypom/page.py
20: if isinstance(arg, collections.Iterable) and not isinstance(arg, str):
Hi!
Newer minor versions of the zope.interface
and zope.component
dependencies now pull in many more transient dependencies than they used to:
https://github.com/mozilla/treeherder/blob/1bbc11c09b36c1aeb642fe8057647bc7c60c796d/requirements/dev.txt#L119-L184
This feels pretty heavyweight for something that doesn't seem entirely necessary. (And is adding to our dependency bot PR churn, plus on multiple occasions needed manual changes to add the hashes for sub-dependencies).
Could the zope dependencies be removed?
Hey Dave!
A brief issue I noticed is that I can't install via command: pip install PyPOM
Could not find a version that satisfies the requirement PyPOM (from versions: )
No matching distribution found for PyPOM
Could you explain what's causing this?
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.