class HeaderTestCases(BaseTest): def setUp(self): super().setUp() self.header_page = Header() self.user_api = UsersAPI() self.roles_api = RolesAPI() self.set_authorization(auth=self.roles_api.AUTHORIZATION_RESPONSE) self.header_page.get_users_page() self.header_page.set_all_configure_table_columns_to_specific_value() def test001_archive_user_management(self): """ User management: Make sure that you can archive any record LIMS-6379 """ self.info("select random users rows") selected_user_management_data, _ = self.header_page.select_multiple_random_users_rows() self.info("Archive selected rows") self.header_page.archive_entity(menu_element='user_management:right_menu', archive_element='user_management:archive') self.info("Navigate to archived users") self.header_page.get_archived_entities(menu_element='user_management:right_menu', archived_element='user_management:archived') for user in selected_user_management_data: user_name = user['Name'] self.info('{} user should be activated.'.format(user_name)) self.assertTrue(self.header_page.is_user_in_table(value=user_name)) def test002_restore_user(self): """ User management: Restore Approach: Make sure that you can restore any record successfully LIMS-6380 """ user_names = [] self.info("Navigate to archived users") self.header_page.get_archived_entities(menu_element='user_management:right_menu', archived_element='user_management:archived') self.info("Select random archived users rows") selected_user_data, _ = self.header_page.select_multiple_random_users_rows() self.assertTrue(selected_user_data, 'No archived users found') for user in selected_user_data: user_names.append(user['Name']) self.info("Restore selected rows") self.header_page.restore_entity(menu_element='user_management:right_menu', restore_element='user_management:restore') self.header_page.get_active_entities(menu_element='user_management:right_menu', active_element='user_management:active') for user_name in user_names: self.assertTrue(self.header_page.is_user_in_table(value=user_name)) #@skip("https://modeso.atlassian.net/browse/LIMSA-199") def test003_user_search(self): """ Header: User management: Search Approach: Make sure that you can search by any field in the active table successfully LIMS-6082 """ self.info("select random row and search by its data") row = self.header_page.get_random_user_row() row_data = self.base_selenium.get_row_cells_dict_related_to_header(row=row) for column in row_data: if re.findall(r'\d{1,}.\d{1,}.\d{4}', row_data[column]) \ or row_data[column] == '' or row_data[column] == '-': continue self.info('search for {} : {}'.format(column, row_data[column])) search_results = self.header_page.search(row_data[column]) self.assertGreater(len(search_results), 1, " * There is no search results for {}, Report a bug.".format(row_data[column])) for search_result in search_results: search_data = self.base_selenium.get_row_cells_dict_related_to_header(search_result) if search_data[column] == row_data[column]: break self.assertEqual(row_data[column], search_data[column]) def test004_download_user_sheet(self): """ User management: Make sure you can export all the data in the active table & it should display in the same order LIMS-6101 """ self.header_page.download_xslx_sheet() rows_data = list(filter(None, self.header_page.get_table_rows_data())) for index in range(len(rows_data)): self.info('comparing the user no. {} '.format(index)) fixed_row_data = self.fix_data_format(rows_data[index].split('\n')) values = self.header_page.sheet.iloc[index].values fixed_sheet_row_data = self.fix_data_format(values) for item in fixed_row_data: self.assertIn(item, fixed_sheet_row_data) def test005_delete_user(self): """ User management : Delete Approach: Make sure that you can delete any record successfully If this record not used in any other entity LIMS-6381 """ self.info("create new user") response, payload = UsersAPI().create_new_user() self.assertEqual(response['status'], 1, payload) new_user_name = response['user']['username'] self.header_page.search(value=new_user_name) self.header_page.select_all_records() self.header_page.archive_entity(menu_element='user_management:right_menu', archive_element='user_management:archive') self.header_page.get_archived_entities(menu_element='user_management:right_menu', archived_element='user_management:archived') self.info('make sure that that the user record navigate to the archive table') self.assertTrue(self.header_page.search(value=new_user_name)) self.header_page.select_all_records() self.header_page.delete_entity() result = self.header_page.search(value=new_user_name) self.assertEqual(result[0].get_attribute("textContent"), 'No data available in table') self.info('deleted successfully') def test006_create_new_user(self): """ Header: User management Approach: Make sure that I can create new user successfully LIMS-6000 """ random_user_name = self.generate_random_string() random_user_email = self.header_page.generate_random_email() self.header_page.create_new_user( user_name=random_user_name, user_email=random_user_email, user_password='******', user_confirm_password='******') self.header_page.sleep_tiny() user_row = self.header_page.search(value=random_user_name) table_row = self.header_page.result_table() self.assertEqual(table_row, user_row) def test007_overview_btn_from_create_mode(self): """ User Management: Overview button Approach: Make sure after you press on the overview button, it will redirect me to the active table LIMS-6396 """ # from the create mode it will redirect me to the active table self.header_page.click_create_new_user() self.header_page.click_on_overview_btn() self.info('it will redirect me to the active table') self.assertEqual(self.base_selenium.get_url(), '{}users'.format(self.base_selenium.url)) def test008_overview_btn_from_edit_mode(self): """ User Management: Overview button Approach: Make sure after you press on the overview button, it will redirect me to the active table LIMS-6396 """ # from the edit mode it will redirect me to the active table self.header_page.get_random_user() self.header_page.click_on_overview_btn() self.info('it will redirect me to the active table') self.assertEqual(self.base_selenium.get_url(), '{}users'.format(self.base_selenium.url)) @parameterized.expand(['save_btn', 'cancel']) def test009_update_user_name_with_save_cancel_btn(self, save): """ User management: User management: I can update user name with save & cancel button LIMS-6395 """ self.header_page.get_random_user() user_url = self.base_selenium.get_url() self.info('user_url : {}'.format(user_url)) self.header_page.sleep_tiny() current_name = self.header_page.get_user_name() self.header_page.set_user_name(self.generate_random_string()) new_name = self.header_page.get_user_name() if 'save_btn' == save: self.header_page.save(save_btn='user_management:save_btn') else: self.header_page.cancel(force=True) self.base_selenium.get( url=user_url, sleep=self.base_selenium.TIME_MEDIUM) user_name = self.header_page.get_user_name() if 'save_btn' == save: self.info( 'Assert {} (new_name) == {} (user_name)'.format(new_name, user_name)) self.assertEqual(new_name, user_name) else: self.info( 'Assert {} (current_name) == {} (user_name)'.format(current_name, user_name)) self.assertEqual(current_name, user_name) @parameterized.expand(['save_btn', 'cancel']) def test010_update_user_role_with_save_cancel_btn(self, save): """ User management: I can update user role with save & cancel button LIMS-6398 """ # open random user in the edit mode self.header_page.get_random_user() user_url = self.base_selenium.get_url() self.info('user_url : {}'.format(user_url)) self.header_page.sleep_tiny() current_role = self.header_page.get_user_role() self.header_page.set_user_role() new_role = self.header_page.get_user_role() if 'save_btn' == save: self.header_page.save(save_btn='user_management:save_btn') else: self.header_page.cancel(force=True) self.base_selenium.get( url=user_url, sleep=self.base_selenium.TIME_MEDIUM) user_role = self.header_page.get_user_role() if 'save_btn' == save: self.info( 'Assert {} (new_role) == {} (user_role)'.format(new_role, user_role)) self.assertEqual(new_role, user_role) else: self.info( 'Assert {} (current_role) == {} (user_role)'.format(current_role, user_role)) self.assertEqual(current_role, user_role) @parameterized.expand(['save_btn', 'cancel']) def test011_update_user_email_with_save_cancel_btn(self, save): """ User management: I can update user email with save & cancel button LIMS-6397 """ # open random user in the edit mode self.header_page.get_random_user() user_url = self.base_selenium.get_url() self.info('user_url : {}'.format(user_url)) self.header_page.sleep_tiny() current_email = self.header_page.get_user_email() new_email = self.header_page.generate_random_email() self.header_page.set_user_email(new_email) if 'save_btn' == save: self.header_page.save(save_btn='user_management:save_btn') else: self.header_page.cancel(force=True) self.base_selenium.get( url=user_url, sleep=self.base_selenium.TIME_MEDIUM) user_email = self.header_page.get_user_email() if 'save_btn' == save: self.info( 'Assert {} (new_email) == {} (user_email)'.format(new_email, user_email)) self.assertEqual(new_email, user_email) else: self.info( 'Assert {} (current_email) == {} (user_email)'.format(current_email, user_email)) self.assertEqual(current_email, user_email) def test012_validation_user_name_email_fields(self): """ Header: User management: Make sure when the user update name & email then press on save button, red border display and he can't save LIMS-6121 """ # from the create mode it will redirect me to the active table self.header_page.get_random_user() self.header_page.clear_user_name() self.header_page.clear_user_email() self.header_page.save(save_btn='user_management:save_btn') self.info('Waiting for error message') validation_result = self.base_selenium.wait_element(element='general:oh_snap_msg') self.info('Assert error msg') self.assertEqual(validation_result, True) @parameterized.expand([('name', 'filter_name', 'Name'), ('email', 'filter_email', 'Email'), ('number', 'filter_number', 'No'), ('created_on', 'filter_created_on', 'Created On')]) def test013_filter_by_text_field(self, field, filter_elem, header): """ User management Approach: I can filter by name, email, number and created on successfully LIMS-6002 LIMS-6442 LIMS-6488 LIMS-6486 """ self.header_page.sleep_tiny() filter_data = self.header_page.get_data_from_row()[field] self.info(" filter by {}".format(filter_data)) user_results = self.header_page.filter_user_by(filter_element='user_management:{}'.format(filter_elem), filter_text=filter_data) for user_result in user_results: self.assertEqual(user_result[header].replace("'", ""), filter_data.replace("'", "")) def test014_filter_by_role(self): """ User management Approach: I can filter by user role successfully LIMS-6443 """ self.info('get random role') res, _ = self.roles_api.get_all_roles(limit=50) random_role = random.choice(res['roles']) self.info(f'random role id: {random_role["id"]}') self.info('create random user') payload = { 'role': { 'id': random_role['id'], 'text': random_role['name'] }, 'roleId': random_role['id'] } response, payload = self.user_api.create_new_user(**payload) user_results = self.header_page.filter_user_by(filter_element='user_management:filter_role', filter_text=random_role['name'], field_type='drop_down') usernames = [] for user_result in user_results: self.assertEqual(user_result["Role"], random_role['name']) usernames.append(user_result['Name']) self.assertIn(response['user']['username'], usernames) @skip('https://modeso.atlassian.net/browse/LIMS-6624') def test015_cant_create_two_users_with_the_same_name(self): """ User management: Can't create two users with the same name LIMS-6503 """ # create new user with random data random_user_name = self.generate_random_string() random_user_email = self.header_page.generate_random_email() self.header_page.create_new_user(user_name=random_user_name, user_email=random_user_email, user_role='Admin', user_password='******', user_confirm_password='******') self.info('search to make sure that the role created '.format(random_user_name)) created_user = self.header_page.search(random_user_name)[0] user_data = self.base_selenium.get_row_cells_dict_related_to_header(row=created_user) self.assertTrue(created_user, user_data) # create role with the same name self.header_page.create_new_user(user_name=random_user_name, user_email=random_user_email, user_role='Admin', user_password='******', user_confirm_password='******') self.info('waiting fo validation message appear when I enter two users with the same name') validation_result = self.base_selenium.wait_element(element='general:oh_snap_msg') self.info('Assert the error message to make sure that validation when ' 'I enter two users with the same name? {}'.format(validation_result)) self.assertTrue(validation_result)
class MyProfileTestCases(BaseTest): def setUp(self): super().setUp() self.my_profile_page = MyProfile() self.users_api = UsersAPI() self.info("create new user") response, payload = self.users_api.create_new_user() self.assertEqual(response['status'], 1, "failed to create new user") self.current_password = payload["password"] self.username = payload["username"] self.email = payload["email"] self.info('user {}:{}'.format(self.username, self.current_password)) self.users_api._get_authorized_session(username=self.username, password=self.current_password, reset_token=True) self.set_authorization(auth=self.users_api.AUTHORIZATION_RESPONSE) self.my_profile_page.get_my_profile_page() def tearDown(self): # Blocked by https: // modeso.atlassian.net / browse / LIMS - 6425 # self.users_api.delete_active_user(id=self.userId) return super().tearDown() def test001_user_can_change_password_and_press_on_cancel(self): """ My Profile: Make sure after you change the password and press on cancel button, the password shouldn't change LIMS-6091 """ self.new_password = self.my_profile_page.generate_random_text() self.my_profile_page.change_password(self.current_password, self.new_password) response = self.users_api.post_auth(username=self.username, password=self.new_password) self.assertEqual("username_or_password_is_incorrect", response.json()["message"]) def test002_my_profile_should_show_username_and_email(self): """ My Profile: Make sure that the user name & email displayed above the language LIMS-6090 """ username = self.base_selenium.get_text(element='my_profile:username') self.info('Check the username is {}'.format(self.username)) self.assertEqual(username.lower(), self.username.lower()) email = self.base_selenium.get_text(element='my_profile:email') self.info('Check the email is {}'.format(self.email)) self.assertTrue(email.lower(), self.email.lower()) def test003_user_can_change_password_and_login_successfully(self): """ My Profile: Make sure that you can change the password and login with the new one successfully LIMS-6084 """ # new password value new_password = self.my_profile_page.generate_random_text() # change password self.my_profile_page.change_password(self.current_password, new_password, True) # Authorize baseAPI = BaseAPI() auth_token = baseAPI._get_authorized_session( username=self.base_selenium.username, password=new_password) # check if the auth token has value self.assertTrue(auth_token) @parameterized.expand(['EN', 'DE']) def test004_user_can_change_the_language(self, lang): """ My Profile: Language Approach: Make sure that you can change language LIMS-6089 """ self.my_profile_page.chang_lang('DE') self.my_profile_page.sleep_tiny() if lang == 'EN': self.my_profile_page.chang_lang('EN') self.my_profile_page.sleep_tiny() self.base_selenium.scroll() self.my_profile_page.sleep_tiny() page_name = self.base_selenium.get_text('my_profile:page_name') if lang == 'EN': self.assertEqual(page_name, 'My Profile') else: self.assertEqual(page_name, 'Mein Profil') def test005_company_profile_upload_logo_then_cancel_should_not_save(self): """ My Profile: Signature Approach: Make sure after you upload the signature & press on cancel button, this signature didn't submit LIMS-6086 """ self.info('open signature tab') self.base_selenium.click('my_profile:signature_tab') # choose file from assets to be uploaded file_name = 'logo.png' self.info('upload the file then cancel') self.my_profile_page.upload_logo( file_name=file_name, drop_zone_element='my_profile:signature_field', save=False) self.info("Navigate to my profile page") self.my_profile_page.get_my_profile_page() self.info('open signature tab') self.base_selenium.click('my_profile:signature_tab') self.info('check that the image is not saved') is_the_file_not_exist = self.base_selenium.check_element_is_not_exist( element='general:file_upload_success_flag') self.assertTrue(is_the_file_not_exist) def test006_my_profile_user_can_upload_logo(self): """ My Profile: Signature Approach: Make sure that you can upload the signature successfully LIMS-6085 """ self.info('open signature tab') self.base_selenium.click('my_profile:signature_tab') file_name = 'logo.png' uploaded_file_name = self.my_profile_page.upload_logo( file_name=file_name, drop_zone_element='my_profile:signature_field', save=True) self.assertEqual(uploaded_file_name, file_name) def test007_my_profile_user_can_update_logo(self): """ My Profile: Signature Approach: Make sure that you can remove any signature LIMS-6095 """ self.info('open signature tab') self.base_selenium.click('my_profile:signature_tab') self.info('choose file from assets to be uploaded') file_name = 'logo.png' self.my_profile_page.upload_logo( file_name=file_name, drop_zone_element='my_profile:signature_field', save=True) self.info('remove the uploaded logo') self.base_selenium.scroll() self.base_selenium.click('general:remove_file') self.my_profile_page.save(save_btn="my_profile:save_button") self.info("check that the image is not saved") is_the_file_not_exist = self.base_selenium.check_element_is_not_exist( element='general:file_upload_success_flag') self.assertTrue(is_the_file_not_exist) def test008_you_cant_upload_more_than_one_signature(self): """ My Profile: Signature Approach: Make sure you can't download more than one signature LIMS-6087 """ self.info('open signature tab') self.base_selenium.click('my_profile:signature_tab') self.info('choose file from assets to be uploaded') file_name = 'logo.png' other_file_name = 'logo2.png' self.info("upload the first file") self.my_profile_page.upload_logo( file_name=file_name, drop_zone_element='my_profile:signature_field', save=True) self.base_selenium.scroll() self.info("upload other file beside the current one") self.my_profile_page.upload_logo( file_name=other_file_name, drop_zone_element='my_profile:signature_field', save=True) self.base_selenium.scroll() self.assertTrue(self.base_selenium.find_element('general:oh_snap_msg')) self.info('wait to see if the file upload') self.my_profile_page.sleep_medium() self.info('get array of all uploaded files') files_uploaded_flags = self.base_selenium.find_elements( 'general:files_upload_success_flags') self.info('assert that only 1 file should be uploaded') self.assertEqual(len(files_uploaded_flags), 1)