def set_address(self, address, dest_page='dest'): self.address1.clear() self.address1.send_keys(address[0]) self.address2.clear() self.address2.send_keys(address[1]) self.city.clear() self.city.send_keys(address[2]) if main.is_android( ): # hide keyboard (probably covering state element) self.try_hide_keyboard() self.select_state(address[3]) self.postal.clear() self.postal.send_keys(address[4]) self.click_continue() # Redirect page could be destination picker (normal) or... # send page (US recipient sending to MX bank account or cashout) if dest_page == 'send': WDW(self.driver, 10).until( EC.presence_of_element_located((By.ID, 'sourceAmountInput'))) elif dest_page == 'recipient_view': WDW(self.driver, 10).until( EC.presence_of_element_located( (By.CLASS_NAME, 'recipient_remove'))) else: # destination page (default) WDW(self.driver, 10).until( EC.presence_of_element_located((By.ID, 'radio_cashout')))
def manage_facility(self, facilityIndex, action): if action != 'delete' and action != 'edit': print('Invalid facility action: ' + str(action)) return False facility = None try: facility = self.facilities[facilityIndex] except IndexError: print('Invalid facility index') return False if facility: facility[action].click() if action == 'delete': self.popUpForm = popUpForm.PopUpForm(self.driver) WDW(self.driver, 10).until(lambda x: self.popUpForm.load()) self.popUpForm.confirm('confirm') # Wait for confirm popup and loading overlay to disappear WDW(self.driver, 3).until_not(EC.presence_of_element_located((By.CLASS_NAME, 'react-confirm-alert'))) WDW(self.driver, 10).until_not(EC.presence_of_element_located((By.CLASS_NAME, 'overlay'))) elif action == 'edit': # Should be on edit version of Consent Form pass return True
def edit_treatments(self, editInfo, expectedInfo): self.editTreatmentForm = editTreatmentForm.EditTreatmentForm( self.driver) WDW(self.driver, 20).until(lambda x: self.editTreatmentForm.load()) if self.editTreatmentForm.edit_treatment(editInfo): WDW(self.driver, 20).until( lambda x: self.load({'tests': [expectedInfo]}, 'saved'))
def submit(self, mrdInfo, action='cancel'): for questionIndex, question in enumerate(mrdInfo): print('answering question: ' + str(questionIndex)) loadedQuestion = self.loadedData[questionIndex] secondaryInfo = question.get('secondary', None) questionOptions = loadedQuestion.get('options', None) textarea = loadedQuestion.get('textInput', None) dropdowns = loadedQuestion.get('dropdowns', None) multipleDropdown = question.get('multiple_dropdown') if questionOptions: WDW(self.driver, 20).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay'))) inputEl = questionOptions[question['option']] inputEl.click() if not inputEl.is_selected(): print('Clicked input, but it is not selected') return False if textarea: textarea.send_keys(question.get('textInput', None)) if dropdowns: if multipleDropdown: self.form.set_dropdown( dropdowns[0], question.get('multiple_dropdown', None)) AC(self.driver).send_keys(Keys.ESCAPE).perform() else: self.form.set_dropdown(dropdowns[0], question.get('dropdown', None)) if secondaryInfo: # Question has secondary response # Reload question and get loadedInfo for secondary question WDW(self.driver, 20).until(lambda x: self.load()) loadedSecondaryInfo = self.loadedData[questionIndex].get( 'secondary_questions', None) secondaryText = secondaryInfo.get('text', None) secondaryOptions = secondaryInfo.get('options', None) if secondaryText: print(loadedSecondaryInfo) textInput = loadedSecondaryInfo[0]['textInput'] if textInput: textInput.clear() textInput.send_keys(secondaryText) else: print('could not find textarea for question[' + str(questionIndex) + ']') else: radioOptions = loadedSecondaryInfo[0]['options'] radioOptions[secondaryOptions].click() time.sleep(1) if action == 'save': self.save_button.click() else: self.cancel_button.click() return True
def add_new_lab(self, labInfo, action='save'): self.add_new_labs.click() self.addLabsForm = addLabsForm.AddLabsForm(self.driver) WDW(self.driver, 10).until(lambda x: self.addLabsForm.load()) self.addLabsForm.submit(labInfo, 'save') WDW(self.driver, 3).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay')))
def add_ngs_test(self, ngsInfo, action='save'): self.add_ngs_button.click() self.ngsTestForm = ngsTestForm.NgsTestForm(self.driver) WDW(self.driver, 10).until(lambda x: self.ngsTestForm.load()) self.ngsTestForm.submit(ngsInfo, action) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay')))
def upload_file(self, action='cancel'): self.upload_file_button.click() self.uploadFileForm = uploadFileForm.UploadFileForm(self.driver) WDW(self.driver, 10).until(lambda x: self.uploadFileForm.load()) self.uploadFileForm.confirm(action) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay')))
def edit_high_risk(self, riskInfo, action='save'): self.editHighRiskForm = editHighRiskForm.EditHighRiskForm(self.driver) WDW(self.driver, 10).until(lambda x: self.editHighRiskForm.load()) self.editHighRiskForm.submit(riskInfo, action) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay'))) self.validate_risk_table(riskInfo)
def add_treatment(self, treatmentInfo, expectedInfo=None, expectedError=None, expectedWarnings=None): # ExpectedInfo should be list of expected tests if expectedInfo is None: expectedInfo = [treatmentInfo] try: # print(self.state) if self.state == 'normal' or self.state == 'saved': self.click_add_treatment() self.addTreatmentForm = addTreatmentForm.AddTreatmentForm( self.driver) WDW(self.driver, 10).until(lambda x: self.addTreatmentForm.load()) if self.addTreatmentForm.add_treatment(treatmentInfo): WDW(self.driver, 10).until( lambda x: self.load({'tests': expectedInfo}, 'saved')) else: print('Failed to add treatment') else: # todo: handle fresh popup pass return True except MsgError: # Is add treatment expected to fail? errorType = self.error['errorType'] if expectedError and errorType.lower() == expectedError.lower(): return True print(self.error['errorMsg']) if errorType == 'undefined': print('Undefined error: ' + self.error['errorText']) except WarningError: # Is form submission expected to have warning? unexpectedWarnings = [] if expectedWarnings: # Go through self.warnings and check each warningType matches an expectedWarning # Append warnings that aren't expected to unexpectedWarnings for i, warning in enumerate(self.warnings): expected = False warningType = warning['type'] for expectedWarning in expectedWarnings: if expectedWarning == warningType: expected = True if not expected: unexpectedWarnings.append(self.warnings[i]) if unexpectedWarnings: for unexpected in unexpectedWarnings: print(unexpected['msg']) if warningType == 'undefined': print('Undefined warning: ' + unexpected['text']) else: return True return True
def set_location(self,location): self.location_menu.click() time.sleep(.4) WDW(self.driver, 10).until(EC.visibility_of(self.driver.find_element_by_id('account_location'))) self.driver.find_element_by_id('account_location').click() WDW(self.driver, 10).until(EC.element_to_be_clickable((By.ID, 'account_location'))) if location == "United States": self.try_load_us() else: self.try_load_mexico()
def select_tab(self, tabName): try: tab = self.tabs[tabName.lower()] tab.click() WDW(self.driver, 10).until(lambda x: self.load(tabName)) WDW(self.driver, 20).until_not(EC.presence_of_element_located((By.CLASS_NAME, 'overlay'))) return True except KeyError: print('fullHealthView: No tab named: ' + str(tabName))
def mrd_survey(self, mrdInfo, action): self.surveys[0]['mrd testing in myeloma'].click() self.mrdTestingSurveyForm = mrdTestingSurveyForm.MrdTestingSurveyForm( self.driver) WDW(self.driver, 10).until(lambda x: self.mrdTestingSurveyForm.load()) self.mrdTestingSurveyForm.submit(mrdInfo, action) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay')))
def add_physician_typeahead(self, partial_name, full_name, physicianInfo): # Enter partial_name, select option w/ full_name, verify info matches physicianInfo # Enter partial_name physician_elements = self.physicians[-1]['elements'] physician_elements['name_input'].click() AC(self.driver).send_keys(partial_name).perform() # Wait for options to show up, then click option that matches full_name WDW(self.driver, 10).until( EC.presence_of_element_located((By.CLASS_NAME, 'rbt-menu'))) count = 0 loaded = False while not loaded or count > 10: count += 1 try: menu = self.driver.find_element_by_class_name('rbt-menu') options = menu.find_elements_by_tag_name('li') for option in options: option_text = option.text if option_text == 'No matches found.': time.sleep(.5) break elif option.text == full_name: anchor = option.find_element_by_tag_name('a') anchor.click() loaded = True except StaleElementReferenceException: pass # Reload to avoid staleElementException WDW(self.driver, 10).until(lambda x: self.load()) physician_elements = self.physicians[-1]['elements'] # Validate physicianInfo failures = [] if physicianInfo['name'] != physician_elements[ 'name_input'].get_attribute('value'): failures.append('Name does not match.') if physicianInfo['facility'] != physician_elements[ 'facility_input'].get_attribute('value'): failures.append('Facility does not match') if physicianInfo['city'] != physician_elements[ 'city_input'].get_attribute('value'): failures.append('City does not match') if physicianInfo['state'] != physician_elements['state_selector'].text: failures.append('State does not match') if len(failures) > 0: for failure in failures: print(failure) return False else: return True
def set_state(self, state): #raw_input(self.state_dd.text) self.move_to_el(self.state_dd) WDW(self.driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'sm-state-menuitem'))) states = self.driver.find_elements_by_class_name('sm-state-menuitem') for i, st in enumerate(states): text = states[i].text if state in text: states[i].click() break WDW(self.driver, 10).until_not(EC.presence_of_element_located((By.CLASS_NAME, 'sm-state-menuitem')))
def add_recipient(self): # ensure add button is visible on page self.scroll_to_bottom() WDW(self.driver, 10).until( EC.element_to_be_clickable( (By.CLASS_NAME, 'add_recipient_button'))) #time.sleep(.4) self.add_button.click() WDW(self.driver, 10).until( EC.presence_of_element_located( (By.ID, 'recipient_second_surname')))
def set_carrier(self, carrier): if carrier: self.load_carrier_input() self.carrier_click.click() WDW(self.driver, 5).until(EC.element_to_be_clickable((By.ID, 'carrier_01'))) self.try_load_carrier_dd() self.carriers[carrier].click() WDW(self.driver, 5).until( EC.invisibility_of_element_located((By.ID, 'carrier_01'))) return True
def molecular_survey(self, myelomaInfo, action='cancel'): self.surveys[0]['multiple myeloma genetic (molecular) testing'].click() self.multipleMyelomaSurveyForm = multipleMyelomaSurveyForm.MultipleMyelomaSurveyForm( self.driver) WDW(self.driver, 10).until(lambda x: self.multipleMyelomaSurveyForm.load()) self.multipleMyelomaSurveyForm.submit(myelomaInfo, action) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay')))
def add_gep_test(self, gepInfo, action='cancel'): self.add_gep_button.click() self.gepTestForm = gepTestForm.GepTestForm(self.driver) WDW(self.driver, 10).until(lambda x: self.gepTestForm.load()) self.gepTestForm.submit(gepInfo, action) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay'))) self.load() self.validate_gep_test(gepInfo)
def add_physician(self, physicianInfo, action='submit'): self.add_physician_button.click() self.addPhysicianForm = addPhysicianForm.AddPhysicianForm(self.driver) WDW(self.driver, 10).until(lambda x: self.addPhysicianForm.load()) self.addPhysicianForm.submit(physicianInfo, action) # Wait for modal and loading overlay to disappear WDW(self.driver, 3).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay'))) return True
def change_username(self, usernameInfo, action='continue'): self.header = header.AuthHeader(self.driver) self.edit_username_button.click() self.changeUsernameForm = changeUsernameForm.ChangeUsernameForm( self.driver) WDW(self.driver, 20).until(lambda x: self.changeUsernameForm.load()) self.changeUsernameForm.submit(usernameInfo, action) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 20).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay')))
def conditions_survey(self, conditionsInfo, action='cancel'): self.surveys[0][ 'pre-cursor conditions to multiple myeloma (mgus and smoldering myeloma) in families'].click( ) self.conditionsSurveyForm = conditionsSurveyForm.ConditionsSurveyForm( self.driver) WDW(self.driver, 10).until(lambda x: self.conditionsSurveyForm.load()) self.conditionsSurveyForm.submit(conditionsInfo, action) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay')))
def imaging_survey(self, imagingInfo, action='cancel'): self.surveys[0][ 'imaging tests you have had performed (x-ray, mri, pet, etc.)'].click( ) self.imagingSurveyForm = imagingSurveyForm.ImagingSurveyForm( self.driver) WDW(self.driver, 10).until(lambda x: self.imagingSurveyForm.load()) self.imagingSurveyForm.submit(imagingInfo, action) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay')))
def vaccinations_survey(self, vaccinationsInfo, action): self.surveys[0][ 'vaccinations you received after myeloma treatment'].click() self.vaccinationsSurveyForm = vaccinationsSurveyForm.VaccinationsSurveyForm( self.driver) WDW(self.driver, 10).until(lambda x: self.vaccinationsSurveyForm.load()) self.vaccinationsSurveyForm.submit(vaccinationsInfo, action) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay')))
def click_continue(self): try: WDW(self.driver, 10).until( EC.element_to_be_clickable((By.CLASS_NAME, 'primaryButton'))) except TimeoutException: raise TimeoutException("Send page: Continue button not enabled.") self.continue_button.click() try: WDW(self.driver, 10).until( EC.presence_of_element_located((By.ID, 'send_conf_button'))) except TimeoutException: raise TimeoutException("Send Page: Could not find element on next page.")
def remove_phone(self, attempt=True): if self.remove_phone_button != None: self.remove_phone_button.click() WDW(self.driver, 10).until( EC.presence_of_element_located((By.CLASS_NAME, 'remove_ok'))) self.try_load_remove_popup() if attempt: self.remove_button.click() else: self.remove_cancel.click() WDW(self.driver, 10).until(EC.presence_of_element_located((By.ID, 'callmi_pin')))
def load(self): try: WDW(self.driver, 10).until(EC.presence_of_element_located((By.ID, 'signin_form_user'))) self.signInForm = signInForm.SignInForm(self.driver) WDW(self.driver, 10).until(lambda x:self.signInForm.load()) # self.load_body() self.header = header.PubHeader(self.driver) return True except (NoSuchElementException, StaleElementReferenceException, IndexError) as e: #print('Exception loading signin page') return False except TimeoutException: return False
def confirm_sign_out(self): # mobile personal settings page has extra sign out option button = self.driver.find_element_by_class_name('logout_ok') button.click() try: if main.is_web(): # Goes to home page # WDW(self.driver, 10).until(EC.presence_of_element_located((By.ID, 'contactEmail2'))) WDW(self.driver, 10).until(EC.presence_of_element_located((By.ID, 'empEnroll'))) else: # Native: goes to signin page WDW(self.driver, 10).until(EC.element_to_be_clickable((By.ID, 'submit_si_button'))) except TimeoutException: raise Exception("Menu: Could not find expected element after logout.")
def remove_recipient(self, remove=True): self.remove_button.click() WDW(self.driver, 10).until( EC.presence_of_element_located((By.CLASS_NAME, 'recip_remove_ok'))) if remove: # click ok css = 'recip_remove_ok' self.driver.find_element_by_class_name(css).click() else: # click cancel css = 'recip_remove_cancel' self.driver.find_element_by_class_name(css).click() WDW(self.driver, 10).until( EC.presence_of_element_located( (By.CLASS_NAME, 'add_recipient_button')))
def add_diagnosis(self, diagnosisInfo, action='submit'): self.add_diagnosis_button.click() self.additionalDiagnosisForm = additionalDiagnosisForm.AdditionalDiagnosisForm( self.driver) WDW(self.driver, 10).until(lambda x: self.additionalDiagnosisForm.load()) self.additionalDiagnosisForm.submit(diagnosisInfo) # Wait for modal and loading overlay to disappear WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'modal-dialog'))) WDW(self.driver, 10).until_not( EC.presence_of_element_located((By.CLASS_NAME, 'overlay'))) return True
def click_continue(self): self.continue_button = self.form.find_element_by_id('send_cont_button') try: WDW(self.driver, 10).until( EC.element_to_be_clickable((By.ID, 'send_cont_button'))) except TimeoutException: raise TimeoutException("Send page: Continue button not enabled.") self.nav.click_el(self.continue_button) try: WDW(self.driver, 10).until( EC.presence_of_element_located((By.ID, 'send_conf_button'))) except TimeoutException: raise TimeoutException( "Send Page: Could not find element on next page.")