Created
June 21, 2013 22:35
-
-
Save douglatornell/5834848 to your computer and use it in GitHub Desktop.
Examples of Selenium/WebDriver page objects and tests. The page objects are based on the holmium.core library.
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 -*- | |
"""Page objects for UI testing of Nordion SmartSolve CF app. | |
""" | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from holmium.core import ( | |
Locators, | |
PageElement, | |
PageObject, | |
) | |
class Login(PageObject): | |
login_id = PageElement(Locators.NAME, 'LoginControl:LoginID') | |
password = PageElement(Locators.NAME, 'LoginControl:Password') | |
signin_btn = PageElement(Locators.ID, 'LoginControl_SignInBtn') | |
def sign_in(self, username, password): | |
self.login_id.send_keys(username) | |
self.password.send_keys(password) | |
self.signin_btn.click() | |
return wait_until_visible(self.driver, Dashboard, 'CF_btn') | |
class Dashboard(PageObject): | |
logout_btn = PageElement( | |
Locators.ID, 'smartRibbon_MainApplicationBar_LogoutBtn_Text') | |
CF_btn = PageElement( | |
Locators.ID, 'smartRibbon_HomeTabGroup_CreateCF_Text') | |
def log_out(self): | |
self.logout_btn.click() | |
def initiate_CF(self): | |
self.CF_btn.click() | |
return wait_until_visible(self.driver, CreateCF, 'create_CF_btn') | |
class CreateCF(PageObject): | |
create_CF_btn = PageElement(Locators.ID, 'btnSave') | |
proposed_chg = PageElement(Locators.ID, 'textarea_V_CF_CF_PROPOSAL_1', timeout=10) | |
chg_type = PageElement(Locators.ID, 'comboBox_V_CF_GRC_TYPE_1') | |
chg_category = PageElement(Locators.ID, 'comboBox_V_CF_CF_CATEGORY_1') | |
def create_CF(self, chg_proposal, chg_type, chg_category): | |
ta = self.driver.find_element_by_id('V_CF_CF_PROPOSAL_1') | |
ta.send_keys('foo') | |
WebDriverWait(self.driver, 10).until(EC.visibility_of(self.proposed_chg)) | |
self.proposed_chg.send_keys(chg_proposal) | |
self.chg_type.send_keys(chg_type) | |
self.chg_category.send_keys(chg_category) | |
# self.create_CF_btn.click() | |
def wait_until_visible(driver, page_object, element, timeout=10): | |
page = page_object(driver) | |
try: | |
(WebDriverWait(driver, timeout) | |
.until(EC.visibility_of(getattr(page, element)))) | |
finally: | |
return page |
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 -*- | |
""" | |
""" | |
import holmium.core | |
import pages | |
class TestCreateCF(holmium.core.HolmiumTestCase): | |
def setUp(self): | |
self.driver.maximize_window() | |
login_page = pages.Login( | |
self.driver, 'https://nordion.pilgrimasp.com/qa/') | |
self.dashboard_page = login_page.sign_in( | |
'doug.latornell', 'fooBar28feB') | |
def test_create_product_mfg_support_CF(self): | |
create_CF_page = self.dashboard_page.initiate_CF() | |
print self.driver.current_window_handle | |
print self.driver.window_handles | |
self.driver.switch_to_window(self.driver.window_handles[1]) | |
self.driver.maximize_window() | |
import time | |
time.sleep(15) | |
create_CF_page.create_CF( | |
chg_proposal='In response to CAPA 120804, the following actions ' | |
'will be taken:\n' | |
'- Introduce a stainless steel funnel cap to be applied to the ' | |
'dispensing funnel after dispensing is complete.\n' | |
'- Clarify and improve on the cleaning and inspection steps in the' | |
'funnel preparation process.', | |
chg_type='Product/Process', | |
chg_category='Manufacturing Process', | |
) | |
import time | |
time.sleep(15) | |
self.dashboard_page.go_home() | |
self.dashboard_page.log_out() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment