Created
August 12, 2016 03:32
-
-
Save belimawr/471a7fc401e1ac124b6a5b46bac820c5 to your computer and use it in GitHub Desktop.
Example of Splinter's find_by_text with pyfunct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Based on https://github.com/gabrielpjordao/pyfunct/blob/master/examples/wikipedia.py | |
from pyfunct import BaseConfig | |
from pyfunct import Page | |
from pyfunct import FunctTestCase | |
from pyfunct import action | |
class WikipediaConfig(BaseConfig): | |
base_url = 'http://en.wikipedia.org' | |
default_browser = 'firefox' | |
class IndexPage(Page): | |
page_name = 'wikipedia index' | |
def get_url(self): | |
return '/' | |
@property | |
def elements_selectors(self): | |
return ( | |
('search input', "//input[@name='search']", 'xpath'), | |
('search button', "#searchButton", 'css'), | |
('in the news', 'In the news', 'text'), | |
) | |
class MyTestCase(FunctTestCase): | |
def test_searching_a_wiki(self): | |
# This goes to the page and loads it's elements selectors. | |
self.browser.open_page('wikipedia index') | |
# Fill the search input with "Functional testing" | |
self.browser.type('search input', 'Functional testing') | |
# Submit the search by clicking the button | |
self.browser.click_and_wait('search button') | |
page_title = self.browser.page_title | |
expected_title = 'Functional testing - Wikipedia' | |
self.assertIn(expected_title, page_title) | |
def test_searching_a_wiki_using_actions(self): | |
self.actions.perform_search(self.browser, 'Functional testing') | |
expected_title = 'Functional testing - Wikipedia' | |
self.actions.assert_title_contains(self.browser, expected_title) | |
def test_find_by_text(self): | |
self.browser.open_page('wikipedia index') | |
elements = self.browser.get_element_by_text('In the news') | |
expected_text = elements.first.text | |
self.assertIn('In the news', expected_text) | |
@action | |
def perform_search(browser, query): | |
# This goes to the page and loads it's elements selectors. | |
browser.open_page('wikipedia index') | |
# Fill the search input with "Functional testing" | |
browser.type('search input', 'Functional testing') | |
# Submit the search by clicking the button | |
browser.click_and_wait('search button') | |
@action | |
def assert_title_contains(browser, expected_title): | |
page_title = browser.page_title | |
assert expected_title in page_title, "The expected title was not found in"\ | |
"the page title" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment