def test_2(): try: # create lib page object obj_lib=LIB() # open browser browser=obj_lib.open_browser() # navigate to the url obj_lib.page_load(browser) # create Home and Contact_us pages objects obj_home=Home(browser) obj_contact_us=Contact_us(browser) # click on Sign In button of the Home page browser.find_element(*obj_home.contact_us).click() # wait for the element to be visible in Sign in page obj_lib.wait_for_element(browser, obj_contact_us.subject_heading) # locate subject heading element and choose one of the options element = browser.find_element(*obj_contact_us.subject_heading) element.click() select_text = obj_lib.get_data(key='subject_heading') select_option = Select(element) select_option.select_by_visible_text(select_text) # fill in the email field valid_email_value=obj_lib.get_data(key='valid_email') browser.find_element(*obj_contact_us.email_address).send_keys(valid_email_value) # input in order reference field order_reference_value=obj_lib.get_data(key='references') browser.find_element(*obj_contact_us.order_reference).send_keys(order_reference_value) # fill in the message field message_text = obj_lib.get_data(key='contact_us_input_message') browser.find_element(*obj_contact_us.message_field).send_keys(message_text) # click Send button browser.find_element(*obj_contact_us.send_button).click() # validate that success message has appeared success_message=obj_lib.get_data(key='contact_us_success_message') assert success_message in browser.page_source print("Test 2 passes!") except Exception as e: # save the screenshot of the test file which has failed obj_lib.save_screenshot(browser) pytest.fail(e) print('Test 2 failed!') finally: # close the browser obj_lib.close_browser(browser)
def test_3(): try: #create objet of the LIB class . open browser and go to URL obj_lib = LIB() browser = obj_lib.open_browser() obj_lib.page_load(browser) # Creating homepage & contact us page objects obj_home = Home(browser) obj_contuct_us = Contuct_us(browser) # Filling all mandatory fields obj_contuct_us.choose_subject_heading(browser) obj_contuct_us.input_invalid_email() obj_contuct_us.input_reference() obj_contuct_us.click_send() #check error message error_message = obj_lib.get_data("contact_us_error_message") assert success_message in browser.page_source print("test passed") except: obj_lib.save_screenshot(browser) print("Test failed") finally: obj_lib.close_browser(browser)
def choose_subject_heading(self, browser): LIB.wait_for_element(self, browser , self.subject_heading) select_text = LIB.get_data(self , key = "subject_heading") element = self.browser.find_element(*self.subject_heading) element.click() select = Select(element) select.select_by_visible_text(select_text)
def write_message(self): message = LIB.get_data(self, key='message') self.browser.find_element_by_id(self.message).send_keys(message)
def attach_file(self): img = LIB.get_data(self, key='img_path') self.browser.find_element_by_id('fileUpload').send_keys(img)
def order_refference(self): order_ref = LIB.get_data(self, key='ord_refferance') self.browser.find_element_by_id( self.order_refference_locator).send_keys(order_ref)
def select_subject_heading(self, browser): LIB.wait_for_element(self, browser, self.subject_heading_locator) select_text = LIB.get_data(self, key='subject_heading') select = Select( self.browser.find_element_by_xpath(self.subject_heading)) select.select_by_visible_text(select_text)
def input_invalid_email(self): inv_email = LIB.get_data(self , key = "invalid_email") self.browser.find_element(*self.email_address).send_keys(inv_email)
def input_message(self): mes = LIB.get_data(self, key = "contact_us_input_message") self.browser.find_element(*self.message_field).send_keys(mes)
def input_reference(self): ref = LIB.get_data(self, key = "references") self.browser.find_element(*self.order_reference).send_keys(ref)
def input_email_address(self): email = LIB.get_data(self, key = "valid_email") self.browser.find_element(*self.email_address).send_keys(email)