def edit_address(driver, id): address_field = driver.find_element_by_name("addr") prsentaddr = address_field.text address_field.clear() driver.implicitly_wait(1) to_update_addr = prsentaddr + " A" address_field.send_keys(to_update_addr) driver.find_element_by_name("sub").click() driver.implicitly_wait(1) msg = driver.find_element_by_xpath( "//*[@id='customer']/tbody/tr[1]/td/p").text if "Customer details updated Successfully!!!" in msg: print(msg) add_filed = driver.find_element_by_xpath( "//*[@id='customer']/tbody/tr[8]/td[2]") updated_address = add_filed.text if prsentaddr != updated_address: print("New Address got updated in Bank app for " + id) else: print("Address wrongly updated or not updated") driver.implicitly_wait(1) col, row = Excelutility.search_value_in_column( TC_EditCustmerTest.Path, TC_EditCustmerTest.SheetToStore, id, "A") # print("col,row:",col,row) Excelutility.write_data(TC_EditCustmerTest.Path, TC_EditCustmerTest.SheetToStore, row, 5, updated_address) changed_val_in_xl = Excelutility.read_data( TC_EditCustmerTest.Path, TC_EditCustmerTest.SheetToStore, row, 5) if changed_val_in_xl == updated_address: print("New Address got updated in excel for " + id)
def edit_account_type(driver): present_acc_type = TC_EditAccountTest.get_current_account_type(driver) print("Present Account type is:", present_acc_type) # Set the string as exactly differnt than present to_update_acc_type = None if present_acc_type == "Current": to_update_acc_type = "Savings" elif present_acc_type == "Savings": to_update_acc_type = "Current" print("To update with :", to_update_acc_type) # select the value as per to_update_acc_type veriable select = Select(driver.find_element_by_name("a_type")) select.select_by_value(to_update_acc_type) time.sleep(1) driver.find_element_by_name("AccSubmit").click() time.sleep(1) msg = driver.find_element_by_xpath( "//*[@id='account']/tbody/tr[1]/td/p").text if "Account details updated Successfully!!!" in msg: print(msg) updated_acc_type = driver.find_element_by_xpath( "//*[@id='account']/tbody/tr[8]/td[2]" ).text #self.get_current_account_type() print("After Update: " + updated_acc_type) if present_acc_type != updated_acc_type: print("Account type got updated in Bank app with " + updated_acc_type) else: print("Account type not updated with " + updated_acc_type) acc_id = driver.find_element_by_xpath( "//*[@id='account']/tbody/tr[4]/td[2]").text col, row = Excelutility.search_value_in_column( TC_EditAccountTest.Path, TC_EditAccountTest.Sheet_Name, acc_id, "B") print("col,row:", col, row) Excelutility.write_data(TC_EditAccountTest.Path, TC_EditAccountTest.Sheet_Name, row, 3, updated_acc_type) changed_val_in_xl = Excelutility.read_data( TC_EditAccountTest.Path, TC_EditAccountTest.Sheet_Name, row, 3) if changed_val_in_xl == updated_acc_type: print("New account type got updated in excel with type " + updated_acc_type)
def create_dummy_account(driver): total_row = Excelutility.get_row_count(TC_DeleteAccountTest.Path,TC_DeleteAccountTest.Sheet_Name) print("Total Row:",total_row) last_cust_id = Excelutility.read_data(TC_DeleteAccountTest.Path,TC_DeleteAccountTest.Sheet_Name,total_row,1) print("Last Cust Id :",last_cust_id) BankAPP_CommonFunctions.close_popup(driver) BankAPP_CommonFunctions.click_menu_by_perform_mouse_action(driver, "New Acc", "new account") TC_AddAccountTest.add_account_details(driver,last_cust_id,"Savings",3000) TC_AddAccountTest.validate_account_info(driver,"Savings",3000) total_row_after_addition = Excelutility.get_row_count(TC_DeleteAccountTest.Path, TC_DeleteAccountTest.Sheet_Name) print("Total row in excel after adding new account:",total_row_after_addition) account_id_to_delete = Excelutility.read_data(TC_DeleteAccountTest.Path,TC_DeleteAccountTest.Sheet_Name, total_row_after_addition,2) print("Account Id to delete is :",account_id_to_delete) return account_id_to_delete
def select_gender(driver, gender): radios = None if gender.lower() == "m": radios = driver.find_element_by_xpath( "/html/body/table/tbody/tr/td/table/tbody/tr[5]/td[2]/input[1]" ) elif gender.lower() == "f": radios = driver.find_element_by_xpath( "/html/body/table/tbody/tr/td/table/tbody/tr[5]/td[2]/input[2]" ) else: print("Wrong input!!!") radios.click() time.sleep(1) if radios.is_selected(): print("Gender " + radios.get_property("value").upper() + " got selected") else: print("Failed to select :" + radios.get_property("value").upper()) Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 2, radios.get_property("value").upper()) return radios.get_property("value").upper()
def search_acc_BYID_Delete(driver, id, action): driver.find_element_by_name("accountno").send_keys(id) driver.find_element_by_css_selector("input[name='AccSubmit']").click() time.sleep(2) msg = driver.switch_to.alert.text if "Do you really want to delete this Account?" in msg and action == "No": print(msg) driver.switch_to.alert.dismiss() elif "Do you really want to delete this Account?" in msg and action == "Yes": print(msg) driver.switch_to.alert.accept() wait = WebDriverWait(driver, 35) wait.until(EC.alert_is_present(), 'Timed out waiting for PA creation ' + 'confirmation popup to appear.') msgon_deletion = driver.switch_to.alert.text if "Account does not exist" in msgon_deletion: print(msgon_deletion) driver.switch_to.alert.accept() elif "Account Deleted Sucessfully" in msgon_deletion: print(msgon_deletion) driver.switch_to.alert.accept() driver.implicitly_wait(1) col, row = Excelutility.search_value_in_column(TC_DeleteAccountTest.Path, TC_DeleteAccountTest.Sheet_Name, id, "B") print("Row {0},Col {1}:".format(row, col)) total_row = Excelutility.get_row_count(TC_DeleteAccountTest.Path, TC_DeleteAccountTest.Sheet_Name) print("Total Row :", total_row) if row != None: Excelutility.delete_row(TC_DeleteAccountTest.Path, TC_DeleteAccountTest.Sheet_Name, row, 1) if Excelutility.get_row_count(TC_DeleteAccountTest.Path, TC_DeleteAccountTest.Sheet_Name) == total_row - 1 and Excelutility.read_data( TC_DeleteAccountTest.Path, TC_DeleteAccountTest.Sheet_Name, row, 1) != id: print(id + " got deleted from xls") elif Excelutility.get_row_count(TC_DeleteAccountTest.Path, TC_DeleteAccountTest.Sheet_Name) == total_row: print(id + " not found in excel or already deleted!!!")
def validate_account_info(driver, account_type, initial_amount): if "Account Generated Successfully!!!" in driver.find_element_by_xpath( "//*[@id='account']/tbody/tr[1]/td/p").text: print("Added Account successfully") row = Excelutility.get_row_count(TC_AddAccountTest.Path, TC_AddAccountTest.Sheet_Name) acc_id = driver.find_element_by_xpath( "//*[@id='account']/tbody/tr[4]/td[2]").text Excelutility.write_data(TC_AddAccountTest.Path, TC_AddAccountTest.Sheet_Name, row + 1, 2, acc_id) cust_id = driver.find_element_by_xpath( "//*[@id='account']/tbody/tr[5]/td[2]").text Excelutility.write_data(TC_AddAccountTest.Path, TC_AddAccountTest.Sheet_Name, row + 1, 1, cust_id) store_accid_custid(acc_id, cust_id) col_inCustID, row_inCustID = Excelutility.search_value_in_column( TC_AddAccountTest.Path, TC_AddAccountTest.Sheet_Verify, cust_id, "A") cust_name = driver.find_element_by_xpath( "//*[@id ='account']/tbody/tr[6]/td[2]").text cust_nameFromXl = Excelutility.read_data( TC_AddAccountTest.Path, TC_AddAccountTest.Sheet_Verify, row_inCustID, 2) if cust_name == cust_nameFromXl: print(cust_name + " is matching Of id " + cust_id + " from " + TC_AddAccountTest.Sheet_Verify) else: print("Customer name is not matching") TC_AddAccountTest.assertTrue( cust_name == cust_nameFromXl, cust_name + " is matching with id " + cust_id) cust_mail = driver.find_element_by_xpath( "//*[@id ='account']/tbody/tr[7]/td[2]").text cust_mailFromXl = Excelutility.read_data( TC_AddAccountTest.Path, TC_AddAccountTest.Sheet_Verify, row_inCustID, 10) if cust_mail == cust_mailFromXl: print(cust_mail + " is matching of id " + cust_id + " from " + TC_AddAccountTest.Sheet_Verify) else: print("Customer mail is not matching") TC_AddAccountTest.assertTrue( cust_mail == cust_mailFromXl, cust_mail + " is matching with id " + cust_id) acc_type = driver.find_element_by_xpath( "//*[@id ='account']/tbody/tr[8]/td[2]").text if acc_type == account_type: Excelutility.write_data(TC_AddAccountTest.Path, TC_AddAccountTest.Sheet_Name, row + 1, 3, acc_type) else: print("Account type is not matching") date_of_opening = driver.find_element_by_xpath( "//*[@id ='account']/tbody/tr[9]/td[2]").text Excelutility.write_data(TC_AddAccountTest.Path, TC_AddAccountTest.Sheet_Name, row + 1, 4, date_of_opening) cur_amount = driver.find_element_by_xpath( "//*[@id='account']/tbody/tr[10]/td[2]").text #print(cur_amount) #print(initial_amount) if int(cur_amount) == int(initial_amount): print("Initial amount added " + cur_amount) Excelutility.write_data(TC_AddAccountTest.Path, TC_AddAccountTest.Sheet_Name, row + 1, 5, cur_amount) else: print("Initial amount is not matching") print("Validation is done for added account " + acc_id + " of type " + acc_type + " Successfully!!!")
def login_with_diff_credentials(driver, excel_path, excel_sheet, app_url): rows = Excelutility.get_row_count(excel_path, excel_sheet) # self.site_open() for row in range(2, rows + 1): print(row) username = Excelutility.read_data(excel_path, excel_sheet, row, 1) print("Current username:"******"Current Password:"******"uid").send_keys(username) driver.find_element_by_name("password").send_keys(password) time.sleep(1) error = "Shri" try: driver.find_element_by_xpath( "/html/body/form/table/tbody/tr[3]/td[2]/input[1]").click( ) time.sleep(1) if BankAPP_CommonFunctions.get_modal_alert(driver): error = driver.switch_to.alert.text driver.switch_to.alert.accept() print("Login Failed with :", error) Excelutility.write_data(excel_path, excel_sheet, row, 3, "Test Failed") else: if "Guru99 Bank Manager HomePage" in driver.title: print("Login is successful") Excelutility.write_data(excel_path, excel_sheet, row, 3, "Test Passed") else: print("Failed to login") Excelutility.write_data(excel_path, excel_sheet, row, 3, "Test Failed") except Exception as e: print('Error on line {}'.format(sys.exc_info()[-1].tb_lineno), type(e).__name__, e) # print("Failed to login as", error) Excelutility.write_data(excel_path, excel_sheet, row, 3, "Test Failed") driver.refresh() driver.get(app_url) driver.set_page_load_timeout(10) finally: print("Completed Iteration with excel row no :", row) if "User or Password is not valid" not in error: BankAPP_CommonFunctions.close_popup(driver) driver.execute_script( "window.scrollBy(0,document.body.scrollHeight)") time.sleep(1) BankAPP_CommonFunctions.logout(driver) # def test_validationNavigation(self): # self.login_with_diff_credentials(self.driver,self.Path,self.SheetName,self.url) # @classmethod # def tearDownClass(cls): # cls.driver.close() # if __name__ == "__main__": # unittest.main()
def validate_custinfo(driver): if "Customer Registered Successfully!!!" in driver.find_element_by_xpath( "//*[@id='customer']/tbody/tr[1]/td/p").text: print("Customer registered successfully") row = Excelutility.get_row_count(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetToStore) cust_id = driver.find_element_by_xpath( "//*[@id='customer']/tbody/tr[4]/td[2]").text #global_cust_id = cust_id store_custid(cust_id) Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetToStore, row + 1, 1, cust_id) cust_name = driver.find_element_by_xpath( "//*[@id ='customer']/tbody/tr[5]/td[2]").text cust_nameFromXl = Excelutility.read_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 1) if cust_name == cust_nameFromXl: Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetToStore, row + 1, 2, cust_name) else: print(cust_name + " is not same as " + cust_nameFromXl + " added") cust_gender = driver.find_element_by_xpath( "//*[@id ='customer']/tbody/tr[6]/td[2]").text #print(cust_gender) cust_genderFromXl = Excelutility.read_data( TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 2) gen_fromxl = TC_AddCustomerTest.gender_fullform(cust_genderFromXl) if cust_gender == gen_fromxl: Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetToStore, row + 1, 3, cust_gender) else: print(cust_gender + " is not same as " + cust_genderFromXl + " added") cust_dob = driver.find_element_by_xpath( "//*[@id ='customer']/tbody/tr[7]/td[2]").text cust_dobFromXl = Excelutility.read_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 3) x = TC_AddCustomerTest.date_Conversion(cust_dobFromXl) #print(x) if cust_dob == x: Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetToStore, row + 1, 4, cust_dob) else: print(cust_dob + " is not same as " + cust_dobFromXl + " added") cust_addr = driver.find_element_by_xpath( "//*[@id ='customer']/tbody/tr[8]/td[2]").text cust_addrFromXl = Excelutility.read_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 4) if cust_addr == re.sub(' +', ' ', cust_addrFromXl): #cust_addrFromXl: Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetToStore, row + 1, 5, cust_addr) else: print(cust_addr + " is not same as " + cust_addrFromXl + " added") cust_city = driver.find_element_by_xpath( "//*[@id ='customer']/tbody/tr[9]/td[2]").text cust_cityFromXl = Excelutility.read_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 5) if cust_city == cust_cityFromXl: Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetToStore, row + 1, 6, cust_city) else: print(cust_city + " is not same as " + cust_cityFromXl + " added") cust_state = driver.find_element_by_xpath( "//*[@id ='customer']/tbody/tr[10]/td[2]").text cust_stateFromXl = Excelutility.read_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 6) if cust_state == cust_stateFromXl: Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetToStore, row + 1, 7, cust_state) else: print(cust_state + " is not same as " + cust_stateFromXl + " added") cust_pin = driver.find_element_by_xpath( "//*[@id ='customer']/tbody/tr[11]/td[2]").text cust_pinFromXl = Excelutility.read_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 7) if cust_pin == cust_pinFromXl: Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetToStore, row + 1, 8, cust_pin) else: print(cust_pin + " is not same as " + cust_pinFromXl + " added") cust_mobile = driver.find_element_by_xpath( "//*[@id ='customer']/tbody/tr[12]/td[2]").text cust_mobileFromXl = Excelutility.read_data( TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 8) if cust_mobile == cust_mobileFromXl: Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetToStore, row + 1, 9, cust_mobile) else: print(cust_mobile + " is not same as " + cust_mobileFromXl + " added") cust_mail = driver.find_element_by_xpath( "//*[@id ='customer']/tbody/tr[13]/td[2]").text cust_mailFromXl = Excelutility.read_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 9) if cust_mail == cust_mailFromXl: Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetToStore, row + 1, 10, cust_mail) else: print(cust_mail + " is not same as " + cust_mailFromXl + " added") print("Validation is done for added customer with id " + cust_id + " " + cust_name + " Successfully!!!") Excelutility.delete_row(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 1) TC_AddCustomerTest.assertTrue( Excelutility.get_row_count(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName) == 1, "Temp Profile got deleted!!!")
def add_password(driver, password): driver.find_element_by_xpath( "/html/body/table/tbody/tr/td/table/tbody/tr[13]/td[2]/input" ).send_keys(password) Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 10, password)
def add_mail(driver, mail): driver.find_element_by_xpath( "/html/body/table/tbody/tr/td/table/tbody/tr[12]/td[2]/input" ).send_keys(mail) Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 9, mail)
def add_phoneno(driver, phoneno): driver.find_element_by_xpath( "/html/body/table/tbody/tr/td/table/tbody/tr[11]/td[2]/input" ).send_keys(phoneno) Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 8, phoneno)
def add_state(driver, state): driver.find_element_by_xpath( "/html/body/table/tbody/tr/td/table/tbody/tr[9]/td[2]/input" ).send_keys(state) Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 6, state)
def add_city(driver, city): driver.find_element_by_xpath( "/html/body/table/tbody/tr/td/table/tbody/tr[8]/td[2]/input" ).send_keys(city) Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 5, city)
def add_address(driver, address): driver.find_element_by_xpath( "/html/body/table/tbody/tr/td/table/tbody/tr[7]/td[2]/textarea" ).send_keys(address) Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 4, address)
def add_dateBirth(driver, date): driver.find_element_by_xpath("//*[@id='dob']").send_keys(date) Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 3, date)
def cust_name(driver, name): name_filed = driver.find_element_by_xpath( "/html/body/table/tbody/tr/td/table/tbody/tr[4]/td[2]/input") name_filed.send_keys(name) Excelutility.write_data(TC_AddCustomerTest.Path, TC_AddCustomerTest.SheetName, 2, 1, name)