def test_3_device_model(self): print(colored('Running: test_3_device_model - estimate: 57s', 'yellow')) for i in range(3): print(colored('\trandom gateway ' + str(i + 1), 'magenta')) updated_imei = get_random_gateway() gateway_detail_form = browser.find_element_by_xpath( '//div[@class="MuiFormControl-root"]') device_model_dropdown = gateway_detail_form.find_element_by_id( 'device-model') device_model_dropdown.send_keys(Keys.ENTER) sleep(SLEEP_INTERVAL) device_model_items = browser.find_elements_by_xpath( '//ul[@class="MuiList-root MuiMenu-list ' 'MuiList-padding"]/li') random_device_model = get_random_dropdown_item(device_model_items) random_device_model.click() click_update_button() print( colored('\ttest_3_device_model: confirm update - asserting...', 'blue')) assert "The selected gateway with IMEI " + updated_imei + " has been updated successfully." in browser.page_source get_back_previously_updated_gateway(updated_imei) close_modal() print(colored('\ttest_3_device_model: 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 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 test_2_commands_display(self): print(colored('Running: test_2_commands_display - estimate: 5s', 'yellow')) pagination_label = browser.find_element_by_xpath('//tfoot[@class="MuiTableFooter-root"]/tr/td/div/div/span[' '@class="MuiTypography-root MuiTypography-caption"]') total_commands = int(pagination_label.get_attribute('innerHTML').split(' ')[2]) print(colored('\ttest_2_commands_display: commands count - asserting...', 'blue')) self.assertGreater(total_commands, 0) print(colored('\ttest_2_commands_display: passed.', 'cyan'))
def test_4_create_success(): print( colored('Running: test_4_create_success - estimate: 27s', 'yellow')) for i in range(3): print(colored('\tnew gateway ' + str(i + 1), 'magenta')) click_fab_button() imei = str(int(datetime.now().timestamp())) + "-" + str(i + 1) browser.find_element_by_id('gateway-imei').send_keys(imei) browser.find_element_by_id('gateway-name').send_keys('test name') browser.find_element_by_id('phone-number').send_keys('test phone') browser.find_element_by_id('hex-address').send_keys('hex address') browser.find_element_by_id('dec-address').send_keys('dec address') browser.find_element_by_id('ip-address').send_keys('ip address') browser.find_element_by_id('software-version').send_keys( 'sw version') browser.find_element_by_id('firmware-version').send_keys( 'fw version') browser.find_element_by_id('sim-serial').send_keys('sim serial') browser.find_element_by_id('sim-puk').send_keys('sim puk') gateway_detail_form = browser.find_element_by_xpath( '//div[@class="MuiFormControl-root"]') device_model_dropdown = gateway_detail_form.find_element_by_id( 'device-model') device_model_dropdown.send_keys(Keys.ENTER) sleep(SLEEP_INTERVAL) device_model_items = browser.find_elements_by_xpath( '//ul[@class="MuiList-root MuiMenu-list ' 'MuiList-padding"]/li') random_device_model = get_random_dropdown_item(device_model_items) random_device_model.click() click_save_button() print( colored( '\ttest_4_create_success: alert message - asserting...', 'blue')) assert "New gateway has been created successfully with IMEI " + imei in browser.page_source print(colored('\ttest_4_create_success: passed.', 'cyan'))
def test_3_device_model_dropdown(self): print( colored('Running: test_3_device_model_dropdown - estimate: 39s', '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') click_action_button(meter_cols) meter_detail_form = browser.find_element_by_xpath( '//div[@class="MuiFormControl-root"]') device_model_dropdown = meter_detail_form.find_element_by_id( 'device-model') device_model_dropdown.send_keys(Keys.ENTER) sleep(SLEEP_INTERVAL) device_model_items = browser.find_elements_by_xpath( '//ul[@class="MuiList-root MuiMenu-list ' 'MuiList-padding"]/div') print( colored( '\ttest_3_device_model_dropdown: device models count - asserting...', 'blue')) self.assertGreaterEqual(len(device_model_items), 1) random_device_model = get_random_dropdown_item(device_model_items) random_model_value = random_device_model.find_element_by_xpath( '//span/div/div').get_attribute('innerHTML') random_device_model.click() sleep(SLEEP_INTERVAL) random_model_selected = random_model_value # browser.find_element_by_id('device-model').get_attribute('innerHTML') print( colored( '\ttest_3_device_model_dropdown: device models selected - asserting...', 'blue')) self.assertEqual(random_model_value, random_model_selected) close_modal() print(colored('\ttest_3_device_model_dropdown: passed.', 'cyan'))
def test_5_clashed_primary_key(): print( colored('Running: test_5_clashed_primary_key - estimate: 27s', 'yellow')) imei = get_random_table_data('Imei') click_fab_button() browser.find_element_by_id('gateway-imei').send_keys(imei) browser.find_element_by_id('gateway-name').send_keys('test name') browser.find_element_by_id('phone-number').send_keys('test phone') browser.find_element_by_id('hex-address').send_keys('hex address') browser.find_element_by_id('dec-address').send_keys('dec address') browser.find_element_by_id('ip-address').send_keys('ip address') browser.find_element_by_id('software-version').send_keys('sw version') browser.find_element_by_id('firmware-version').send_keys('fw version') browser.find_element_by_id('sim-serial').send_keys('sim serial') browser.find_element_by_id('sim-puk').send_keys('sim puk') gateway_detail_form = browser.find_element_by_xpath( '//div[@class="MuiFormControl-root"]') device_model_dropdown = gateway_detail_form.find_element_by_id( 'device-model') device_model_dropdown.send_keys(Keys.ENTER) sleep(SLEEP_INTERVAL) device_model_items = browser.find_elements_by_xpath( '//ul[@class="MuiList-root MuiMenu-list ' 'MuiList-padding"]/li') random_device_model = get_random_dropdown_item(device_model_items) random_device_model.click() click_save_button() confirmation = browser.switch_to_alert() print( colored( '\ttest_5_clashed_serial: confirmation dialog - asserting...', 'blue')) assert "Error occurred while saving gateway" in confirmation.text confirmation.accept() close_modal() sleep(2 * SLEEP_INTERVAL)
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'))