Top Banner
Selenium PageObject: Bok-Choy Tim Babych
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

Oct 17, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
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

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

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

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

● 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

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

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

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

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

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

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

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

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

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

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

● 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

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

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

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

Github: https://github.com/edx/bok-choy

Docs:

http://bok-choy.readthedocs.org

@tymofiy

Thanks!