def test_3_delete_confirm_success(self): print(colored('Running: test_3_delete_confirm_success - estimate: 15s', 'yellow')) for i in range(3): print(colored('\trandom meter ' + str(i + 1), 'magenta')) deleted_serial = get_random_meter_and_delete() browser.switch_to_alert().accept() sleep(2*SLEEP_INTERVAL) print(colored('\ttest_3_delete_confirm_success: confirm delete - asserting...', 'blue')) assert "The Meter with Serial No. " + deleted_serial + " has been deleted successfully." in browser.page_source print(colored('\ttest_3_delete_confirm_success: check modal - asserting...', 'blue')) self.assertFalse(check_existence('//div[@class="MuiFormControl-root"]', is_id=False)) meter_table_headers = get_table_headers() rows = browser.find_elements_by_xpath('//tbody[@class="MuiTableBody-root"]/tr') serials = [] for row in rows: serials.append(row.find_elements_by_tag_name('td')[meter_table_headers.index('Serial No.')] .get_attribute('innerHTML')) print(colored('\ttest_3_delete_confirm_success: check deleted serial - asserting...', 'blue')) assert deleted_serial not in serials print(colored('\ttest_3_delete_confirm_success: passed.', 'cyan'))
def test_2_correct_details(self): print(colored('Running: test_2_correct_details - estimate: 24s', 'yellow')) for i in range(3): print(colored('\trandom command ' + str(i + 1), 'magenta')) command_row = get_random_table_row() command_cols = command_row.find_elements_by_tag_name('td') command_table_headers = get_table_headers() command_name_in_table = command_cols[command_table_headers.index('Name')].get_attribute('innerHTML') command_syntax_in_table = command_cols[command_table_headers.index('Command')].get_attribute('innerHTML') command_type_in_table = command_cols[command_table_headers.index('Type')].get_attribute('innerHTML') click_action_button(command_cols) command_detail_form = browser.find_element_by_xpath('//div[@class="MuiFormControl-root"]') command_name_in_form = command_detail_form.find_element_by_id('command-name').get_attribute('value') command_syntax_in_form = command_detail_form.find_element_by_id('command-syntax').get_attribute('value') command_type_in_form = command_type_in_table # command_detail_form.find_element_by_id('command-type').get_attribute('value') print(colored('\ttest_2_command_details: is correct command - asserting...', 'blue')) self.assertEqual(command_name_in_table, command_name_in_form) self.assertEqual(command_syntax_in_table, command_syntax_in_form) self.assertEqual(command_type_in_table, command_type_in_form) close_modal() print(colored('\ttest_2_correct_details: passed.', 'cyan'))
def get_back_previously_updated_node(hex): node_table_headers = get_table_headers() rows = browser.find_elements_by_xpath( '//tbody[@class="MuiTableBody-root"]/tr') for row in rows: cols = row.find_elements_by_tag_name('td') if hex == cols[node_table_headers.index('Hex. Address')].get_attribute( 'innerHTML'): click_action_button(cols) break
def get_back_previously_updated_meter(serial): meter_table_headers = get_table_headers() rows = browser.find_elements_by_xpath( '//tbody[@class="MuiTableBody-root"]/tr') for row in rows: cols = row.find_elements_by_tag_name('td') if serial == cols[meter_table_headers.index( 'Serial No.')].get_attribute('innerHTML'): click_action_button(cols) break
def get_random_meter(): meter_row = get_random_table_row() meter_cols = meter_row.find_elements_by_tag_name('td') meter_table_headers = get_table_headers() meter_serial = meter_cols[meter_table_headers.index( 'Serial No.')].get_attribute('innerHTML') click_action_button(meter_cols) return meter_serial
def get_back_previously_updated_gateway(imei): gateway_table_headers = get_table_headers() rows = browser.find_elements_by_xpath( '//tbody[@class="MuiTableBody-root"]/tr') for row in rows: cols = row.find_elements_by_tag_name('td') if imei == cols[gateway_table_headers.index('Imei')].get_attribute( 'innerHTML'): click_action_button(cols) break
def get_random_gateway(): gateway_row = get_random_table_row() gateway_cols = gateway_row.find_elements_by_tag_name('td') gateway_table_headers = get_table_headers() gateway_imei = gateway_cols[gateway_table_headers.index( 'Imei')].get_attribute('innerHTML') click_action_button(gateway_cols) return gateway_imei
def get_back_previously_updated_command(cmd): command_table_headers = get_table_headers() rows = browser.find_elements_by_xpath( '//tbody[@class="MuiTableBody-root"]/tr') for row in rows: cols = row.find_elements_by_tag_name('td') if len(cols) > 0 and cmd == cols[command_table_headers.index( 'Command')].get_attribute('innerHTML'): click_action_button(cols) break
def get_random_node(): node_row = get_random_table_row() node_cols = node_row.find_elements_by_tag_name('td') node_table_headers = get_table_headers() node_hex = node_cols[node_table_headers.index( 'Hex. Address')].get_attribute('innerHTML') click_action_button(node_cols) return node_hex
def test_3_correct_details(self): print( colored('Running: test_3_correct_details - estimate: 24s', 'yellow')) for i in range(3): print(colored('\trandom gateway ' + str(i + 1), 'magenta')) gateway_row = get_random_table_row() gateway_cols = gateway_row.find_elements_by_tag_name('td') gateway_table_headers = get_table_headers() gateway_imei_in_table = gateway_cols[gateway_table_headers.index( 'Imei')].get_attribute('innerHTML') gateway_serial_in_table = gateway_cols[gateway_table_headers.index( 'Serial No.')].get_attribute('innerHTML') gateway_hex_in_table = gateway_cols[gateway_table_headers.index( 'Hex. Address')].get_attribute('innerHTML') gateway_dec_in_table = gateway_cols[gateway_table_headers.index( 'Dec. Address')].get_attribute('innerHTML') gateway_ip_in_table = gateway_cols[gateway_table_headers.index( 'IP Address')].get_attribute('innerHTML') gateway_phone_in_table = gateway_cols[gateway_table_headers.index( 'Phone No.')].get_attribute('innerHTML') click_action_button(gateway_cols) gateway_detail_form = browser.find_element_by_xpath( '//div[@class="MuiFormControl-root"]') gateway_imei_in_form = gateway_detail_form.find_element_by_id( 'gateway-imei').get_attribute('value') gateway_serial_in_form = gateway_detail_form.find_element_by_id( 'serial-number').get_attribute('value') gateway_hex_in_form = gateway_detail_form.find_element_by_id( 'hex-address').get_attribute('value') gateway_dec_in_form = gateway_detail_form.find_element_by_id( 'dec-address').get_attribute('value') gateway_ip_in_form = gateway_detail_form.find_element_by_id( 'ip-address').get_attribute('value') gateway_phone_in_form = gateway_detail_form.find_element_by_id( 'phone-number').get_attribute('value') print( colored( '\ttest_3_correct_details: is correct gateway - asserting...', 'blue')) self.assertEqual(gateway_imei_in_table, gateway_imei_in_form) self.assertEqual(gateway_serial_in_table, gateway_serial_in_form) self.assertEqual(gateway_hex_in_table, gateway_hex_in_form) self.assertEqual(gateway_dec_in_table, gateway_dec_in_form) self.assertEqual(gateway_ip_in_table, gateway_ip_in_form) self.assertEqual(gateway_phone_in_table, gateway_phone_in_form) close_modal() print(colored('\ttest_3_correct_details: passed.', 'cyan'))
def get_random_command(): while True: command_row = get_random_table_row() command_cols = command_row.find_elements_by_tag_name('td') if len(command_cols) > 0: break command_table_headers = get_table_headers() command = command_cols[command_table_headers.index( 'Command')].get_attribute('innerHTML') click_action_button(command_cols) return command
def test_3_commands_columns(self): print(colored('Running: test_3_commands_columns - estimate: 5s', 'yellow')) commands_table_headers = get_table_headers() for i in range(2): print(colored('\trandom commands ' + str(i + 1), 'magenta')) commands_row = get_random_table_row() commands_cols = commands_row.find_elements_by_tag_name('td') for col in commands_table_headers: col_data = commands_cols[commands_table_headers.index(col)].get_attribute('innerHTML') has_data = (col == 'Command' or col == 'Type') and len(col_data) > 0 or len(col_data) >= 0 print(colored('\ttest_3_commands_columns: column "' + col + '" - asserting...', 'blue')) self.assertTrue(has_data) print(colored('\ttest_3_commands_columns: passed.', 'cyan'))
def test_3_delete_confirm_success(self): print( colored('Running: test_3_delete_confirm_success - estimate: 15s', 'yellow')) for i in range(3): print(colored('\trandom gateway ' + str(i + 1), 'magenta')) deleted_imei = get_random_gateway() click_delete_button() browser.switch_to_alert().accept() sleep(2 * SLEEP_INTERVAL) print( colored( '\ttest_3_delete_confirm_success: confirm delete - asserting...', 'blue')) assert "The selected gateway with IMEI " + deleted_imei + " has been deleted successfully." in browser.page_source print( colored( '\ttest_3_delete_confirm_success: check modal - asserting...', 'blue')) self.assertFalse( check_existence('//div[@class="MuiFormControl-root"]', is_id=False)) gateway_table_headers = get_table_headers() rows = browser.find_elements_by_xpath( '//tbody[@class="MuiTableBody-root"]/tr') imeis = [] for row in rows: imeis.append( row.find_elements_by_tag_name('td')[ gateway_table_headers.index('Imei')].get_attribute( 'innerHTML')) print( colored( '\ttest_3_delete_confirm_success: check deleted imei - asserting...', 'blue')) assert deleted_imei not in imeis print(colored('\ttest_3_delete_confirm_success: passed.', 'cyan'))
def test_3_search_success(self): print( colored('Running: test_3_search_success - estimate: 13s', 'yellow')) search_form = SearchForm() search_form.form_clear_button.send_keys(Keys.ENTER) gateway_table_headers = get_table_headers() keyword = '' for i in range(5): random_row = get_random_table_row() cols = random_row.find_elements_by_tag_name('td') keyword += (cols[gateway_table_headers.index( 'Imei')].get_attribute('innerHTML') + ",") keyword = keyword[:-1] search_form.keyword_input.send_keys(keyword) browser.execute_script('arguments[0].click()', search_form.search_fields[0]) search_form.search_button.send_keys(Keys.ENTER) sleep(2 * SLEEP_INTERVAL) results = browser.find_elements_by_xpath( '//tbody[@class="MuiTableBody-root"]/tr') result_imeis = [] for result in results: cols = result.find_elements_by_tag_name('td') if len(cols) != 0: result_imeis.append(cols[gateway_table_headers.index( 'Imei')].get_attribute('innerHTML')) keyword_imeis = keyword.split(',') print( colored('\ttest_3_search_success: matching results - asserting...', 'blue')) self.assertEqual(keyword_imeis.sort(), result_imeis.sort()) print(colored('\ttest_3_search_success: passed.', 'cyan'))
def test_4_correct_details(self): print(colored('Running: test_4_correct_details - estimate: 5s', 'yellow')) account_table_headers = get_table_headers() active_user_row = get_random_row_in_account_table() active_user_cols = active_user_row.find_elements_by_tag_name('td') click_action_button(active_user_cols) fullname_in_table = active_user_cols[account_table_headers.index('Full Name')].get_attribute('innerHTML') username_in_table = active_user_cols[account_table_headers.index('Username')].get_attribute('innerHTML') email_in_table = active_user_cols[account_table_headers.index('Email')].get_attribute('innerHTML') fullname_in_form = browser.find_element_by_id('full-name').get_attribute('value') username_in_form = browser.find_element_by_id('username').get_attribute('value') email_in_form = browser.find_element_by_id('email-address').get_attribute('value') print(colored('\ttest_4_correct_details: user details - asserting...', 'blue')) self.assertEqual(fullname_in_table, fullname_in_form) self.assertEqual(username_in_table, username_in_form) self.assertEqual(email_in_table, email_in_form) browser.find_element_by_id('cancel-button').click() print(colored('\ttest_4_correct_details: passed.', 'cyan'))
def test_2_correct_details(self): print( colored('Running: test_2_correct_details - estimate: 24s', 'yellow')) for i in range(3): print(colored('\trandom meter ' + str(i + 1), 'magenta')) meter_row = get_random_table_row() meter_cols = meter_row.find_elements_by_tag_name('td') meter_table_headers = get_table_headers() meter_serial_in_table = meter_cols[meter_table_headers.index( 'Serial No.')].get_attribute('innerHTML') meter_endpoint_in_table = meter_cols[meter_table_headers.index( 'End Point')].get_attribute('innerHTML') click_action_button(meter_cols) meter_detail_form = browser.find_element_by_xpath( '//div[@class="MuiFormControl-root"]') meter_serial_in_form = meter_detail_form.find_element_by_id( 'serial-number').get_attribute('value') meter_endpoint_in_form = meter_detail_form.find_element_by_id( 'endpoint-address').get_attribute('value') print( colored( '\ttest_2_correct_details: is correct meter - asserting...', 'blue')) self.assertEqual(meter_serial_in_table, meter_serial_in_form) self.assertEqual(meter_endpoint_in_table, meter_endpoint_in_form) close_modal() print(colored('\ttest_2_correct_details: passed.', 'cyan'))
def test_2_correct_details(self): print( colored('Running: test_2_correct_details - estimate: 24s', 'yellow')) for i in range(3): print(colored('\trandom node ' + str(i + 1), 'magenta')) node_row = get_random_table_row() node_cols = node_row.find_elements_by_tag_name('td') node_table_headers = get_table_headers() node_hex_in_table = node_cols[node_table_headers.index( 'Hex. Address')].get_attribute('innerHTML') node_dec_in_table = node_cols[node_table_headers.index( 'Dec. Address')].get_attribute('innerHTML') click_action_button(node_cols) node_detail_form = browser.find_element_by_xpath( '//div[@class="MuiFormControl-root"]') node_hex_in_form = node_detail_form.find_element_by_id( 'hex-address').get_attribute('value') node_dec_in_form = node_detail_form.find_element_by_id( 'dec-address').get_attribute('value') print( colored( '\ttest_2_node_details: is correct node - asserting...', 'blue')) self.assertEqual(node_hex_in_table, node_hex_in_form) self.assertEqual(node_dec_in_table, node_dec_in_form) close_modal() print(colored('\ttest_2_correct_details: passed.', 'cyan'))
def test_3_confirm_success(): print( colored('Running: test_2_confirm_no_network - estimate: 20s', 'yellow')) account_table_headers = get_table_headers() for i in range(2): print(colored('\trandom account ' + str(i + 1), 'magenta')) active_user_row = get_random_row_in_account_table() active_user_cols = active_user_row.find_elements_by_tag_name('td') click_action_button(active_user_cols) browser.find_element_by_id('delete-button').send_keys(Keys.ENTER) sleep(SLEEP_INTERVAL) browser.switch_to_alert().accept() sleep(2 * SLEEP_INTERVAL) active_users_table = browser.find_element_by_xpath( '//tbody[@class="MuiTableBody-root"]') active_users_rows = active_users_table.find_elements_by_tag_name( 'tr') active_users = [ row for row in active_users_rows if len(row.find_elements_by_tag_name('td')) > 0 ] user_names = [] for user in active_users: user_names.append( user.find_elements_by_tag_name('td') [account_table_headers.index('Full Name')].get_attribute( 'innerHTML')) print( colored('\ttest_1_unconfirmed: active users - asserting...', 'blue')) assert active_user_cols[account_table_headers.index( 'Full Name')] not in user_names if len( browser.find_elements_by_xpath( '//tbody[@class="MuiTableBody-root"]')) > 1: inactive_users_table = browser.find_elements_by_xpath( '//tbody[@class="MuiTableBody-root"]')[1] inactive_users_rows = inactive_users_table.find_elements_by_tag_name( 'tr') inactive_users = [ row for row in inactive_users_rows if len(row.find_elements_by_tag_name('td')) > 0 ] in_user_names = [] for user in inactive_users: in_user_names.append( user.find_elements_by_tag_name('td')[ account_table_headers.index( 'Full Name')].get_attribute('innerHTML')) print( colored( '\ttest_1_unconfirmed: inactive users - asserting...', 'blue')) assert active_user_cols[account_table_headers.index( 'Full Name')] in in_user_names print(colored('\ttest_1_unconfirmed: passed.', 'cyan'))
def test_1_unconfirmed(self): print(colored('Running: test_1_unconfirmed - estimate: 3s', 'yellow')) account_table_headers = get_table_headers() active_user_row = get_random_row_in_account_table() active_user_cols = active_user_row.find_elements_by_tag_name('td') click_action_button(active_user_cols) browser.find_element_by_id('delete-button').send_keys(Keys.ENTER) sleep(SLEEP_INTERVAL) confirmation = browser.switch_to_alert() print( colored('\ttest_1_unconfirmed: cancel deletion - asserting...', 'blue')) self.assertEqual( confirmation.text, 'Delete the account ' + active_user_cols[account_table_headers.index('Full Name')] + '. Continue?') active_users_table = browser.find_element_by_xpath( '//tbody[@class="MuiTableBody-root"]') active_users_rows = active_users_table.find_elements_by_tag_name('tr') active_users = [ row for row in active_users_rows if len(row.find_elements_by_tag_name('td')) > 0 ] user_names = [] for user in active_users: user_names.append( user.find_elements_by_tag_name('td')[ account_table_headers.index('Full Name')].get_attribute( 'innerHTML')) print( colored('\ttest_1_unconfirmed: active users - asserting...', 'blue')) assert active_user_cols[account_table_headers.index( 'Full Name')] in user_names if len( browser.find_elements_by_xpath( '//tbody[@class="MuiTableBody-root"]')) > 1: inactive_users_table = browser.find_elements_by_xpath( '//tbody[@class="MuiTableBody-root"]')[1] inactive_users_rows = inactive_users_table.find_elements_by_tag_name( 'tr') inactive_users = [ row for row in inactive_users_rows if len(row.find_elements_by_tag_name('td')) > 0 ] in_user_names = [] for user in inactive_users: in_user_names.append( user.find_elements_by_tag_name('td') [account_table_headers.index('Full Name')].get_attribute( 'innerHTML')) print( colored('\ttest_1_unconfirmed: inactive users - asserting...', 'blue')) assert active_user_cols[account_table_headers.index( 'Full Name')] not in in_user_names print(colored('\ttest_1_unconfirmed: passed.', 'cyan'))