Best Python code snippet using selene_python
NPSP.py
Source:NPSP.py
...76 """ Populate field with Place Holder as a locator77 and actual value of the place holder.78 """79 xpath = npsp_lex_locators["placeholder"].format(loc)80 field = self.selenium.get_webelement(xpath)81 field.send_keys(value)82 time.sleep(1)83# if loc == ("Search Contacts" or "Search Accounts"):84 field.send_keys(Keys.ENTER)85# field.send_keys(Keys.ARROW_DOWN)86# field.send_keys(Keys.ENTER)87 def click_record_button(self, title):88 """ Pass title of the button to click the buttons on the records edit page. Usually save and cancel are the buttons seen.89 """90 locator = npsp_lex_locators['record']['button'].format(title)91 self.selenium.set_focus_to_element(locator)92 button = self.selenium.get_webelement(locator)93 button.click()94 time.sleep(5)95 96 def select_tab(self, title):97 """ Switch between different tabs on a record page like Related, Details, News, Activity and Chatter98 Pass title of the tab99 """100 locator = npsp_lex_locators['tab'].format(title)101 self.selenium.set_focus_to_element(locator)102 button = self.selenium.get_webelement(locator)103 button.click()104 time.sleep(5) 105 106 def click_special_related_list_button(self, heading, button_title):107 """ To Click on a related list button which would open up a new lightning page rather than a modal.108 Pass the list name and button name"""109 self.salesforce.load_related_list(heading)110 locator = npsp_lex_locators["record"]["related"]["button"].format(111 heading, button_title112 )113 self.selenium.click_link(locator)114 115 def click_dropdown(self, title):116 locator = npsp_lex_locators['record']['list'].format(title)117 self.selenium.set_focus_to_element(locator)118 self.selenium.get_webelement(locator).click()119 self.wait_for_locator('popup')120 def open_date_picker(self, title):121 locator = npsp_lex_locators['record']['list'].format(title)122 self.selenium.set_focus_to_element(locator)123 self.selenium.get_webelement(locator).click()124 def pick_date(self, value):125 """To pick a date from the date picker"""126 locator = npsp_lex_locators['record']['datepicker'].format(value)127 self.selenium.set_focus_to_element(locator)128 self.selenium.get_webelement(locator).click() 129 def change_month(self, value): 130 """To pick month in the date picker"""131 locator = npsp_lex_locators['record']['month_pick'].format(value)132 self.selenium.set_focus_to_element(locator)133 self.selenium.get_webelement(locator).click()134 135# def select_row(self,value):136# """To select a row on object page based on name and open the dropdown""" 137# drop_down = npsp_lex_locators['locating_delete_dropdown'].format(value)138# self.selenium.get_webelement(drop_down).click()139# #self.selenium.get_webelement(drop_down).click()140# def select_row(self,value):141# """To select a row on object page based on name and open the dropdown""" 142# locator = npsp_lex_locators['select_name'].format(value)143# self.selenium.set_focus_to_element(locator)144# drop_down = npsp_lex_locators['locating_delete_dropdown'].format(value)145# time.sleep(1)146# return drop_down147 148 def select_row(self, value):149 """To select a row on object page based on name and open the dropdown"""150 locators = npsp_lex_locators['name']151 list_ele = self.selenium.get_webelements(locators)152 for index, element in enumerate(list_ele):153 if element.text == value:154 drop_down = npsp_lex_locators['locate_dropdown'].format(index + 1)155 self.selenium.get_webelement(drop_down).click()156 time.sleep(1)157 def select_related_row(self, value):158 """To select a row on object page based on name and open the dropdown"""159 locators = npsp_lex_locators['related_name']160 list_ele = self.selenium.get_webelements(locators)161 for index, element in enumerate(list_ele):162 if element.text == value:163 drop_down = npsp_lex_locators['rel_loc_dd'].format(index + 1)164 self.selenium.get_webelement(drop_down).click()165 time.sleep(1)166# def select_row(self, value ):167# """To select a row on object page based on name and open the dropdown"""168# locators = npsp_lex_locators['name']169# list_ele = self.selenium.get_webelements(locators)170# index= 1171# for locator in list_ele:172# global index173# if locator.text != value:174# index = index+1175# else:176# drop_down = npsp_lex_locators['locate_dropdown'].format(index)177# self.selenium.get_webelement(drop_down).click()178# self.selenium.get_webelement(drop_down).click()179 180# def select_related_row(self, value ):181# """To select row from a related list based on name and open the dropdown"""182# locators = npsp_lex_locators['related_name']183# list_ele = self.selenium.get_webelements(locators)184# index= 1185# for locator in list_ele:186# global index187# if locator.text != value:188# index = index+1189# else:190# drop_down = npsp_lex_locators['rel_loc_dd'].format(index)191# self.selenium.get_webelement(drop_down).click()192# self.selenium.get_webelement(drop_down).click() 193 194 def delete_icon(self, field_name,value): 195 """To click on x """196 locator=npsp_lex_locators['delete_icon'].format(field_name,value)197 self.selenium.get_webelement(locator).click() 198 def click_id(self, title): 199 locator=npsp_lex_locators['aff_id'].format(title)200 self.selenium.get_webelement(locator).click() 201 202 def select_object_dropdown(self): 203 locator=npsp_lex_locators['object_dd']204 self.selenium.get_webelement(locator).click() 205 206 def check_status(self, acc_name):207 aff_list = npsp_lex_locators['aff_status'].format(acc_name)208 aff_list_text=self.selenium.get_webelement(aff_list).text 209 self.aff_id=npsp_lex_locators['aff_id'].format(acc_name)210 self.aff_id_text=self.selenium.get_webelement(self.aff_id).text211 return self.aff_id_text,aff_list_text 212 213 214 def get_id(self):215 locator=npsp_lex_locators['click_aff_id'].format(self.aff_id_text)216 self.selenium.get_webelement(locator).click() 217 218 219 def confirm_value(self, field,value,status):220 locator=npsp_lex_locators['check_status'].format(field)221 actual_value=self.selenium.get_webelement(locator).text222 if status.upper() == "Y":223 assert value == actual_value, "Expected value to be {} but found {}".format(224 value, actual_value225 )226 elif status.upper() == "N":227 assert value != actual_value, "Expected value {} and actual value {} should not match".format(228 value, actual_value229 ) 230 231 def verify_field_value(self, field,value,status):232 locator=npsp_lex_locators['check_field'].format(field)233 actual_value=self.selenium.get_webelement(locator).text234 if status.upper() == "Y":235 assert value == actual_value, "Expected value to be {} but found {}".format(236 value, actual_value237 )238 elif status.upper() == "N":239 assert value != actual_value, "Expected value {} and actual value {} should not match".format(240 value, actual_value241 ) 242 243 244 def verify_record(self, name):245 """ Checks for the record in the object page and returns true if found else returns false246 """247 locator=npsp_lex_locators['account_list'].format(name)248 self.selenium.page_should_contain_element(locator)249 250 def select_option(self, name): 251 """selects various options in Contact>New opportunity page using name252 """253 locator=npsp_lex_locators['dd_options'].format(name)254 self.selenium.get_webelement(locator).click()255 256 def verify_related_list_items(self,list_name,value):257 """Verifies a specified related list has specified value(doesn't work if the list is in table format)"""258 locator=npsp_lex_locators['related_list_items'].format(list_name,value)259 self.selenium.page_should_contain_element(locator)260 261 def click_span_button(self,title): 262 """clicks on the button under span tag""" 263 locator=npsp_lex_locators['span_button'].format(title)264 self.selenium.get_webelement(locator).click() 265 266 def header_field_value(self,title,value): 267 """Validates if the specified header field has specified value""" 268 locator= npsp_lex_locators['header_field_value'].format(title,value)269 self.selenium.page_should_contain_element(locator)270 271 def verify_header(self,value): 272 """Validates header value""" 273 locator= npsp_lex_locators['header'].format(value)274 self.selenium.page_should_contain_element(locator) 275 276 def Verify_affiliated_contact(self,list_name,first_name,last_name, y): 277 """Validates if the affiliated contacts have the added contact details enter Y for positive case and N for negative case"""278 name = first_name + ' ' + last_name279 locator = self.salesforce.get_locator('record.related.link', list_name, name)280 if y.upper()=="Y":281 self.selenium.page_should_contain_element(locator)282 elif y.upper()=="N":283 self.selenium.page_should_not_contain_element(locator)284 285 def fill_address_form(self, **kwargs):286 """Validates if the affiliated contacts have the added contact details enter Y for positive case and N for negative case""" 287 for label, value in kwargs.items():288 locator= npsp_lex_locators['manage_hh_page']['address'].format(label,value)289 if label=="Street":290 locator = locator+"textarea"291 self.selenium.get_webelement(locator).send_keys(value)292 else:293 locator = locator+"input"294 self.selenium.get_webelement(locator).send_keys(value)295 296 def fill_bge_form(self, **kwargs):297 for label, value in kwargs.items():298 if label=="Batch Description":299 locator= npsp_lex_locators['bge']['field-text'].format(label,value) 300 self.salesforce._populate_field(locator, value) 301 else:302 locator= npsp_lex_locators['bge']['field-input'].format(label,value)303 self.salesforce._populate_field(locator, value)304 305 306 def Verify_details_address(self,field,npsp_street, npsp_city, npsp_country): 307 """Validates if the details page address field has specified value""" 308 locator= npsp_lex_locators['detail_page']['address'].format(field)309 street, city, country = self.selenium.get_webelements(locator)310 if street.text == npsp_street and city.text == npsp_city and country.text == npsp_country:311 return "pass"312 else:313 return "fail"314 315 def validate_checkbox(self,name,checkbox_title): 316 """validates all 3 checkboxes for contact on manage hh page and returns locator for the checkbox thats required""" 317 318 locator=npsp_lex_locators['manage_hh_page']['mhh_checkbox'].format(name,"fauxCBInformal")319 self.selenium.page_should_contain_element(locator)320 321 locator=npsp_lex_locators['manage_hh_page']['mhh_checkbox'].format(name,"fauxCBFormal")322 self.selenium.page_should_contain_element(locator)323 324 locator=npsp_lex_locators['manage_hh_page']['mhh_checkbox'].format(name,"fauxCBExName") 325 self.selenium.page_should_contain_element(locator)326 327 if checkbox_title == "Informal Greeting":328 locator=npsp_lex_locators['manage_hh_page']['mhh_checkbox'].format(name,"fauxCBInformal")329 elif checkbox_title == "Formal Greeting":330 locator=npsp_lex_locators['manage_hh_page']['mhh_checkbox'].format(name,"fauxCBFormal") 331 elif checkbox_title.capitalize() == "Household Name":332 locator=npsp_lex_locators['manage_hh_page']['mhh_checkbox'].format(name,"fauxCBExName") 333 return locator334 335 def check_field_value(self, title, value):336 """checks value of a field in details page(section without header)"""337 locator=npsp_lex_locators['detail_page']['verify_field_value'].format(title,value)338 self.selenium.page_should_contain_element(locator)339 340 def click_managehh_button(self,title): 341 """clicks on the new contact button on manage hh page""" 342 locator=npsp_lex_locators['manage_hh_page']['button'].format(title)343 self.selenium.get_webelement(locator).click() 344 345 def click_managehh_link(self,title): 346 locator=npsp_lex_locators['manage_hh_page']['address_link'].format(title)347 self.selenium.get_webelement(locator).click() 348 349 def select_lightning_checkbox(self,title):350 locator=npsp_lex_locators['checkbox'].format(title)351 self.selenium.get_webelement(locator).click()352 353 def select_lightning_table_checkbox(self,title):354 locator=npsp_lex_locators['table_checkbox'].format(title)355 self.selenium.get_webelement(locator).click()356 357 def select_bge_checkbox(self,title):358 locator=npsp_lex_locators['bge']['checkbox'].format(title)359 self.selenium.get_webelement(locator).click() 360 361 def populate_modal_field(self, title, value):362 locator=npsp_lex_locators['modal_field'].format(title,value)363 self.salesforce._populate_field(locator, value)364 365 366 def verify_occurrence(self,title,value):367 locator=npsp_lex_locators['record']['related']['check_occurrence'].format(title,value)368 actual_value=self.selenium.get_webelement(locator).text369 exp_value="("+value+")"370 assert exp_value == actual_value, "Expected value to be {} but found {}".format(371 exp_value, actual_value372 ) 373 374 def check_record_related_item(self,title,value):375 locator=npsp_lex_locators['record']['related']['item'].format(title,value)376 actual_value=self.selenium.get_webelement(locator).text377 assert value == actual_value, "Expected value to be {} but found {}".format(378 value, actual_value379 ) 380 381 382 def select_related_dropdown(self,title):383 """Clicks on the dropdown next to Related List"""384 locator=npsp_lex_locators['record']['related']['drop-down'].format(title)385 self.selenium.get_webelement(locator).click() 386 387 def get_header_date_value(self,title): 388 """Validates if the specified header field has specified value""" 389 locator= npsp_lex_locators['header_datepicker'].format(title)390 date=self.selenium.get_webelement(locator).text 391 return date 392 393 def get_main_header(self):394 locator = npsp_lex_locators['header_text']395 header = self.selenium.get_webelement(locator).text396 return header397 398 def verify_contact_role(self,name,role):399 """verifies the contact role on opportunity page"""400 locator=npsp_lex_locators['opportunity']['contact_role'].format(name,role)401 self.selenium.page_should_contain_element(locator) 402 403 def select_relatedlist(self,title):404 """click on the related list to open it"""405 locator=npsp_lex_locators['record']['related']['title'].format(title)406 self.selenium.get_webelement(locator).click() 407 408 def verify_related_list_field_values(self, **kwargs):409 """verifies the values in the related list objects page""" 410 for name, value in kwargs.items():411 locator= npsp_lex_locators['record']['related']['field_value'].format(name,value)412 self.selenium.page_should_contain_element(locator)413 414 def page_contains_record(self,title): 415 """Validates if the specified record is present on the page""" 416 locator= npsp_lex_locators['object']['record'].format(title)417 self.selenium.page_should_not_contain_element(locator) 418 419 420 421 def click_special_object_button(self, title):422 locator = npsp_lex_locators['object']['button'].format(title)423 self.selenium.get_webelement(locator).click()424 425 def click_eng_plan_dropdown(self, title):426 locator = npsp_lex_locators['engagement_plan']['dropdown'].format(title)427 self.selenium.set_focus_to_element(locator)428 self.selenium.get_webelement(locator).click()429 430 def select_eng_plan_checkbox(self,title):431 """"""432 if title=="Skip Weekends":433 locator=npsp_lex_locators['engagement_plan']['checkbox'].format("span",title)434 self.selenium.get_webelement(locator).click()435 else:436 locator=npsp_lex_locators['engagement_plan']['checkbox'].format("label",title)437 self.selenium.get_webelement(locator).click()438 439 def enter_eng_plan_values(self, name, value):440 """Enter values into corresponding fields in Engagement Plan Templet page"""441 locator = npsp_lex_locators['id'].format(name) 442 self.salesforce._populate_field(locator, value)443 444 445 446 def enter_task_id_and_subject(self, id, value):447 """Enter values into corresponding task subject fields based on last 2 digits of id"""448 locator = npsp_lex_locators['engagement_plan']['input_box'].format(id) 449 self.selenium.get_webelement(locator).send_keys(value)450 451 452 def click_task_button(self, task_id, name):453 """Click Task button based on Task id and button label""" 454 locator = npsp_lex_locators['engagement_plan']['button'].format(task_id, name)455 self.selenium.get_webelement(locator).click() 456 457 458 def check_related_list_values(self,list_name,*args):459 """Verifies the value of custom related list"""460 for value in args:461 locator = npsp_lex_locators['check_related_list_item'].format(list_name,value)462 self.selenium.page_should_contain_element(locator)463 def verify_eng_plan_exists(self,name, delete=None): 464 """verifies that the Engagement Plans related list has a plan stored under it and clicks on dropdown if True is passed as 2nd argument"""465 locator = npsp_lex_locators['engagement_plan']['check_eng_plan'].format(name)466 self.selenium.page_should_contain_element(locator) 467 plan=self.selenium.get_webelement(locator).text 468 if delete == "True":469 locator = npsp_lex_locators['engagement_plan']['dd'].format(name)470 self.selenium.get_webelement(locator).click() 471 return plan472 473 def check_activity_tasks(self, *args):474 """verifies that the specified tasks are present under activity tab """475 for value in args:476 locator = npsp_lex_locators['engagement_plan']['tasks'].format(value)477 self.selenium.page_should_contain_element(locator)478 def enter_level_values(self, **kwargs):479 """Enter values into corresponding fields in Levels page"""480 for name, value in kwargs.items():481 if name == "Level Name":482 id = "fldName"483 locator = npsp_lex_locators['levels']['id'].format(id)484 self.salesforce._populate_field(locator, value) 485 elif name == "Minimum Amount":486 id = "fldMinAmount"487 locator = npsp_lex_locators['levels']['id'].format(id)488 self.salesforce._populate_field(locator, value) 489 elif name == "Maximum Amount":490 id = "fldMaxAmount"491 locator = npsp_lex_locators['levels']['id'].format(id)492 self.salesforce._populate_field(locator, value) 493 def enter_level_dd_values(self, name,value):494 """Enter values into corresponding fields in Levels page""" 495 if name == "Target":496 id = "fldTarget"497 locator = npsp_lex_locators['levels']['select'].format(id)498 loc = self.selenium.get_webelement(locator)499 self.selenium.set_focus_to_element(locator) 500 self.selenium.select_from_list_by_label(loc,value)501 time.sleep(2)502 elif name == "Source Field":503 id = "fldSourceField"504 locator = npsp_lex_locators['levels']['select'].format(id)505 loc = self.selenium.get_webelement(locator) 506 self.selenium.set_focus_to_element(locator) 507 self.selenium.select_from_list_by_label(loc,value) 508 time.sleep(2) 509 elif name == "Level Field":510 id = "fldLevel"511 locator = npsp_lex_locators['levels']['select'].format(id)512 loc = self.selenium.get_webelement(locator) 513 self.selenium.set_focus_to_element(locator) 514 self.selenium.select_from_list_by_label(loc,value)515 time.sleep(2)516 elif name == "Previous Level Field":517 id = "fldPreviousLevel"518 locator = npsp_lex_locators['levels']['select'].format(id)519 loc = self.selenium.get_webelement(locator) 520 self.selenium.set_focus_to_element(locator) 521 self.selenium.select_from_list_by_label(loc,value) 522 def select_app_launcher_link(self,title):523 locator = npsp_lex_locators['app_launcher']['select-option'].format(title) 524 self.selenium.get_webelement(locator).click()525 time.sleep(1)526 527 def click_on_first_record(self): 528 """selects first record of the page"""529 locator = npsp_lex_locators['select_one_record']530 self.selenium.get_webelement(locator).click()531 time.sleep(1) 532 533 def select_search(self, index, value):534 """"""535 locator = npsp_lex_locators["click_search"].format(index)536 loc_value = self.selenium.get_webelement(locator).send_keys(value)537 loc = self.selenium.get_webelement(locator)538 #loc.send_keys(Keys.TAB+ Keys.RETURN)539 time.sleep(1) 540 541 def enter_gau(self, value):542 id = "lksrch"543 locator = npsp_lex_locators["id"].format(id)544 loc = self.selenium.get_webelement(locator)545 loc.send_keys(value)546 self.selenium.get_webelement("//*[@title='Go!']").click()547 time.sleep(1)548 def add_gau_allocation(self,field, value):549 locator = npsp_lex_locators["gaus"]["input_field"].format(field)550 loc = self.selenium.get_webelement(locator).send_keys(value)551 552 553 def click_save(self, page):554 if page== "GAU":555 id="j_id0:theForm:j_id9:j_id10:saveBTN"556 locator = npsp_lex_locators["id"].format(id)557 self.selenium.get_webelement(locator).click()558 559 def enter_payment_schedule(self, *args):560 """Enter values into corresponding fields in Levels page""" 561 #if name == "Payments":562 #id = ["paymentCount","intervals","intervalunits"]563 id = ["paymentCount","vfForm:intervalnumber","intervalunits"]564 for i in range(len(args)):565 locator = npsp_lex_locators['id'].format(id[i])566 loc = self.selenium.get_webelement(locator)567 self.selenium.set_focus_to_element(locator) 568 self.selenium.select_from_list_by_label(loc,args[i])569 time.sleep(2) 570 571 def verify_payment_split(self, amount, no_payments):572 loc = "//*[@id='pmtTable']/tbody/tr/td[2]/div//input[@value= '{}']"573 values = int(amount)/int(no_payments)574 #global self.val575 values_1 = "{0:.2f}".format(values)576 self.val = str(values_1)577 locator = loc.format(self.val)578 list_payments = self.selenium.get_webelements(locator)579 self.t_loc=len(list_payments)580 if self.t_loc == int(no_payments):581 for i in list_payments:582 self.selenium.page_should_contain_element(i) 583 return str(self.t_loc)584 else:585 return str(self.t_loc)586 587 def verify_date_split(self,date, no_payments, interval): 588 ddate=[] 589 mm, dd, yyyy = date.split("/")590 mm, dd, yyyy = int(mm), int(dd), int(yyyy)591 locator = npsp_lex_locators['payments']['date_loc'].format(date)592 t_dates = self.selenium.get_webelement(locator)593 self.selenium.page_should_contain_element(t_dates)594# for i in range(int(no_payments) + 1):595 if mm <= 12:596 date_list = [mm, dd, yyyy]597 dates = list(map(str, date_list))598 new_date = "/".join(dates)599 mm = mm + int(interval)600 dates = list(map(str, date_list))601 #if new_date not in t_dates: 602 locator1 = npsp_lex_locators['payments']['date_loc'].format(new_date)603 t_dates = self.selenium.get_webelement(locator1) 604 self.selenium.page_should_contain_element(t_dates)605 elif mm > 12:606 yyyy = yyyy + 1607 mm = (mm + int(interval))-(12+int(interval))608 #return "pass"609# else:610# return "fail"611 612 def click_viewall_related_list (self,title): 613 """clicks on the View All link under the Related List""" 614 locator=npsp_lex_locators['record']['related']['viewall'].format(title)615 self.selenium.get_webelement(locator).click()616 617 def click_button_with_value (self,title): 618 """clicks on the button on the payments page""" 619 locator=npsp_lex_locators['button'].format(title)620 self.selenium.get_webelement(locator).click()621 622# 623# def verify_payments(self, amount,no_payments):624# """To select a row on object page based on name and open the dropdown"""625# locators = npsp_lex_locators['payments']['no_payments']626# list_ele = self.selenium.get_webelements(locators)627# t_count=len(list_ele)628# for index, element in enumerate(list_ele):629# if element.text == amount:630# loc = npsp_lex_locators['payments']['pay_amount'].format(index + 1, amount)631# self.selenium.page_should_contain_element(loc)632# time.sleep(1)633 634 def verify_occurrence_payments(self,title,value=None):635 """"""636 locator=npsp_lex_locators['payments']['check_occurrence'].format(title)637 occ_value=self.selenium.get_webelement(locator).text638 return occ_value 639 640 641 def verify_payment(self):642 locators=npsp_lex_locators['payments']['no_payments']643 list_ele=self.selenium.get_webelements(locators)644 l_no_payments = len(list_ele)645 #return list_ele646 #return l_no_payments, self.t_loc647 #if self.t_loc == l_no_payments:648 for element in list_ele:649 payment_com=self.selenium.get_webelement(element).text650 cc=payment_com.replace("$","")651 if cc == str(self.val) and self.t_loc == l_no_payments :652 return 'pass'653 #return cc, self.val654 else:655 return "fail"656 657 def select_value_from_list(self,list_name,value): 658 locator = npsp_lex_locators['npsp_settings']['list'].format(list_name)659 loc = self.selenium.get_webelement(locator)660 self.selenium.set_focus_to_element(locator) 661 self.selenium.select_from_list_by_label(loc,value) 662 663 def select_value_from_bge_dd(self,list_name,value):664 """Pass the list name and value to be selected from the dropdown"""665 if list_name == 'Payment Method': 666 locator = npsp_lex_locators['bge']['dd'].format(list_name)667 loc = self.selenium.get_webelement(locator)668 self.selenium.set_focus_to_element(locator) 669 self.selenium.select_from_list_by_label(loc,value) 670 else:671 locator = npsp_lex_locators['bge']['list'].format(list_name)672 loc = self.selenium.get_webelement(locator)673 self.selenium.set_focus_to_element(locator) 674 self.selenium.select_from_list_by_label(loc,value) 675 676 def select_multiple_values_from_list(self,list_name,*args): 677 """Pass the list name and values to be selected from the dropdown. Please note that this doesn't unselect the existing values"""678 locator = npsp_lex_locators['npsp_settings']['multi_list'].format(list_name)679 loc = self.selenium.get_webelement(locator)680 self.selenium.set_focus_to_element(locator) 681 self.selenium.select_from_list_by_label(loc,*args) 682 683 def choose_frame(self, value):684 """Returns the first displayed iframe on the page with the given name or title"""685 locator = npsp_lex_locators['frame_new'].format(value,value)686 frames = self.selenium.get_webelements(locator)687 for frame in frames:688 if frame.is_displayed():689 self.selenium.select_frame(frame)690 return frame691 raise Exception('unable to find visible iframe with title "{}"'.format(value))692 def select_frame_and_click_element(self,iframe,path, *args, **kwargs):693 """Selects the first displayed frame with given name or title and scrolls to element identified by locator and clicks """694 self.choose_frame(iframe)695 loc = self.get_npsp_locator(path, *args, **kwargs)696 self.selenium.wait_until_element_is_visible(loc, timeout=60)697 self.selenium.scroll_element_into_view(loc)698 self.selenium.click_element(loc)699 700 701 def get_npsp_locator(self, path, *args, **kwargs):702 """ Returns a rendered locator string from the npsp_lex_locators703 dictionary. This can be useful if you want to use an element in704 a different way than the built in keywords allow.705 """ 706 locator = npsp_lex_locators707 for key in path.split('.'):708 locator = locator[key]709 main_loc = locator.format(*args, **kwargs)710 return main_loc 711 def wait_for_locator(self, path, *args, **kwargs):712 """Waits for 60 sec for the specified locator"""713 main_loc = self.get_npsp_locator(path,*args, **kwargs) 714 self.selenium.wait_until_element_is_visible(main_loc, timeout=90)715 def get_npsp_settings_value(self,field_name): 716 locator = npsp_lex_locators['npsp_settings']['field_value'].format(field_name)717 loc = self.selenium.get_webelement(locator).text 718 return loc 719 720 def click_panel_sub_link (self,title): 721 """clicks on the button on the payments page""" 722 locator=npsp_lex_locators['npsp_settings']['panel_sub_link'].format(title)723 self.selenium.get_webelement(locator).click()724 725 def click_settings_button (self,panel_id,btn_value): 726 """clicks on the buttons on npsp settings object using panel id and button value""" 727 locator=npsp_lex_locators['npsp_settings']['batch-button'].format(panel_id,btn_value)728 self.selenium.click_element(locator) 729 730 731 732 def verify_payment_details(self):733 locator = "//tbody/tr/td[2]/span/span"734 locs1 = self.selenium.get_webelements(locator)735 locator2 = "//tbody/tr/td[3]/span/span"736 locs2 = self.selenium.get_webelements(locator2)737 for i, j in list(zip(locs1, locs2)):738 #loc1_vaue = self.selenium.get_webelemt(i).text739 #loc2_vaue = self.selenium.get_webelemt(j).text740 if i.text == "Pledged" and j.text == "$100.00":741 pass742 else:743 return "fail"744 return len(locs1)745 # def verify_opportunities(self, len_value):746 # locator = "//tbody/tr[12]/th"747 # s = self.selenium.get_webelement(locator).text748 # #return s749 # strip_list = s.split(" ")750 # date = strip_list[-1]751 # date = date.split("/")752 # date = list(map(int, date))753 # mm, dd, yyyy = date754 # for _ in range(int(len_value)):755 # if mm == 12:756 # mm = 1757 # yyyy = yyyy + 1758 # date = [mm, dd, yyyy]759 # date = list(map(str, date))760 # date = "/".join(date)761 # loctor_contains = "//tbody//a[contains(@title , '{}')]".format(date)762 # self.selenium.page_should_contain_element(loctor_contains) 763 # else:764 # mm = mm + 1765 # date = [mm, dd, yyyy]766 # date = list(map(str, date))767 # date = "/".join(date)768 # loctor_contains = "//tbody//a[contains(@title , '{}')]".format(date)769 # self.selenium.page_should_contain_element(loctor_contains)770 def click_object_manager_button(self,title): 771 """clicks on the buttons in object manager""" 772 locator=npsp_lex_locators['object_manager']['button'].format(title)773 self.selenium.get_webelement(locator).click() 774 775 def click_bge_button(self,text): 776 """clicks on buttons for BGE""" 777 locator=npsp_lex_locators['bge']['button'].format(text)778 #self.selenium.get_webelement(locator).click()779 self.selenium.click_button(locator) 780 781 def verify_title(self,title,value):782 """"""783 locator=npsp_lex_locators['bge']['title'].format(title,value)784 actual_value=self.selenium.get_webelement(locator).text785 assert value == actual_value, "Expected value to be {} but found {}".format(786 value, actual_value787 ) 788 789 def page_scroll_to_locator(self, path, *args, **kwargs):790 locator = self.get_npsp_locator(path, *args, **kwargs)791 self.selenium.scroll_element_into_view(locator) 792 def get_bge_card_header(self,title): 793 """Validates if the specific header field has specified value""" 794 locator= npsp_lex_locators['bge']['card-header'].format(title)795 id=self.selenium.get_webelement(locator).text 796 return id 797 798 def click_bge_edit_button(self, title): 799 """clicks the button in the table by using name mentioned in data-label"""800 locator=npsp_lex_locators['bge']['edit_button'].format(title)801 #self.selenium.get_webelement(locator).click()802 self.selenium.click_button(locator)803 804 def populate_bge_edit_field(self, title, value):805 """Clears the data in input field and enters the value specified """806 locator=npsp_lex_locators['bge']['edit_field'].format(title)807 field=self.salesforce._populate_field(locator, value)808 809 810 def verify_row_count(self,value):811 """verifies if actual row count matches with expected value"""812 locator=npsp_lex_locators['bge']['count']813 actual_value=self.selenium.get_webelements(locator)814 count=len(actual_value)815 assert int(value) == count, "Expected value to be {} but found {}".format(816 value, count817 ) 818 819 def return_locator_value(self, path, *args, **kwargs): 820 """Returns the value pointed by the specified locator"""821 locator=self.get_npsp_locator(path, *args, **kwargs)822 value=self.selenium.get_webelement(locator).text 823 return value824 def select_bge_row(self, value):825 """To select a row on object page based on name and open the dropdown"""826 locators = npsp_lex_locators['bge']['name']827 list_ele = self.selenium.get_webelements(locators)828 for index, element in enumerate(list_ele):829 if element.text == value:830 drop_down = npsp_lex_locators['bge']['locate_dropdown'].format(index+1)831 self.selenium.click_element(drop_down)832 time.sleep(1)833 def click_link_with_text(self, text):834 self.builtin.log("This test is using the 'Click link with text' workaround", "WARN")835 element = self.selenium.driver.find_element_by_link_text(text)836 self.selenium.driver.execute_script('arguments[0].click()', element) 837 838 def verify_expected_batch_values(self, batch_id,**kwargs):839 """To verify that the data in Data Import Batch matches expected value provide batch_id and the data u want to verify""" 840 ns=self.get_npsp_namespace_prefix()841 table=ns + "DataImportBatch__c"842 bge_batch=self.salesforce.salesforce_get(table,batch_id)843 for key, value in kwargs.items():844 label=ns + key845 self.builtin.should_be_equal_as_strings(bge_batch[label], value)846 847 def click_element_with_locator(self, path, *args, **kwargs):848 """Pass the locator and its values for the element you want to click """849 locator=self.get_npsp_locator(path, *args, **kwargs) 850 self.selenium.click_element(locator) 851 852 def wait_for_record_to_update(self, id, value):853 """Waits for specified record header to be updated by checking every second for 10 times.854 """855 i = 0856 while True:857 i += 1858 if i > 10:859 raise AssertionError(860 "Timed out waiting for record name to be {} .".format(value)861 )862 self.salesforce.go_to_record_home(id)863 try:864 self.verify_header(value)865 break866 except Exception:867 time.sleep(1)868 869 def load_locator(self, path, *args, **kwargs):870 """Scrolls down until the specified locator is found.871 """872 locator = self.get_npsp_locator(path, *args, **kwargs)873 i = 0874 while True:875 i += 1876 if i > 20:877 raise AssertionError(878 "Timed out waiting for locator {} to load.".format(locator)879 )880 self.selenium.execute_javascript("window.scrollBy(0, 100)")881 self.wait_for_aura()882 try:883 self.selenium.get_webelement(locator)884 break885 except ElementNotFound:886 time.sleep(0.2)887 ...
base.py
Source:base.py
...13 def go_to(self, base_url):14 """navigate to the given url"""15 self.log.info(f"Navigating to {base_url}")16 return self.driver.get(base_url)17 def get_webelement(self, by_locator):18 """finds and returns the element located using the locator"""19 self.log.info(f"Finding element with locator {by_locator[0]}:{by_locator[1]}")20 return self.driver.find_element(*by_locator)21 def input_text(self,by_locator,text):22 self.log.info(f"Entering text {text} into the field with locator {by_locator[0]}:{by_locator[1]}")23 self.get_webelement(by_locator).send_keys(text)24 25 def click_element(self,by_locator):26 self.log.info(f"Clicking element with locator {by_locator[0]}:{by_locator[1]}")27 self.get_webelement(by_locator).click()28 def get_text(self, by_locator):29 """returns the text from a specific element"""30 text = self.get_webelement(by_locator).text31 self.log.info(f"Element with locator {by_locator[0]}:{by_locator[1]} has text: {text}")32 return text33 def is_element_visible(self, by_locator):34 """returns if the element located using the given locator is visbile or not"""35 try:36 return self.get_webelement(by_locator).is_displayed()37 except NoSuchElementException:38 return False39 40 def wait_until_element_is_visible(self, by_locator):41 """waits until the element located using the given locator is visible on the page"""42 self.log.info(f"Waiting until element with locator {by_locator[0]}:{by_locator[1]} is visible")43 return WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((by_locator)))44 def get_page_url(self):...
Delivery.py
Source:Delivery.py
...12 "[//div[contains(@class,'uiMenu')]//"13 "a[@class='select']]"14 ).format(title)15 self.selenium.set_focus_to_element(locator)16 self.selenium.get_webelement(locator).click()17 def pick_date(self, value):18 """To pick a date from the date picker"""19 locator = (20 "//div[contains(@class,'uiDatePickerGrid')]/"21 "table[@class='calGrid']//"22 "span[text()='{}']"23 ).format(value)24 self.selenium.set_focus_to_element(locator)25 self.selenium.get_webelement(locator).click()26 def populate_picklist(self, name, value):27 locator_picklist = (28 "//div[contains(@class, 'uiInput')]"29 "[.//span[contains(@class, 'uiPicklistLabel')]"30 "[.//span[text()='{}']]]//div"31 ).format(name)32 locator_value = (33 "//div[contains(@class, 'uiMenuList') and contains(@class, 'visible')]"34 "//div//ul//li//a[text()='{}']"35 ).format(value)36 self.selenium.set_focus_to_element(locator_picklist)37 picklist = self.selenium.get_webelement(locator_picklist)38 picklist.click()39 self.selenium.set_focus_to_element(locator_value)40 picklist_value = self.selenium.get_webelement(locator_value)...
agencies_list_parser.py
Source:agencies_list_parser.py
...18 def _get_name(self, agency):19 self.browser.wait_until_element_is_visible(20 locator=[agency, 'css:span:nth-of-type(1)']21 )22 return self.browser.get_webelement(23 locator=[agency, 'css:span:nth-of-type(1)']24 )25 def _get_spending(self, agency):26 self.browser.wait_until_element_is_visible(27 locator=[agency, 'css:span:nth-of-type(2)']28 )29 return self.browser.get_webelement(30 locator=[agency, 'css:span:nth-of-type(2)']31 )32 def _get_information(self):33 agencies = self._get_agencies()34 helper = XlsxSaver(35 worksheet='Agencies',36 path='output/Agencies.xlsx'37 )38 row = 139 for agency in agencies:40 spending = self._get_spending(agency).text41 helper._fill_row(row, "A", spending)42 row += 143 helper._save_workbook()44 def _get_agency_link(self, id):45 agency = self._get_agencies()[id]46 link = self.browser.get_webelement(47 locator=[agency, 'css:div>div>div>a']48 )...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!