@@ -31,18 +31,29 @@ and ensure some results are found.
3131 import page
3232
3333 class PythonOrgSearch(unittest.TestCase):
34+ """A sample test class to show how page object works"""
3435
3536 def setUp(self):
3637 self.driver = webdriver.Firefox()
3738 self.driver.get("http://www.python.org")
3839
3940 def test_search_in_python_org(self):
41+ """
42+ Tests python.org search feature. Searches for the word "pycon" then verified that some results show up.
43+ Note that it does not look for any particular text in search results page. This test verifies that
44+ the results were not empty.
45+ """
46+
47+ #Load the main page. In this case the home page of Python.og.
4048 main_page = page.MainPage(self.driver)
49+ #Checks if the word "Python" is in title
4150 assert main_page.is_title_matches(), "python.org title doesn't match."
42- main_page.search_text_element = "pycon"
43- main_page.click_go_button()
51+ #Sets the text of search textbox to "pycon"
52+ main_page.search_text_element = "pycon"
53+ main_page.click_go_button()
4454 search_results_page = page.SearchResultsPage(self.driver)
45- assert search_results_page.is_results_found(), "No results found."
55+ #Verifies that the results page is not empty
56+ assert search_results_page.is_results_found(), "No results found."
4657
4758 def tearDown(self):
4859 self.driver.close()
@@ -59,29 +70,37 @@ The ``page.py`` will look like this::
5970 from locators import MainPageLocators
6071
6172 class SearchTextElement(BasePageElement):
73+ """This class gets the search text from the specified locator"""
6274
75+ #The locator for search box where search string is entered
6376 locator = 'q'
6477
6578
6679 class BasePage(object):
80+ """Base class to initialize the base page that will be called from all pages"""
6781
6882 def __init__(self, driver):
6983 self.driver = driver
7084
7185
7286 class MainPage(BasePage):
87+ """Home page action methods come here. I.e. Python.org"""
7388
89+ #Declares a variable that will contain the retrieved text
7490 search_text_element = SearchTextElement()
7591
7692 def is_title_matches(self):
93+ """Verifies that the hardcoded text "Python" appears in page title"""
7794 return "Python" in self.driver.title
7895
7996 def click_go_button(self):
97+ """Triggers the search"""
8098 element = self.driver.find_element(*MainPageLocators.GO_BUTTON)
8199 element.click()
82100
83101
84102 class SearchResultsPage(BasePage):
103+ """Search results page action methods come here"""
85104
86105 def is_results_found(self):
87106 # Probably should search for this text in the specific page
@@ -97,14 +116,17 @@ The ``element.py`` will look like this::
97116
98117
99118 class BasePageElement(object):
119+ """Base page class that is initialized on every page object class."""
100120
101121 def __set__(self, obj, value):
122+ """Sets the text to the value supplied"""
102123 driver = obj.driver
103124 WebDriverWait(driver, 100).until(
104125 lambda driver: driver.find_element_by_name(self.locator))
105126 driver.find_element_by_name(self.locator).send_keys(value)
106127
107128 def __get__(self, obj, owner):
129+ """Gets the text of the specified object"""
108130 driver = obj.driver
109131 WebDriverWait(driver, 100).until(
110132 lambda driver: driver.find_element_by_name(self.locator))
@@ -119,7 +141,9 @@ The ``locators.py`` will look like this::
119141 from selenium.webdriver.common.by import By
120142
121143 class MainPageLocators(object):
144+ """A class for main page locators. All main page locators should come here"""
122145 GO_BUTTON = (By.ID, 'submit')
123146
124147 class SearchResultsPageLocators(object):
148+ """A class for search results locators. All search results locators should come here"""
125149 pass
0 commit comments