def select_cell_range_via_drag(drag_direction, number_of_cells_to_drag, sheet, range): drag_direction = pwa_directional_command_dictionary[drag_direction] cells_dragged = 1 xwu.ensure_focus(sheet, range) while cells_dragged < number_of_cells_to_drag: pwa.keyboard.send_keys('+' + drag_direction) cells_dragged += 1
def set_subcategory_db_values(self): category_group_metakey_tuple = ('CategoryGroup', None, None) sub_category_metakey_tuple = ('SubCategory', None, None) first_data_row = xwu.find_first_data_row(self.tracker_data_tab) category_group_valid_values_list = xwu.dropdown_decoder(self.tracker_data_tab.range(first_data_row, self.tracker_data_metakey_col_dict[category_group_metakey_tuple])) for category_group in category_group_valid_values_list: self.tracker_data_tab.range(first_data_row, self.tracker_data_metakey_col_dict[category_group_metakey_tuple]).value = category_group sub_category_valid_values = fc.get_sub_category_list_from_category_group(self.book, category_group) for sub_category in sub_category_valid_values: xwu.ensure_focus(self.tracker_data_tab, self.tracker_data_tab.range(first_data_row, self.tracker_data_metakey_col_dict[sub_category_metakey_tuple])) pwa.keyboard.send_keys(str(sub_category) + '~')
def test_field_lock(ticket_id, test_description, expected_result, book_test, sheet, field_to_test): actual_result = "" test_status = None # target metakey column number target_field_col_number = xwu.find_col_by_multi_metakey([field_to_test], sheet) first_data_row = xwu.find_first_data_row(sheet) row_number_insert = xwu.get_insert_data_row_number(sheet) for test_execution in range(3): selected_row = rnd.randint(first_data_row, row_number_insert) # record the current target data value initial_target_line_data = sheet.range(selected_row, target_field_col_number).value # send keys to line number cell book_test.clicker.setup("OK") updated_target_line_data = fc.gen_line_desc() xwu.ensure_focus(sheet, sheet.range(selected_row, target_field_col_number)) pwa.keyboard.send_keys(updated_target_line_data + "~") time.sleep(4) # check that an error message appeared and the data remains unchanged if book_test.clicker.click_count == 0: test_status = 0 actual_result = "The error message did not appear for column " + field_to_test + "for at least one instance. " if sheet.range( selected_row, target_field_col_number).value != initial_target_line_data: test_status = 0 actual_result = actual_result + "For at least one test instance the value in field " + field_to_test + " has changed" if test_status == 0: pass else: test_status = 1 actual_result = "Error messages appeared for the field " + field_to_test + " and the " + field_to_test + " field remains unchanged" # Write the test to the database logger.write_result(ticket_id, test_description, expected_result, actual_result, test_status)
def paste_cells_to_range(sheet, range): xwu.ensure_focus(sheet, range) pwa.keyboard.send_keys('^' + 'v')
def copy_cells_from_range(sheet, range): xwu.ensure_focus(sheet, range) pwa.keyboard.send_keys('^' + 'c')
def test_line_level_field(ticket_id, test_description, expected_result, field_to_test): """ SUMMARY: Ensure data cannot be changed in especific columns received as paramedters. As an expected result, an error message must appear in the screen and the data remains unchanged DETAILS: Opens Order Sheet workbook and runs Reset macro Reads the column for the especific field to test in the first data sheet Gets the first row with data in a range Gets the first row available for insert in a range Runs 10 times a test getting a row at random and attempts to write a value Check if the script changed the data or an screen error appeared and the data remains unchanged. Write the test result to the database NOTES: This script will generate error messages in the screen and will attemp to answer them. Thus, the focus should always be hold by the worksheet, so using the keyboard during the test will make the script to fail. """ #set up the ordersheet with tinysheet2 data book_test = setup_order_sheet(parameter_path) global pid pid = book_test.process_id #tab object ts2_tab1 = book_test.order_sheet.sheets[ book_test.excel_book_parameters['OrderSheet Tabs'][0]] #target metakey column number target_field_col_number = xwu.find_col_by_multi_metakey([field_to_test], ts2_tab1) first_data_row = xwu.find_first_data_row(ts2_tab1) row_number_insert = xwu.get_insert_data_row_number(ts2_tab1) #run test 10 times for the target field (different rows) for test_execution in range(10): #select row number selected_row = rnd.randint(first_data_row, row_number_insert) #record the current target data value initial_target_line_data = ts2_tab1.range( selected_row, target_field_col_number).value #send keys to line number cell book_test.clicker.setup("OK") updated_target_line_data = fc.gen_line_desc() xwu.ensure_focus(ts2_tab1, ts2_tab1.range(selected_row, target_field_col_number)) pwa.keyboard.send_keys(updated_target_line_data + "~") time.sleep(3) #check that an error message appeared and the data remains unchanged print(book_test.clicker.click_count) if book_test.clicker.click_count == 0: test_status = 0 actual_result = "For at least one test instance the error message did not appear, " if ts2_tab1.range( selected_row, target_field_col_number).value != initial_target_line_data: test_status = 0 actual_result = "For at least one test instance the value in field " + field_to_test + " has changed" try: if test_status == 0: pass except: test_status = 1 actual_result = "Error messages appeared and the " + field_to_test + " field remains unchanged" #Write the test to the database logger.write_result(ticket_id, test_description, expected_result, actual_result, test_status) #Close the ordersheet/clicker thread book_test.clicker.shut_down() book_test.order_sheet.close()