I was reading about page objects and design patterns on the Webdriver project site and came across pagefactory. It doesn't look like the Webdriver for Python API includes pagefactory. Is this true?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
I don't think there is any equivalents of the Java annotations (@Find(By.xxx) etc) in Python. But it doesn't mean that you can't use the PageObject pattern.
You can find good example on how to do here : https://github.com/SeleniumHQ/selenium/blob/master/py/test/selenium/webdriver/common/google_one_box.py
I have created a module called
pageobject_support
that implements PageFactory pattern in a pythonic way.With this module, Google Search page could be modelled as follows:
Your feedback is appreciated. For more details, please visit https://jeremykao.wordpress.com/2015/06/10/pagefactory-pattern-in-python/
Dynamically-typed languages like Python are less obsessed by design patterns to create objects - because it is trivially easy just create object of any type (with proper methods) and return it. Patterns are common solutions to common problems. If something is not a problem, you don't need a pattern to deal with it :-) OOP was initially a design pattern in C.
Edit, Dec 2017:
In our homegrown framework for page automation (for automated UI testing and other purposes), we do use pageobject design pattern, but had no need for a page factory. Old-school inheritance from our custom BasePage covered all our (quite diversified) needs. We do use few tricks to create page elements and make sure that proper page was instantiated, and based on that experience I like that our PageObject is simple.
Also, Python allows for multiple inheritance, if your needs grow more complicated.
In my experience (using Python, Selenium and WebDriver for more than 5 years now), lack of page factory pattern is a sign that you don't need it, not that it cannot be implemented.