Fix home page tests

This commit is contained in:
Mat Hare 2021-07-11 12:16:24 +01:00
parent 0176973a49
commit 918181fbc4
5 changed files with 30 additions and 27 deletions

View File

@ -77,20 +77,8 @@ class DataTable(object):
@given(parsers.parse('I have navigated to the \'the-internet\' "{page_name}" page'), target_fixture='navigate_to') @given(parsers.parse('I have navigated to the \'the-internet\' "{page_name}" page'), target_fixture='navigate_to')
def navigate_to(browser, page_name): def navigate_to(browser, page_name):
BASE_URL = "https://the-internet.herokuapp.com" url = BasePage.PAGE_URLS.get(page_name.lower())
PAGE_URLS = {
"home": BASE_URL + "/",
"checkboxes": BASE_URL + "/checkboxes",
"dropdown": BASE_URL + "/dropdown",
"dynamic controls": BASE_URL + "/dynamic_controls",
"form authentication": BASE_URL + "/login",
"inputs": BASE_URL + "/inputs",
"secure area": BASE_URL + "/secure"
}
url = PAGE_URLS.get(page_name.lower())
browser.get(url) browser.get(url)
return url
@then(parsers.parse('a "{text}" banner is displayed in the top-right corner of the page')) @then(parsers.parse('a "{text}" banner is displayed in the top-right corner of the page'))

View File

@ -58,10 +58,10 @@ Feature: Home Page
And the link in the page footer goes to "http://elementalselenium.com/" And the link in the page footer goes to "http://elementalselenium.com/"
Scenario Outline: Open <page> page Scenario Outline: Open <page> page
When I click on the "<page>" link When I click on the <page> link
Then the "<page>" page opens Then the <page> page opens
Examples: Examples:
| page | | page |
| Checkboxes | | Checkboxes |
| Dropdown | | Dropdown |
| Dynamic Controls | | Dynamic Controls |

View File

@ -3,6 +3,18 @@ from selenium.webdriver.common.by import By
class BasePage(): class BasePage():
BASE_URL = "https://the-internet.herokuapp.com"
PAGE_URLS = {
"home": BASE_URL + "/",
"checkboxes": BASE_URL + "/checkboxes",
"dropdown": BASE_URL + "/dropdown",
"dynamic controls": BASE_URL + "/dynamic_controls",
"form authentication": BASE_URL + "/login",
"inputs": BASE_URL + "/inputs",
"secure area": BASE_URL + "/secure"
}
@property @property
@abstractmethod @abstractmethod
def PAGE_TITLE(self): def PAGE_TITLE(self):

View File

@ -19,6 +19,7 @@ class HomePage(BasePage):
for link in links: for link in links:
if link.text.startswith(page_name): if link.text.startswith(page_name):
link.click() link.click()
break
def get_page_title_text(self): def get_page_title_text(self):
return self.browser.find_element(*self.PAGE_TITLE).text return self.browser.find_element(*self.PAGE_TITLE).text

View File

@ -1,30 +1,32 @@
from pytest_bdd import scenarios, when, then, parsers from pytest_bdd import scenarios, when, then, parsers
from pages.home import HomePage as page from pages.home import HomePage
from sttable import parse_str_table
from pages.base import BasePage from pages.base import BasePage
from sttable import parse_str_table
scenarios('../features/home_page.feature') scenarios('../features/home_page.feature')
@when(parsers.parse('I click on the "{page_name}" link'))
def click_page_link(browser, page_name): @when('I click on the <page> link')
page(browser).click_page_link(page_name) def click_page_link(browser, page):
HomePage(browser).click_page_link(page)
@then(parsers.parse('the page title is "{title}"')) @then(parsers.parse('the page title is "{title}"'))
def verify_page_title(browser, title): def verify_page_title(browser, title):
assert title == page(browser).get_page_title_text() assert title == HomePage(browser).get_page_title_text()
@then(parsers.parse('the sub-header text is "{text}"')) @then(parsers.parse('the sub-header text is "{text}"'))
def verify_subheader_text(browser, text): def verify_subheader_text(browser, text):
assert text == page(browser).get_subheader_text() assert text == HomePage(browser).get_subheader_text()
@then(parsers.parse('a list of the following sub-pages is displayed\n{subpages}')) @then(parsers.parse('a list of the following sub-pages is displayed\n{subpages}'))
def verify_subpage_list(browser, datatable, subpages): def verify_subpage_list(browser, datatable, subpages):
expected = parse_str_table(subpages) expected = parse_str_table(subpages)
for field in expected.fields: for field in expected.fields:
assert expected.columns[field] == page(browser).get_subpage_list() assert expected.columns[field] == HomePage(browser).get_subpage_list()
@then(parsers.parse('the "{page_name}" page opens')) @then('the <page> page opens')
def verify_page_opens(browser, page_name, navigate_to): def verify_page_opens(browser, page):
assert navigate_to == page(browser).get_current_url() assert BasePage.PAGE_URLS.get(page.lower()) == HomePage(browser).get_current_url()