class LoginPage(PageObject): # username needs a more unique identifier username = PageElement(class_name="text-input") password = PageElement(id_="password2") submit = PageElement(class_name="green-button") remember_me = PageElement(id_="remember_me") url_slug = "/login" def load(self): self.get(self.url_slug) def fill_in_form(self, **profile): self.username = profile.get("username") self.password = profile.get("password") # ideally page actions are moved to a client class def login(self, remember=False, **profile): self.fill_in_form(**profile) if remember: self.remember_login() self.submit.click() def is_logged_in(self): return "events" in self.w.current_url def remember_login(self): self.remember_me.click() def clear_cookies(self): self.w.delete_all_cookies()
class DubizzleHomepage(PageObject): place_an_ad_option = PageElement(id_='place_an_ad_callout_en') search_form = PageElement(id_='search-widget-form') quick_links = PageElement(id_='quick-links') def __init__(self, driver): super(DubizzleHomepage, self).__init__(driver) self.fn = None self.driver = driver def go_to(self, local='dubai'): self.driver.get(self.homepage_url(local)) def homepage_url(self, local): site_url = '' if local == 'dubai': return 'http://dubai.dubizzle.com' elif local == 'other blah': return "" else: return 'super blah' def verify_title(self, expected): actual = self.driver.title if re.search(expected, actual): return True else: return False def element_is_visible(self, link): fn_string = link.replace(" ", "_") fn = eval('self.' + fn_string) var = fn.is_displayed() return fn.is_displayed()
class RegisterStudentPage(PageObject): checkboxes = MultiPageElement(xpath="//input[@type='checkbox']") checked_checkboxes = MultiPageElement(css="input:checked[type='checkbox']") submit_button = PageElement(css="input[type='submit']") success_message_element = PageElement(css=".info") finished_course_message_element = PageElement(css=".finished-course-message") not_started_course_message_element = PageElement(css=".not-started-course-message") @property def not_started_course_message(self): return self.not_started_course_message_element.text @property def finished_course_message(self): return self.finished_course_message_element.text @property def success_message(self): return self.success_message_element.text @property def checked_students(self): checked_students = [checked_checkbox.find_element_by_xpath("..").text for checked_checkbox in self.checked_checkboxes] return checked_students def toggle_check(self, student): # this is tied to structure of checkboxes generated by django # <label for="id_students_0"> # <input id="id_students_0" name="students" value="1" type="checkbox"> john # </label> student_chekboxes = [checkbox for checkbox in self.checkboxes if checkbox.find_element_by_xpath("..").text == student] assert len(student_chekboxes) > 0, "student not found in checkboxes" assert len(student_chekboxes) == 1, "many students found in checkboxes" student_chekbox = student_chekboxes[0] student_chekbox.click()
class LoginPage(StorePage): input_email = PageElement(id_="email") input_passwd = PageElement(id_="passwd") btn_submit_login = PageElement(id_="SubmitLogin") span_empty_cart = PageElement(class_name="ajax_cart_no_product") alert = None url = "http://automationpractice.com/index.php?controller=authentication&back=my-account" def fillPassword(self, password): self.input_passwd.send_keys(password) def fillEmail(self, email): self.input_email.send_keys(email) def submitLogin(self): self.btn_submit_login.click() def locateErrors(self, browser): self.alert = browser.find_elements_by_tag_name("li") # self.alert = PageElement(class_name="alert") # for i in self.alert: # print(i.text) # if i.text == "An email address required.": # print("pimba") return self.alert[14].text # the only way i could find to do this
class ShareForm(PageObject): shares = PageElement(name='shares') company = MultiPageElement(css='label.company-label') source = MultiPageElement(css='label.source') transfer_button = PageElement(name='transfer-share') buy_share = PageElement(id_='action-buy') sell_share = PageElement(id_='action-sell') action = PageElement(id_='action-text') def select_company(self, name): # pragma: no cover for label in self.company: if label.get_attribute('for') == 'company-{}'.format(name): label.click() break else: # pragma: no cover raise AssertionError( 'No company called {} found in share list'.format(name)) def select_source(self, name): # pragma: no cover for label in self.source: if label.get_attribute('for') == 'source-{}'.format(name): label.click() break else: raise AssertionError('Could not select {}'.format(name))
class GamePage(PageObject): reload_game = PageElement(id_='reload') add_player_link = PageElement(id_='add_player') add_company_link = PageElement(id_='add_company') display_net_worth_link = PageElement(id_='display-net-worth') undo = PageElement(id_='undo') redo = PageElement(id_='redo') bank_cash = PageElement(css="#bank #cash") bank_pool = MultiPageElement(css="#bank .pool") pool_shares_pay = PageElement(name='pool-shares-pay') ipo_shares_pay = PageElement(name='ipo-shares-pay') treasury_shares_pay = PageElement(name='treasury-shares-pay') log = MultiPageElement(css="#log div.entry") player_name_list = MultiPageElement(css="div.player div.name") _player_list = MultiPageElement(class_name="player") _company_list = MultiPageElement(class_name="company") def get_players(self): res = [] for row in self._player_list: res.append(Player(row, self.w)) return res def get_companies(self): res = [] for row in self._company_list: res.append(Company(row, self.w)) return res
class AdminPage(PageObject): link_register = PageElement(css="a[href='register.htm']") button_database_clean = PageElement(css="button[value='CLEAN']") button_database_initialize = PageElement(css="button[value='INIT']") action_result_message = PageElement(xpath='//*[@id="rightPanel"]/p/b') def method_admin_page_clean_database( self, current_web_driver, ): self.button_database_clean.click() WebDriverWait(current_web_driver, delay_min).until( expected_conditions.visibility_of(self.action_result_message)) return def method_admin_page_initialize_database( self, current_web_driver, ): self.button_database_initialize.click() WebDriverWait(current_web_driver, delay_min).until( expected_conditions.visibility_of(self.action_result_message)) return def method_home_page_navigate_to_register(self, current_web_driver): self.link_register.click() WebDriverWait(current_web_driver, delay_medium).until( expected_conditions.title_contains('Register for Free')) return
class Entity(PageObject): _name = PageElement(css=".name", context=True) _cash = PageElement(css=".cash", context=True) _detail = PageElement(css=".detail", context=True) _shares = MultiPageElement(css=".share", context=True) _summary = PageElement(css=".row", context=True) def __init__(self, root, *args, **kwargs): super(Entity, self).__init__(*args, **kwargs) self.root = root def __getitem__(self, key): if key == 'row': return self.root elif key == 'elem' or key == 'summary': return self._summary(self.root) elif key == 'name': return self._name(self.root) elif key == 'cash': return self._cash(self.root) elif key == 'shares': return self._shares(self.root) elif key == 'detail': return self._detail(self.root) else: # pragma: no cover raise KeyError
class SearchPage(PageObject): _page_title = 'Search | Precision Nutrition' _page_url = '/search?q=' _search_wrapper_area = PageElement(class_name='gsc-above-wrapper-area') _search_results = PageElement(class_name='gsc-webResult') _search_results_selenium = 'gsc-webResult'
class CreateTodo(PageObject): name = PageElement(name='name') description = PageElement(name='desc') urgent = PageElement(name='urgent') submit = PageElement(id_='submit') error = PageElement(css='.terminal-alert-error') def create_todo(self, name, description, urgent): self.wait_page_load() be_blank(self.w, 'input[name="name"]') be_blank(self.w, 'textarea[name="desc"]') self.name = name self.description = description if urgent: self.urgent.click() self.submit.click() def wait_page_load(self): WebDriverWait(self.w, 20).until_not( lambda driver: driver.find_element_by_css_selector('#wait')) def wait_error_message(self): WebDriverWait(self.w, 20).until( lambda driver: 'terminal-alert-error' in driver.page_source)
class PageLogin(PageObject): fieldUsername = PageElement(id_='username') fieldPassword = PageElement(id_='keys') buttonSubmit = PageElement(css='input[type="submit"]') driver = None def _clear_fields_(self): self.fieldPassword.clear() self.fieldUsername.clear() def __init__(self, webdriver): self.driver = webdriver PageObject.__init__(self, webdriver) def __login__(self, username, password): self._clear_fields_() self.fieldUsername = username self.fieldPassword = password self.buttonSubmit.click() def login_correctly(self, username, password): self.__login__(username, password) return PageVaults.PageVaults(self.driver) def login_incorrectly(self, username, password): self.__login__(username, password) return self def verify_on_login_page(self): return self.buttonSubmit.get_attribute("value") == constants.text_loginbutton and \ (self.driver.current_url == constants.url_base or self.driver.current_url == constants.url_base + constants.url_index)
class YandexMainPage(PageObject): search_text = PageElement(id_='text') search_button = PageElement(xpath='//button') def __init__(self, web_driver, uri=''): super().__init__(web_driver, uri) self.get('https://ya.ru')
class Google(PageObject): lstib = PageElement(id_='lst-ib') btnK = PageElement(name='btnK') def search(self, txt): self.lstib.send_keys(txt) self.btnK.click()
class LoginPage(PageObject): input_login = PageElement( xpath="//span[text()='Username*']/ancestor::label/input") input_password = PageElement( xpath="//span[text()='Password*']/ancestor::label/input") btn_submit_login = PageElement(xpath="//button[@class='main-button']") label_invalid_credentials = PageElement( xpath="//p[@class='error-message ng-binding']")
class LoginPage(PageObject): ''' 登录页面 ''' logintab = PageElement(class_name='account-tab-account') username = PageElement(id_='username') password = PageElement(name='password') login = PageElement(link_text='登录豆瓣')
class JamesAllenFooter(PageObject): newsletter_input = PageElement(id_='newsletter-input') male_btn = PageElement(name='Male') def signup_email_list(self, user): self.w.wait_until(lambda f: self.newsletter_input, 30) self.newsletter_input = user['username'] self.male_btn.click()
class ToursListingPage(PageObject): """This class resolves elements for Dubai search""" # to click for element to make a search vacation_place_element1 = PageElement( css="a.select2-choice.select2-default") # To send text "Dubai" vacation_place_element2 = PageElement( css="div.select2-drop-active > div > input.select2-input") # To select Big Bus Tour of Dubai from menu choose_tour_element = PageElement( css="ul > li > ul > li > div.select2-result-label") # To provision date date_element = PageElement(css="input[name = 'date']") # Submit element submit_elemnt = PageElement( css="button.btn-danger.btn.btn-lg.btn-block.pfb0.loader[type='submit']" ) def return_title(self): """This function returns page title for assertation""" return self.w.title def make_screenshot(self, test_name): """This function makes screenshot of the page""" self.w.get_screenshot_as_file( "../phptravels_logs/screen_ToursListingPage{}.png".format( test_name)) def send_dubai_data(self, place="Dubai", start_date="02/08/2018"): """This function populates search data and finally returns new page object""" """To DO: Add tour type: minor""" # Put Dubai as vacation place self.vacation_place_element1.click() self.vacation_place_element2.send_keys(place) # select tour Big Bus Tour of Dubai self.w.implicitly_wait(2) action = ActionChains(self.w) action.move_to_element(self.choose_tour_element) action.click() action.perform() # Set date arrival date self.date_element.clear() self.date_element.send_keys(start_date) # press submit button self.submit_elemnt.click() return BigBusTourPage( self.w, root_uri= 'https://www.phptravels.net/tours/united-arab-emirates/dubai/ \ Big-Bus-Tour-of-Dubai?date=02/08/2018&adults=2' )
class MainPage(PageObject): _page_title = 'Nutrition Coaching and Certification | Precision Nutrition' _page_url = '/' _get_started_button = PageElement(class_name='button_blue') _sing_in_button = PageElement(class_name='sign_in') _search_query_locator = PageElement(name='q') _search_submit = PageElement(xpath='//button[@type="submit"]') _blog_link = PageElement(xpath='//a[@href="/blog"]')
class JamesSignupThanksPopup(PageObject): close_thanx_rsgister = PageElement(id_='closeThanxRegister') popup_div = PageElement(xpath='//div[@id="absoluteDiv"][@class="Visible"]') def close_register_popup(self): self.close_thanx_rsgister.click() def check_popup_disabled(self): return self.w.wait_until_not(lambda f: self.popup_div, 30)
class SubMenu(PageObject): timeLink = PageElement("Time") reportsLink = PageElement("Reports") chartsLink = PageElement("Charts") projectsLink = PageElement("Projects") userLink = PageElement("Users") def go_to_reports(self): self.reportsLink.click()
class FilterPage(PageObject): section_title = PageElement(xpath='//*[@class="inlineBlock"]') popup_close = PageElement(xpath='(//a[@class="btn-close1"])[10]') def __init__(self, web_driver, uri=''): super().__init__(web_driver, uri) self.popup_close.click() sleep(2)
class BaiduIndexPage(PageObject): search_input = PageElement(id_="kw", timeout=3, describe="输入框") search_button = PageElement(css="#su", timeout=20, describe="按钮") # 定位一组元素 search_result = PageElements(xpath="//div/h3/a") settings = PageElement(link_text="设置") search_setting = PageElement(css=".setpref", describe="搜索设置") select_number = PageElement(id_="nr", describe="选择每页显示个数")
class Login(WaitablePageObject): email = PageElement(name='email') password = PageElement(name='senha') submit = PageElement(css='input[value="Login"]') error = PageElement(css='.terminal-alert-error') def wait_form(self, name='email'): WebDriverWait(self.w, 20).until( EC.element_to_be_clickable((By.NAME, name)) )
class RegistrationPage(PageObject): text_box_first_name = PageElement(id_='customer.firstName') button_submit_form = PageElement(css="input[value='Register']") form_submit_result_message = PageElement(id_='customer.lastName.errors') def method_registration_page_clean_database(self, current_web_driver,): self.text_box_first_name = 'name_first' self.button_submit_form.click() WebDriverWait(current_web_driver,delay_medium).until(expected_conditions.visibility_of(self.form_submit_result_message)) return
class CadastroUsuarioPage(BasePage): usuario_field = PageElement(id_ = 'user-username') nome_field = PageElement(id_ = 'user-realname') email_field = PageElement(id_ ='email-field') nivel_acesso_select = PageElement(id_ = 'user-access-level') usuario_habilitado_checkbox_span = PageElement(css = '#user-enabled + span') usuario_habilitado_checkbox = PageElement(id_ = 'user-enabled') usuario_protegido_checkbox_span = PageElement(css = '#user-protected + span') usuario_protegido_checkbox = PageElement(id_ = 'user-protected') criar_usuario_button = PageElement(css = 'input[type="submit"]') def informar_usuario(self, usuario): self.usuario_field = usuario def informar_nome(self, nome): self.nome_field = nome def informar_email(self, email): self.email_field = email def selecionar_nivel_acesso(self, nivel_acesso): Select(self.nivel_acesso_select).select_by_visible_text(nivel_acesso) def marcar_usuario_habilitado(self): if self.usuario_habilitado_checkbox.checked != 'checked': self.usuario_habilitado_checkbox_span.click() def marcar_usuario_protegido(self): if self.usuario_protegido_checkbox.checked != 'checked': self.usuario_protegido_checkbox_span.click() def clicar_em_criar_usuario(self): self.criar_usuario_button.click()
class CallHistoryPage(PageObject): date_filter_btn = PageElement(xpath=DATE_FILTER_BTN_XPATH) date_filter_form = PageElement(id_='callhistoryFiltersForm') @property def is_visible(self): return 'Call History' in self.w.title @property def current_record_count(self): if not self.is_visible: return '0' rec_count = WebDriverWait(self.w, 10).until(EC.element_to_be_clickable((By.XPATH, RECORD_COUNT_XPATH))) return rec_count.text # @property # def filter_input_visible(self): # return self.date_filter_form.is_displayed() # @property # def from_input(self): # wait = WebDriverWait(self.w, 10) # from_input = wait.until(EC.element_to_be_clickable((By.ID, 'from-0'))) # return PageElement(id_='from-0') # @property # def to_input(self): # wait = WebDriverWait(self.w, 10) # from_input = wait.until(EC.element_to_be_clickable((By.ID, 'to-0'))) # return PageElement(id_='to-0') # @property # def set_filters_btn(self): # filter_footer = PageElement(xpath=FILTER_FOOTER_XPATH) # set_filters = PageElement(css='input[type="submit"]', context=True) # return set_filters(filter_footer) @property def current_date_filters(self): filters = WebDriverWait(self.w, 10).until( EC.element_to_be_clickable((By.ID, 'filter_date')) ) return filters.text def set_filters(self, from_date='', to_date=''): self.date_filter_btn.click() from_date_input = WebDriverWait(self.w, 10).until( EC.element_to_be_clickable((By.ID, 'from-0'))) from_date_input.send_keys(from_date) to_date_input = WebDriverWait(self.w, 10).until(EC.element_to_be_clickable((By.ID, 'to-0'))) to_date_input.send_keys(to_date) set_filter_button = self.w.find_element_by_xpath(FILTER_FOOTER_XPATH).find_element_by_tag_name("input") set_filter_button.click() WebDriverWait(self.w, 2)
class LoginPage(PageObject): username = PageElement(id_='LoginUsername') password = PageElement(id_='LoginPassword') login_btn = PageElement(id_='loginBtn') manage_org_btn = PageElement(xpath=MANAGE_ORG_BTN_XPATH) scope_badge = PageElement(id_='scopeButton') def login(self, username, password): self.username = username self.password = password self.login_btn.click()
class NetWorthPopup(PageObject): popup = PageElement(id_='net-worth') background = PageElement(css='.background') def value(self, player, row): field_name = 'value-{}-{}'.format(player, row) return self.popup.find_element_by_id(field_name) def company_row(self, company): field_id = 'row-{}'.format(company) return self.popup.find_element_by_id(field_id)
class Google(PageObject): search_bar = PageElement(id_='lst-ib') btn_search = PageElement(name='btnK') btn_lucky = PageElement(name='btnI') def search(self, text): self.search_bar.send_keys(text) self.btn_search.click() def lucky(self, text): self.search_bar.send_keys(text) self.btn_lucky.click()
class ChartPage(PageObject): del_from_cart_button = PageElement(xpath='//a[@class="del"]') total_price = PageElement( xpath='(//div[@class="total"]//span[@class="value"])[1]') def __init__(self, web_driver, uri=''): super().__init__(web_driver, uri) def delete_from_chart(self): self.del_from_cart_button.click() sleep(1)