selenium pageobject: bok-choyclear.com.ua/talks/bok-choy.pdf · bok-choy tim babych. functional...
TRANSCRIPT
![Page 1: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/1.jpg)
Selenium PageObject: Bok-Choy
Tim Babych
![Page 2: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/2.jpg)
Functional tests for Web
means
Browser Automation
![Page 3: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/3.jpg)
Browser Automantion
Means
Selenium
![Page 4: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/4.jpg)
● Checks system behavior from user's perspective
● Emulates user's actions with real browsers– Firefox– Chrome
● And not so real– Phantom JS (headless)
![Page 5: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/5.jpg)
browser = webdriver.Firefox()
browser.get('https://github.com/')
assert 'GitHub' in browser.title
from selenium.webdriver.common.keys import Keys
elem = browser.find_element_by_css_selector("input[name='q']")
elem.send_keys('splinter' + Keys.RETURN)
assert "splinter" in browser.title
browser.close()
![Page 6: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/6.jpg)
Repetitive
![Page 7: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/7.jpg)
Automate more
Splinter
![Page 8: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/8.jpg)
browser = Browser()
browser.visit('https://github.com/')
assert 'GitHub' in browser.title
from selenium.webdriver.common.keys import Keys
browser.fill_form({'q': 'splinter'+Keys.RETURN})
assert "splinter" in browser.title
browser.quit()
![Page 9: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/9.jpg)
check() for checkboxes
choose() for selects
click_link_by_href() and even by .._partial_href for links
CookieManager
mouse_over and mouse_out
is_element_present_by... (value, tag, name, id)
Helpers
![Page 10: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/10.jpg)
we need to get high
![Page 11: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/11.jpg)
Bok-Choy:the PageObject
![Page 12: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/12.jpg)
from bok_choy.page_object import PageObject
class GitHubSearchPage(PageObject):
url = 'http://www.github.com/search'
def is_browser_on_page(self):
return 'code search' in self.browser.title.lower()
![Page 13: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/13.jpg)
def search_for_term(self, text):
"""
Fill the text into the input field and submit the form
"""
self.q(
css='#search_form > input[type="text"]'
).fill(text) self.q(css='button.button').click()
![Page 14: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/14.jpg)
def search_for(self, text):
"""
Fill the text into the input field and submit the form
"""
…. fill, click....
GitHubSearchResultsPage(
self.browser
).wait_for_page()
![Page 15: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/15.jpg)
● Hide page implementation details– css rules for finding elements– multi-step interactions to get to certain point
● Inherit page classes from one another– share common methods and details
● Decorate tests– @wait_for_js (modules)– @js_defines (vars)
![Page 16: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/16.jpg)
Element Query Sequence
● map● filter● transform (apply func)● replace (values)
• execute
![Page 17: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/17.jpg)
Browser Query Sequence
● attrs● text● selected● visible● fill
Promise
![Page 18: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/18.jpg)
Other Goodies
● Browsermob-proxy:– HAR files
● Screenshots of the exceptions● N retries for selenium queries
![Page 19: Selenium PageObject: Bok-Choyclear.com.ua/talks/bok-choy.pdf · Bok-Choy Tim Babych. Functional tests for Web means Browser Automation. Browser Automantion Means Selenium](https://reader036.vdocuments.site/reader036/viewer/2022070112/6058d0e86f5cf636e024615e/html5/thumbnails/19.jpg)
Github: https://github.com/edx/bok-choy
Docs:
http://bok-choy.readthedocs.org
@tymofiy
Thanks!