def get_active_article_with_tst_plan(self, test_plan_status='complete'): self.test_plan = TstPlan() self.article_page = Article() self.info( 'Get Active article with {} test plan.'.format(test_plan_status)) self.test_plan.get_test_plans_page() complete_test_plans = self.test_plan.search(test_plan_status) complete_test_plans_dict = [ self.base_selenium.get_row_cells_dict_related_to_header( row=complete_test_plan) for complete_test_plan in complete_test_plans[:-1] ] self.article_page.get_articles_page() for complete_test_plan_dict in complete_test_plans_dict: self.info('Is {} article in active status?'.format( complete_test_plan_dict['Article Name'])) if self.article_page.is_article_in_table( value=complete_test_plan_dict['Article Name']): self.info('Active.') return complete_test_plan_dict else: self.info('Archived.') else: return {}
def setUp(self): super().setUp() self.test_plan = TstPlan() self.test_plan_api = TestPlanAPI() self.article_api = ArticleAPI() self.test_plan.get_test_plans_page() self.test_plan_api.set_configuration()
def setUp(self): super().setUp() self.login_page = Login() self.article_page = Article() self.test_plan = TstPlan() self.order = Order() self.login_page.login(username=self.base_selenium.username, password=self.base_selenium.password) self.base_selenium.wait_until_page_url_has(text='dashboard') self.article_page.get_article_page()
def setUp(self): super().setUp() self.test_unit_page = TstUnit() self.test_units_page = TstUnits() self.test_plan = TstPlan() self.article_api = ArticleAPI() self.test_unit_api = TestUnitAPI() self.set_authorization(auth=self.article_api.AUTHORIZATION_RESPONSE) self.test_unit_api.set_configuration() self.test_unit_page.get_test_units_page()
def setUp(self): super().setUp() self.article_page = Article() self.article_api = ArticleAPI() self.test_plan_api = TestPlanAPI() self.test_plans_page = TestPlans() self.test_plan_page = TstPlan() self.orders_page = Orders() self.order_api = OrdersAPI() self.order_page = Order() self.set_authorization(auth=self.article_api.AUTHORIZATION_RESPONSE) self.article_api.set_configuration() self.article_page.get_articles_page()
def test014_create_role_with_master_data_permissions_then_create_user_by_it(self): """ Roles & Permissions: when I create user with master data permissions then create user wit it when I login with this user the master data only should appear in the menu LIMS-6440 """ self.login_page = Login() self.info('create role with random name with master data permissions') random_role_name = self.generate_random_string() self.header_page.create_role_with_mater_data_permissions(role_name=random_role_name) self.info('go to the user section to create user with this role') self.header_page.get_users_page() random_user_name = self.generate_random_string() random_user_email = self.header_page.generate_random_email() random_user_password = self.generate_random_string() self.header_page.create_new_user(user_name=random_user_name, user_email=random_user_email, user_role=random_role_name, user_password=random_user_password, user_confirm_password=random_user_password) self.login_page.logout() self.info('login with role & user {}:{}'.format(random_user_name, random_user_password)) self.login_page.login(username=random_user_name, password=random_user_password) self.header_page.sleep_medium() # make sure that all the master data pages appear(articles & test units & test plans & contacts) self.info('get the test unit url') self.assertTrue('Test Units', TstUnit().get_test_units_page()) self.info('get the articles url') self.assertTrue('Articles', Article().get_articles_page()) self.info('get the test plan url') self.assertTrue('Test Plans', TstPlan().get_test_plans_page()) self.info('get the contacts url') self.assertTrue('Contacts', Contacts().get_contacts_page())
class ArticlesTestCases(BaseTest): def setUp(self): super().setUp() self.login_page = Login() self.article_page = Article() self.test_plan = TstPlan() self.order = Order() self.login_page.login(username=self.base_selenium.username, password=self.base_selenium.password) self.base_selenium.wait_until_page_url_has(text='dashboard') self.article_page.get_article_page() @parameterized.expand(['save', 'cancel']) def test001_cancel_button_edit_unit(self, save): """ New: Article: Save/Cancel button: After I edit unit field then press on cancel button, a pop up will appear that the data will be LIMS-3586 LIMS-3576 :return: """ self.article_page.get_random_article() article_url = self.base_selenium.get_url() self.base_selenium.LOGGER.info( ' + article_url : {}'.format(article_url)) current_unit = self.article_page.get_unit() new_unit = self.generate_random_string() self.article_page.set_unit(new_unit) if 'save' == save: self.article_page.save() else: self.article_page.cancel(force=True) self.base_selenium.get(url=article_url, sleep=self.base_selenium.TIME_MEDIUM) article_unit = self.article_page.get_unit() if 'save' == save: self.base_selenium.LOGGER.info( ' + Assert {} (new_unit) == {} (article_unit)'.format( new_unit, article_unit)) self.assertEqual(new_unit, article_unit) else: self.base_selenium.LOGGER.info( ' + Assert {} (current_unit) == {} (article_unit)'.format( current_unit, article_unit)) self.assertEqual(current_unit, article_unit) @parameterized.expand(['save', 'cancel']) def test002_cancel_button_edit_no(self, save): """ New: Article: Save/Cancel button: After I edit no field then press on cancel button, a pop up will appear that the data will be LIMS-3586 LIMS-3576 :return: """ self.article_page.get_random_article() article_url = self.base_selenium.get_url() self.base_selenium.LOGGER.info( ' + article_url : {}'.format(article_url)) current_no = self.article_page.get_no() new_no = self.generate_random_string() self.article_page.set_no(new_no) if 'save' == save: self.article_page.save() else: self.article_page.cancel(force=True) self.base_selenium.get(url=article_url, sleep=self.base_selenium.TIME_MEDIUM) article_no = self.article_page.get_no() if 'save' == save: self.base_selenium.LOGGER.info( ' + Assert {} (new_no) == {} (article_no)'.format( new_no, article_no)) self.assertEqual(new_no, article_no) else: self.base_selenium.LOGGER.info( ' + Assert {} (current_no) == {} (article_no)'.format( current_no, article_no)) self.assertEqual(current_no, article_no) @parameterized.expand(['save', 'cancel']) def test003_cancel_button_edit_name(self, save): """ New: Article: Save/Cancel button: After I edit name then press on cancel button, a pop up will appear that the data will be LIMS-3586 LIMS-3576 :return: """ self.article_page.get_random_article() article_url = self.base_selenium.get_url() self.base_selenium.LOGGER.info( ' + article_url : {}'.format(article_url)) current_name = self.article_page.get_name() new_name = self.generate_random_string() self.article_page.set_name(new_name) if 'save' == save: self.article_page.save() else: self.article_page.cancel(force=True) self.base_selenium.get(url=article_url, sleep=self.base_selenium.TIME_MEDIUM) article_name = self.article_page.get_name() if 'save' == save: self.base_selenium.LOGGER.info( ' + Assert {} (new_name) == {} (article_name)'.format( new_name, article_name)) self.assertEqual(new_name, article_name) else: self.base_selenium.LOGGER.info( ' + Assert {} (current_name) == {} (article_name)'.format( current_name, article_name)) self.assertEqual(current_name, article_name) @parameterized.expand(['save', 'cancel']) def test004_cancel_button_edit_comment(self, save): """ New: Article: Save/Cancel button: After I edit comment then press on cancel button, a pop up will appear that the data will be LIMS-3586 LIMS-3576 :return: """ self.article_page.get_random_article() article_url = self.base_selenium.get_url() self.base_selenium.LOGGER.info( ' + article_url : {}'.format(article_url)) current_comment = self.article_page.get_comment() new_comment = self.generate_random_string() self.article_page.set_comment(new_comment) if 'save' == save: self.article_page.save() else: self.article_page.cancel(force=True) self.base_selenium.get(url=article_url, sleep=self.base_selenium.TIME_MEDIUM) article_comment = self.article_page.get_comment() if 'save' == save: self.base_selenium.LOGGER.info( ' + Assert {} (new_comment) == {} (article_comment)'.format( new_comment, article_comment)) self.assertEqual(new_comment, article_comment) else: self.base_selenium.LOGGER.info( ' + Assert {} (current_comment) == {} (article_comment)'. format(current_comment, article_comment)) self.assertEqual(current_comment, article_comment) @parameterized.expand(['save', 'cancel']) def test005_cancel_button_edit_material_type(self, save): """ New: Article: Save/Cancel button: After I edit material_type then press on cancel button, a pop up will appear that the data will be LIMS-3586 LIMS-3576 :return: """ self.article_page.get_random_article() article_url = self.base_selenium.get_url() self.base_selenium.LOGGER.info( ' + article_url : {}'.format(article_url)) current_material_type = self.article_page.get_material_type() self.article_page.set_material_type(random=True) new_material_type = self.article_page.get_material_type() if 'save' == save: self.article_page.save() else: self.article_page.cancel(force=True) self.base_selenium.get(url=article_url, sleep=5) article_material = self.article_page.get_material_type() if 'save' == save: self.base_selenium.LOGGER.info( ' + Assert {} (new_material_type) == {} (article_material_type)' .format(new_material_type, article_material)) self.assertEqual(new_material_type, self.article_page.get_material_type()) else: self.base_selenium.LOGGER.info( ' + Assert {} (current_material_type) == {} (article_material_type)' .format(current_material_type, article_material)) self.assertEqual(current_material_type, self.article_page.get_material_type()) def test006_archived_articles_shoudnt_dispaly_in_test_plan(self): """ New: Article: In case I archived any article this article shouldn't display in the test plan module when I create test plan or edit it LIMS-3668 :return: """ self.article_page.create_new_article(material_type='Raw Material') self.base_selenium.LOGGER.info(' + Archive the article.') self.article_page.archive_article(name=self.article_page.article_name) self.test_plan.get_test_plans_page() self.base_selenium.LOGGER.info( ' + Create test plan with the same material type.') self.test_plan.click_create_test_plan_button() self.test_plan.set_material_type( material_type=self.article_page.article_material_type) self.article_page.sleep_tiny() self.base_selenium.LOGGER.info( ' + Assert article is not existing in the list.') self.assertFalse( self.test_plan.is_article_existing( article=self.article_page.article_name)) def test007_archived_articles_shoudnt_dispaly_in_order(self): """ New: Article: Archived any article this article shouldn't display in the order module LIMS-3668 :return: """ self.article_page.create_new_article(material_type='Raw Material') self.article_page.archive_article(name=self.article_page.article_name) self.order.get_orders_page() self.order.click_create_order_button() self.order.set_new_order() self.order.set_material_type( material_type=self.article_page.article_material_type) self.article_page.sleep_tiny() self.assertFalse( self.order.is_article_existing( article=self.article_page.article_name)) def test008_created_article_appear_in_test_plan(self): """ New: Article/Test plan: Any article I created should appear in the test plan according to the materiel type. LIMS-3581 :return: """ self.article_page.create_new_article(material_type='Raw Material') self.test_plan.get_test_plans_page() self.test_plan.click_create_test_plan_button() self.test_plan.set_material_type( material_type=self.article_page.article_material_type) self.article_page.sleep_tiny() self.assertTrue( self.test_plan.is_article_existing( article=self.article_page.article_name)) def test009_create_article_with_test_plan_search_by_test_plan(self): """ In case I create test plan with the article that I created, this test plan should display in the table view LIMS-3583 :return: """ self.article_page.create_new_article(material_type='Raw Material') self.test_plan.get_test_plans_page() self.test_plan.create_new_test_plan( material_type=self.article_page.article_material_type, article=self.article_page.article_name) self.article_page.get_article_page() self.article_page.sleep_small() article = self.article_page.search( value=self.test_plan.test_plan_name)[0] self.assertIn(self.test_plan.test_plan_name, article.text) self.test_plan.get_test_plans_page() self.test_plan.get_test_plan_edit_page( name=self.test_plan.test_plan_name) self.test_plan.clear_article() self.test_plan.set_article(article='All') self.test_plan.save() self.article_page.get_article_page() article = self.article_page.search(self.article_page.article_name)[0] self.assertNotIn(self.test_plan.test_plan_name, article.text) def test010_create_article_with_test_plan_filter_by_test_plan(self): """ In case I create test plan with the article that I created, user could filter with test plan LIMS-3583 :return: """ self.article_page.create_new_article(material_type='Raw Material') self.test_plan.get_test_plans_page() self.test_plan.create_new_test_plan( material_type=self.article_page.article_material_type, article=self.article_page.article_name) self.article_page.get_article_page() self.article_page.sleep_small() self.article_page.filter_by_test_plan( filter_text=self.test_plan.test_plan_name) article = self.article_page.filter_result()[0] self.base_selenium.LOGGER.info( ' + Assert user could filter with test plan.') self.assertIn(self.test_plan.test_plan_name, article.text) def test011_archive_articles(self): """ New: Article: Archive Approach: I can archive/restore any article successfully LIMS-3587 :return: """ selected_articles_data, _ = self.article_page.select_random_multiple_table_rows( ) self.article_page.archive_selected_articles() self.article_page.get_archived_articles() for article in selected_articles_data: article_name = article['Article Name'] self.base_selenium.LOGGER.info( ' + {} article should be activated.'.format(article_name)) self.assertTrue( self.article_page.is_article_archived(value=article_name)) def test012_restore_articles(self): """ New: Article: Restore Approach: I can archive/restore any article successfully LIMS-3587 :return: """ article_names = [] self.article_page.get_archived_articles() selected_articles_data, _ = self.article_page.select_random_multiple_table_rows( ) for article in selected_articles_data: article_names.append(article['Article Name']) self.article_page.restore_selected_articles() self.article_page.get_active_articles() for article_name in article_names: self.assertTrue( self.article_page.is_article_archived(value=article_name)) def test013_create_new_material_type(self): """ Article: Materiel type Approach: make sure you can create new materiel type & this materiel type displayed correct according to this article. LIMS-3582 :return: """ material_type = self.generate_random_string() self.article_page.create_new_article(material_type=material_type) self.test_plan.get_test_plans_page() self.test_plan.click_create_test_plan_button() self.test_plan.set_material_type( material_type=self.article_page.article_material_type) self.article_page.sleep_tiny() self.assertTrue( self.test_plan.is_article_existing( article=self.article_page.article_name)) def test014_article_search(self): """ New: Articles: Search Approach: I can search by any field in the table view LIMS-3594 :return: """ row = self.article_page.get_random_article_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] == '': continue self.base_selenium.LOGGER.info(' + search for {} : {}'.format( column, row_data[column])) search_results = self.article_page.search(row_data[column]) self.assertGreater( len(search_results), 1, " * There is no search results for it, Report a bug.") 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 test015_green_border(self): """ New: All modules: Creation Approach: Green border displayed when I create new record LIMS-3597 :return: """ self.article_page.create_new_article(sleep=False, material_type='Raw Material') self.assertEqual( self.base_selenium.get_text(element='articles:alert_confirmation'), 'Successfully created') def test016_create_full_options_article(self): """ New: Articles: Creation Approach: I can create new article successfully LIMS-3575 :return: """ self.article_page.create_new_article(full_options=True, material_type='Raw Material') article_text = self.article_page.search( value=self.article_page.article_name)[0].text self.assertIn(self.article_page.article_unit, article_text) self.assertIn(self.article_page.article_comment, article_text) self.assertIn(self.article_page.article_material_type, article_text) def test017_delete_article_with_test_plan(self): """ New: Articles: Delete Approach; I can't delete any article if this article related to some data LIMS-3577 :return: """ self.article_page.create_new_article(material_type='Raw Material') self.test_plan.get_test_plans_page() self.test_plan.create_new_test_plan( material_type=self.article_page.article_material_type, article=self.article_page.article_name) self.article_page.get_article_page() self.article_page.sleep_small() article = self.article_page.search( value=self.test_plan.test_plan_name)[0] self.article_page.click_check_box(source=article) self.article_page.archive_selected_articles() self.article_page.get_archived_articles() archived_article = self.article_page.search( value=self.test_plan.test_plan_name)[0] self.article_page.click_check_box(source=archived_article) self.assertFalse(self.article_page.delete_selected_article()) def test018_delete_article_with_order(self): """ New: Articles: Delete Approach; I can't delete any article if this article related to some data LIMS-3577 :return: """ self.base_selenium.LOGGER.info( ' + Create new article with Raw Material.') self.article_page.create_new_article(material_type='Raw Material') self.test_plan.get_test_plans_page() self.base_selenium.LOGGER.info( ' + Create new test plan with {} article.'.format( self.article_page.article_name)) self.test_plan.create_new_test_plan( material_type=self.article_page.article_material_type, article=self.article_page.article_name, test_unit='Qualitative') self.order.get_orders_page() self.order.click_create_order_button() self.base_selenium.LOGGER.info( ' + Create new order with {} article.'.format( self.article_page.article_name)) self.order.create_new_order( article=self.article_page.article_name, material_type=self.article_page.article_material_type, test_plan=self.test_plan.test_plan_name) self.article_page.get_article_page() self.article_page.sleep_small() self.base_selenium.LOGGER.info( ' + Search for active article with {} test plan.'.format( self.test_plan.test_plan_name)) search_results = self.article_page.search( value=self.test_plan.test_plan_name) self.assertGreater( len(search_results), 1, " * There is no search results for it, Report a bug.") for search_result in search_results: search_data = self.base_selenium.get_row_cells_dict_related_to_header( search_result) if self.test_plan.test_plan_name in search_data['Test Plans']: break self.base_selenium.LOGGER.debug(' Article test plan : {} '.format( search_data['Test Plans'])) else: raise ValueError( " There is no active article with {} test plan".format( self.test_plan.test_plan_name)) self.base_selenium.LOGGER.info(' + Archive this article.') self.article_page.click_check_box(source=search_result) self.article_page.archive_selected_articles() self.article_page.get_archived_articles() self.base_selenium.LOGGER.info( ' + Search for archived article with {} test plan.'.format( self.test_plan.test_plan_name)) search_results = self.article_page.search( value=self.test_plan.test_plan_name) self.assertGreater( len(search_results), 1, " * There is no search results for it, Report a bug.") for search_result in search_results: search_data = self.base_selenium.get_row_cells_dict_related_to_header( search_result) if self.test_plan.test_plan_name in search_data['Test Plans']: break self.base_selenium.LOGGER.debug(' Article test plan : {} '.format( search_data['Test Plans'])) else: raise ValueError( " There is no archived article with {} test plan".format( self.test_plan.test_plan_name)) self.base_selenium.LOGGER.info(' + Delete this article, should fail.') self.article_page.click_check_box(source=search_result) self.assertFalse(self.article_page.delete_selected_article()) def test019_download_article_sheet(self): """ New: Articles: XSLX File: I can download all the data in the table view in the excel sheet LIMS:3589 :return: """ self.base_selenium.LOGGER.info(' * Download XSLX sheet') self.article_page.download_xslx_sheet() rows_data = self.article_page.get_articles_rows_data() for index in range(len(rows_data)): self.base_selenium.LOGGER.info( ' * Comparing the article no. {} '.format(index)) fixed_row_data = self.fix_data_format(rows_data[index].split('\n')) values = self.article_page.article_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)
class BaseTest(TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @classmethod def setUpClass(cls) -> None: cls.create_screenshots_dir() cls.base_selenium = BaseSelenium() cls.base_selenium.get_driver() cls.base_selenium.get(url=cls.base_selenium.url) cls.pass_refresh_feature() cls.set_authorization(auth=BaseAPI().AUTHORIZATION_RESPONSE) def setUp(self): print('\t') self.info('Test case : {}'.format(self._testMethodName)) # self.base_selenium.get(url=self.base_selenium.url) # self.base_selenium.wait_until_page_load_resources() def tearDown(self): self.screen_shot() self.info('go to dashboard page') self.base_selenium.get(url=f"{self.base_selenium.url}dashboard") self.info('TearDown. \t') @classmethod def tearDownClass(cls) -> None: cls.base_selenium.quit_driver() def screen_shot(self): try: method, error = self._outcome.errors[0] if error: screen_shot = f"./screenshots/screenshot_{method._testMethodName}_.png" self.info(f"saved error screen shot : {screen_shot}") self.base_selenium.driver.get_screenshot_as_file( f"./screenshots/screenshot_{method._testMethodName}_.png") except: pass def generate_random_string(self): return str(uuid4()).replace("-", "")[:10] def generate_random_number(self, lower=1, upper=100000): return randint(lower, upper) def fix_data_format(self, data_list): tmp = [] for item in data_list: if len(str(item)) > 0: if re.search(r'\d{2}.\d{2}.\d{4},\s\d{1,2}:\d{1,2}\s(A|P)M', str(item)): tmp.append( datetime.datetime.strptime(item, '%d.%m.%Y, %H:%M %p')) elif re.search(r'\d{2}\.\d{2}\.\d{4}', str(item)): tmp.append(datetime.datetime.strptime(item, '%d.%m.%Y')) elif str(item) in ["-", "nan", "N/A"]: continue elif ',' in str(item) and '&' in str(item): item = str(item).replace('&', ',') tmp.extend(str(item).split(',')) elif ',' in str(item): tmp.extend(str(item).split(',')) elif ', ' in str(item): tmp.extend(str(item).split(', ')) elif '&' in str(item): tmp.extend(str(item).split('&')) elif ' ' == str(item)[-1]: tmp.append(item[:-1]) elif 'all' == str(item)[-1]: tmp.append('All') else: tmp.append( str(item).replace(',', '&').replace("'", "").replace(' - ', '-')) return tmp def reformat_data(self, data_list): tmp = [] for item in data_list: if len(str(item)) > 0: tmp.append(str(item).replace(',', ' &').replace("'", "")) return tmp def get_active_article_with_tst_plan(self, test_plan_status='complete'): self.test_plan = TstPlan() self.article_page = Article() self.info( 'Get Active article with {} test plan.'.format(test_plan_status)) self.test_plan.get_test_plans_page() complete_test_plans = self.test_plan.search(test_plan_status) complete_test_plans_dict = [ self.base_selenium.get_row_cells_dict_related_to_header( row=complete_test_plan) for complete_test_plan in complete_test_plans[:-1] ] self.article_page.get_articles_page() for complete_test_plan_dict in complete_test_plans_dict: self.info('Is {} article in active status?'.format( complete_test_plan_dict['Article Name'])) if self.article_page.is_article_in_table( value=complete_test_plan_dict['Article Name']): self.info('Active.') return complete_test_plan_dict else: self.info('Archived.') else: return {} def get_multiple_active_article_with_tst_plan(self, test_plan_status='complete'): self.test_plan = TstPlan() self.article_page = Article() self.info( 'Get Active articles with {} test plans.'.format(test_plan_status)) self.test_plan.get_test_plans_page() complete_test_plans = self.test_plan.search(test_plan_status) complete_test_plans_dict = [ self.base_selenium.get_row_cells_dict_related_to_header( row=complete_test_plan) for complete_test_plan in complete_test_plans[:-1] ] self.article_page.get_articles_page() test_plans_list = [] for complete_test_plan_dict in complete_test_plans_dict: self.info('Is {} article in active status?'.format( complete_test_plan_dict['Article Name'])) if self.article_page.is_article_in_table( value=complete_test_plan_dict['Article Name']): self.info('Active.') test_plans_list.append(complete_test_plan_dict) else: self.LOGGER.info('Archived.') else: return {} return test_plans_list def get_active_tst_unit_with_material_type(self, search, material_type='Raw Material'): self.test_unit_page = TstUnit() self.info('Get Test Unit with type {} .'.format(search)) self.test_unit_page.get_test_units_page() test_units = self.test_unit_page.search(search) test_units_dict = [ self.base_selenium.get_row_cells_dict_related_to_header( row=test_unit) for test_unit in test_units[:-1] ] for test_unit_dict in test_units_dict: if test_unit_dict[ 'Type'] == search and material_type in test_unit_dict[ 'Material Type']: return test_unit_dict return {} ''' Removes the data that was changed in the duplication process in order to compare between the objects to make sure that the duplication was done correcly. ''' def remove_unduplicated_data(self, data_changed=[], first_element=[], second_element=[]): for data in data_changed: if data in first_element and data in second_element: if first_element[data] != None: del first_element[data] if second_element[data] != None: del second_element[data] return first_element, second_element @property def info(self): return self.base_selenium.LOGGER.info @property def debug(self): return self.base_selenium.LOGGER.debug @classmethod def set_authorization(cls, auth): if "Admin" == auth.get('role'): del auth['role'] auth['roles'] = ["Admin"] cls.base_selenium.set_local_storage('modeso-auth-token', auth) @classmethod def pass_refresh_feature(cls): with cls.base_selenium._change_implicit_wait(new_value=2): try: cls.base_selenium.driver.find_element_by_xpath( "//button[@class='btn btn-primary']").click() except: pass @staticmethod def create_screenshots_dir(): dir = 'screenshots' if os.path.exists(dir): shutil.rmtree(dir, ignore_errors=True) os.mkdir(dir)
class TestPlansTestCases(BaseTest): def setUp(self): super().setUp() self.test_plan = TstPlan() self.test_plan_api = TestPlanAPI() self.article_api = ArticleAPI() self.test_plan.get_test_plans_page() self.test_plan_api.set_configuration() def test001_test_plan_delete_testunit(self): """ Testing deleting a test unit from test-plan create or update step two It deletes the first test unit in the chosen test plan and saves this, then refreshes the page and checks if the deletion was done correctly. LIMS-3504 """ self.info("get random completed test plan") random_completed_test_plan = random.choice( self.test_plan_api.get_completed_testplans()) self.info("navigate to the test-plan No. {} edit page".format( random_completed_test_plan['number'])) self.test_plan.get_test_plan_edit_page_by_id( random_completed_test_plan['id']) old_testunits = self.test_plan.get_all_testunits_in_testplan() self.assertTrue(old_testunits, "There's no test units in this test plan") deleted_test_unit = (old_testunits[0])[0] self.info("delete the first test unit with name {}".format( deleted_test_unit)) self.test_plan.delete_the_first_testunit_from_the_tableview() self.info( "save the changes and refresh to make sure test unit deleted") self.test_plan.save_and_confirm_popup() all_testunits = self.test_plan.get_all_testunits_in_testplan() self.info('Checking if the changes were saved successfully') deleted_test_unit_found = self.test_plan.check_if_deleted_testunit_is_available( all_testunits=all_testunits, deleted_test_unit=deleted_test_unit) self.assertFalse(deleted_test_unit_found) @parameterized.expand(['InProgress', 'Completed']) def test002_test_plan_edit_status(self, status): """ Creation Approach: when the status converted from completed to completed, new version created when the status converted from In-Progress to completed, no new version created LIMS-3502 LIMS-3501 """ self.info( "create test unit of material type = All to complete test plan") response, test_unit = TestUnitAPI().create_qualitative_testunit() self.assertEqual(response['status'], 1, 'can not create test unit') testplan = random.choice( self.test_plan_api.get_testplans_with_status(status=status)) self.assertTrue(testplan, 'No test plan selected') self.info( 'Navigate to edit page of test plan: {} with version: {}'.format( testplan['testPlanName'], testplan['version'])) self.test_plan.get_test_plan_edit_page_by_id(testplan['id']) self.info('Going to step 2 to add test unit to this test plan') self.test_plan.sleep_tiny() self.test_plan.set_test_unit(test_unit=test_unit['name']) if status == 'InProgress': self.info('Saving and completing the test plan') self.test_plan.save(save_btn='test_plan:save_and_complete', sleep=True) else: self.info('Saving and confirm pop up') self.test_plan.save_and_confirm_popup() self.info( "go back to the active table and get test plan to check its version and status" ) self.test_plan.get_test_plans_page() new_test_plan_version, test_plan_row_data_status = \ self.test_plan.get_testplan_version_and_status(search_text=testplan['testPlanName']) if status == 'InProgress': self.assertEqual(int(new_test_plan_version), testplan['version']) else: self.assertGreater(int(new_test_plan_version), int(testplan['version'])) self.assertEqual(test_plan_row_data_status, 'Completed') def test003_archive_test_plan_one_record(self): """ Archive one record LIMS-3506 Case 1 """ self.info('choosing a random test plan table row') selected_test_plan = self.test_plan.select_random_table_row() self.assertTrue(selected_test_plan) self.info(f'selected_test_plan : {selected_test_plan}') testplan_number = selected_test_plan['Test Plan No.'] self.info( 'Archive the selected item and navigating to the archived items table' ) self.test_plan.archive_selected_items() self.test_plan.get_archived_items() archived_row = self.test_plan.search(testplan_number) self.info( 'Checking if test plan number: {} is archived correctly'.format( testplan_number)) self.assertIn(selected_test_plan['Test Plan Name'], archived_row[0].text) self.info('Test plan number: {} is archived correctly'.format( testplan_number)) def test004_restore_test_plan_one_record(self): """ Restore one record LIMS-3506 Case 1 """ self.info("Navigate to archived test plan table") self.test_plan.get_archived_items() self.info('Choosing a random testplan table row') self.test_plan.sleep_tiny() selected_test_plan = self.test_plan.select_random_table_row() self.info(f"selected_test_plan : {selected_test_plan}") self.assertTrue(selected_test_plan) testplan_number = selected_test_plan['Test Plan No.'] self.info('select Testplan number: {} to be restored'.format( testplan_number)) self.info( 'Restoring the selected item then navigating to the active items table' ) self.test_plan.restore_selected_items() self.test_plan.get_active_items() self.test_plan.filter_by_testplan_number(filter_text=testplan_number) restored_row = self.test_plan.result_table() self.info( 'Checking if testplan number: {} is restored correctly'.format( testplan_number)) self.assertIn(selected_test_plan['Test Plan Name'], restored_row[0].text) self.info('Testplan number: {} is restored correctly'.format( testplan_number)) def test005_archive_test_plan_multiple_records(self): """ Archive multiple records LIMS-3506 Case 2 """ self.info('Choosing random multiple test plans table rows') self.test_plan.sleep_small() rows_data, rows = self.test_plan.select_random_multiple_table_rows() self.assertTrue(rows_data) testplans_numbers = [row['Test Plan No.'] for row in rows_data] self.info( 'Testplan numbers: {} will be archived'.format(testplans_numbers)) self.info( 'Archiving the selected items and navigating to the archived items table' ) self.test_plan.archive_selected_items() self.test_plan.sleep_small() self.info('Checking if testplans are archived correctly') self.test_plan.get_archived_items() archived_rows = self.test_plan.filter_multiple_rows_by_testplans_numbers( testplans_numbers) self.assertIsNotNone(archived_rows) self.assertEqual(len(archived_rows), len(testplans_numbers)) self.info('Testplan numbers: {} are archived correctly'.format( testplans_numbers)) def test006_restore_test_plan_multiple_records(self): """ Rstore multiple records LIMS-3506 Case 2 """ self.info("Navigate to archived test plan table") self.test_plan.sleep_tiny() self.test_plan.get_archived_items() self.info('Choosing random multiple test plans table rows') self.test_plan.sleep_tiny() rows_data, rows = self.test_plan.select_random_multiple_table_rows() self.assertTrue(rows_data) testplans_numbers = [row['Test Plan No.'] for row in rows_data] self.info( 'Restore Test plans with numbers: {}'.format(testplans_numbers)) self.test_plan.restore_selected_items() self.test_plan.sleep_small() self.info('Navigate to active table and make sure test plans restored') self.test_plan.get_active_items() restored_rows = self.test_plan.filter_multiple_rows_by_testplans_numbers( testplans_numbers) self.assertIsNotNone(restored_rows) self.assertEqual(len(restored_rows), len(testplans_numbers)) self.info('Test plans numbers: {} are restored correctly'.format( testplans_numbers)) @skip('https://modeso.atlassian.net/browse/LIMS-6403') def test007_exporting_test_plan_one_record(self): """ Exporting one record LIMS-3508 Case 1 """ self.info('choosing a random testplan table row') row = self.test_plan.get_random_table_row('general:table') row_data = self.base_selenium.get_row_cells_dict_related_to_header( row=row) testplan_number = row_data['Test Plan No.'] self.info( 'testplan number: {} will be exported'.format(testplan_number)) self.info('Selecting the test plan row') self.test_plan.click_check_box(source=row) self.info('download XSLX sheet of selected test plan') self.test_plan.download_xslx_sheet() row_data_list = list(row_data.values()) self.info('comparing the testplan no. {} '.format(testplan_number)) values = self.test_plan.sheet.iloc[0].values fixed_sheet_row_data = self.fix_data_format(values) fixed_row_data_list = self.fix_data_format(row_data_list) for item in fixed_row_data_list: self.assertIn(item, fixed_sheet_row_data) @skip('https://modeso.atlassian.net/browse/LIMS-6403') def test008_exporting_test_plan_multiple_records(self): """ Exporting multiple records LIMS-3508 Case 2 """ self.info('choosing random multiple testplans table rows') row_data_list = self.test_plan.select_random_multiple_table_rows( element='general:table')[0] self.test_plan.download_xslx_sheet() row_data = [] sheet_data = [] for index in range(len(row_data_list)): row_data.append(self.fix_data_format( row_data_list[index].values())) sheet_data.append( self.fix_data_format(self.test_plan.sheet.iloc[index].values)) row_data = sorted(row_data) sheet_data = sorted(sheet_data) for index in range(len(row_data)): for item in row_data[index]: self.assertIn(item, sheet_data[index]) def test009_test_plan_duplicate(self): """ Duplicate a test plan LIMS-3679 """ self.info('Choosing a random testplan table row') testPlan = random.choice(self.test_plan_api.get_completed_testplans()) self.assertTrue(testPlan, "No completed test plan selected") testunits = self.test_plan_api.get_testunits_in_testplan( id=testPlan['id']) self.assertTrue( testunits, "Completed test plan with id {} has no testunits!!".format( testPlan['id'])) self.info("select test plan {}".format(testPlan['testPlanName'])) self.test_plan.filter_by_testplan_number(testPlan['number']) row = self.test_plan.result_table()[0] self.test_plan.click_check_box(source=row) self.info('Duplicating testplan number: {}'.format(testPlan['number'])) self.test_plan.duplicate_selected_item() duplicated_test_plan_number = self.test_plan.duplicate_testplan( change=['name']) self.info('testplan duplicated with number: {}'.format( duplicated_test_plan_number)) self.info('get duplicated test plan data and child table data') duplicated_testplan_data, duplicated_testplan_childtable_data = \ self.test_plan.get_specific_testplan_data_and_childtable_data( filter_by='number', filter_text=duplicated_test_plan_number) duplicated_test_units = [] for testunit in duplicated_testplan_childtable_data: duplicated_test_units.append(testunit['Test Unit Name']) self.info('Asserting that the data is duplicated correctly') self.assertEqual(testPlan['materialTypes'][0], duplicated_testplan_data['Material Type']) self.assertEqual(testPlan['article'][0], duplicated_testplan_data['Article Name']) self.assertEqual(testPlan['articleNo'][0], duplicated_testplan_data['Article No.']) for testunit in testunits: self.assertIn(testunit['name'], duplicated_test_units) def test010_test_plan_completed_to_inprogress(self): """ When the test plan status is converted from completed to in progress a new version is created LIMS-3503 """ self.info('get random completed test plan') completed_testplan = random.choice( self.test_plan_api.get_completed_testplans()) self.assertTrue(completed_testplan, "There's no completed test plans!") self.info( 'Navigating to edit page of testplan: {} with version: {}'.format( completed_testplan['testPlanName'], completed_testplan['version'])) self.test_plan.get_test_plan_edit_page_by_id(completed_testplan['id']) self.info('Going to step 2 to remove all the test units from it') self.test_plan.navigate_to_testunits_selection_page() self.test_plan.sleep_tiny() self.test_plan.delete_all_testunits() self.test_plan.save_and_confirm_popup() self.info("go back to active table") self.test_plan.get_test_plans_page() self.info( 'Getting the currently changed testplan to check its status and version' ) inprogress_testplan_version, testplan_row_data_status = \ self.test_plan.get_testplan_version_and_status(search_text=completed_testplan['testPlanName']) self.assertEqual(completed_testplan['version'] + 1, int(inprogress_testplan_version)) self.assertEqual(testplan_row_data_status, 'In Progress') @parameterized.expand(['same', 'All']) def test011_create_testplans_same_name_article_materialtype(self, same): """ Testing the creation of two testplans with the same name, material type and article, this shouldn't happen LIMS-3499 New: Test plan: Creation Approach: I can't create two test plans with the same name & same materiel type & one with any article and the other one all LIMS-3500 """ payload = self.test_plan_api.create_completed_testplan_random_data() self.test_plan.click_create_test_plan_button() self.test_plan.set_test_plan(name=payload['testPlan']['text']) self.assertFalse( self.test_plan.is_material_type_existing( material_type=payload['materialType'][0]['text'])) def test012_create_testplans_same_name_different_materialtype(self): """ Testing the creation of two testplans with the same name, but different material type and article. It should be created successfully. LIMS-3498 """ self.info('create complete test plan') payload = self.test_plan_api.create_completed_testplan_random_data() self.assertTrue(payload, 'can not create a tesplan') articles = self.article_api.get_all_articles_json() for article in articles: if article['name'] != payload['selectedArticles'][0]['text'] and article['materialType'] != \ payload['materialType'][0]['text']: self.info( 'create another testplan with the same name, but with different material type and article name' ) second_testplan_name = self.test_plan.create_new_test_plan( name=payload['testPlan']['text'], material_type=article['materialType'], article=article['name']) self.info( 'new testplan is created successfully with name: {}, article name: {} and material type: {}' .format(second_testplan_name, self.test_plan.article, self.test_plan.material_type)) self.assertEqual(payload['testPlan']['text'], second_testplan_name) data = self.test_plan.search(second_testplan_name) self.assertGreaterEqual(len(data), 2) break def test013_delete_used_testplan(self): """ If a test plan is used, it can't be deleted LIMS-3509 """ self.info("create order with test plan") response, payolad = OrdersAPI().create_new_order() self.assertEqual(response['status'], 1, payolad) self.info("created order no {} has testplan name {}".format( payolad[0]['orderNo'], payolad[0]['testPlans'][0]['name'])) self.info('testplan name: {} will be archived'.format( payolad[0]['testPlans'][0]['name'])) self.test_plan.base_selenium.refresh() testplan_deleted = self.test_plan.delete_selected_item_from_active_table_and_from_archived_table( item_name=payolad[0]['testPlans'][0]['name']) self.info( "check for the error popup that this testplan is used and can't be deleted" ) self.assertFalse(testplan_deleted) def test014_archived_testplan_shouldnot_appear_in_order(self): """ In case a testplan is archived, it shouldn't appear when creating a new order LIMS-3708 """ self.info("navigate to orders page") self.order_page = Order() self.info("get random archived testplan") response, payload = self.test_plan_api.get_all_test_plans() self.assertEqual(response['status'], 1, payload) archived_test_plan = random.choice(response['testPlans']) self.test_plan_api.archive_testplans( ids=[str(archived_test_plan['id'])]) self.order_page.get_orders_page() self.info("archived test plan data {}".format(archived_test_plan)) self.info( "create a new order with material type and article of archived testplan" ) if archived_test_plan['article'] != ['all']: self.order_page.create_new_order( material_type=archived_test_plan['materialTypes'][0], article=archived_test_plan['article'][0], test_plans=[archived_test_plan['testPlanName']]) else: self.order_page.create_new_order( material_type=archived_test_plan['materialTypes'][0], test_plans=[archived_test_plan['testPlanName']]) order_data = self.order_page.get_suborder_data() self.info( "get the first suborder's testplan and make sure it's an empty string" ) self.assertCountEqual(order_data['suborders'][0]['testplans'], ['']) def test015_testunit_sub_super_scripts(self): """ Create a testunit with sub/super scripts, use this testunit to create a testplan and check the sub/super scripts in the card view LIMS-5796 """ self.info("create test unit with sub and super scripts") response, payload = TestUnitAPI().create_qualitative_testunit( unit='mg[2]{o}') self.assertEqual(response['status'], 1, payload) self.info("created test unit data {}".format(payload)) self.info("create test plan with same created test unit data") if payload['selectedMaterialTypes'][0]['text'] == 'All': self.test_plan.create_new_test_plan(test_unit=payload['name'], save=False) else: self.test_plan.create_new_test_plan( material_type=payload['selectedMaterialTypes'][0]['text'], test_unit=payload['name'], save=False) unit = self.base_selenium.find_element('test_plan:testunit_unit').text self.assertEqual(unit, 'mg2o') def test016_filter_by_testplan_number(self): """ User can filter with testplan number LIMS-6473 """ self.info("select random test plan") random_testplan = random.choice( self.test_plan_api.get_all_test_plans_json()) self.info("selected_test_plan No {}".format(random_testplan['number'])) self.test_plan.filter_by_testplan_number(random_testplan['number']) testplan_found = self.test_plan.result_table() self.assertIn(str(random_testplan['number']), (testplan_found[0].text).replace("'", "")) self.info('Filtering by number was done successfully') def test017_filter_by_testplan_name(self): """ User can filter with testplan name LIMS-6470 """ random_testplan = random.choice( self.test_plan_api.get_all_test_plans_json()) self.assertTrue(random_testplan, "can't select random test plan !") testplans_found_text = self.test_plan.filter_by_element_and_get_text( 'Testplan Name', 'test_plans:testplan_name_filter', random_testplan['testPlanName'], 'drop_down') for tp_text in testplans_found_text: self.assertIn(str(random_testplan['testPlanName']), tp_text.replace("'", "")) @parameterized.expand(['Completed', 'In Progress']) def test018_filter_by_testplan_status(self, status): """ User can filter with status LIMS-6474 """ testplans_found_text = \ self.test_plan.filter_by_element_and_get_text('Status', 'test_plans:testplan_status_filter', status, 'drop_down') for tp_text in testplans_found_text: self.assertIn(status, tp_text) if status == "In Progress": self.assertNotIn('Completed', tp_text) else: self.assertNotIn('In Progress', tp_text) def test019_filter_by_testplan_changed_by(self): """ User can filter with changed by field LIMS-6475 """ self.login_page = Login() self.info('Calling the users api to create a new user with username') response, payload = UsersAPI().create_new_user() self.assertEqual(response['status'], 1, payload) self.test_plan.sleep_tiny() self.login_page.logout() self.test_plan.sleep_tiny() self.login_page.login(username=payload['username'], password=payload['password']) self.base_selenium.wait_until_page_url_has(text='dashboard') self.test_plan.get_test_plans_page() self.test_plan.sleep_tiny() testplan_name = self.test_plan.create_new_test_plan() self.info('New testplan is created successfully with name: {}'.format( testplan_name)) self.test_plan.set_all_configure_table_columns_to_specific_value( value=True) testplan_found = self.test_plan.filter_by_element_and_get_results( 'Changed By', 'test_plans:testplan_changed_by_filter', payload['username'], 'drop_down') self.assertEqual(len(testplan_found), 2) self.assertIn(payload['username'], testplan_found[0].text) self.assertIn(testplan_name, testplan_found[0].text) def test020_filter_by_testplan_material_type(self): """ User can filter with material type field LIMS-6471 """ random_testplan = random.choice( self.test_plan_api.get_all_test_plans_json()) testplans_found_text = self.test_plan.filter_by_element_and_get_text( 'Material Type', 'test_plans:testplan_material_type_filter', random_testplan['materialTypes'][0], 'drop_down') for tp_text in testplans_found_text: self.assertIn(str(random_testplan['materialTypes'][0]), tp_text) def test021_filter_by_testplan_article(self): """ User can filter with article field LIMS-6472 """ random_testplan = random.choice( self.test_plan_api.get_all_test_plans_json()) if random_testplan['article'][0] == 'all': testplans_found_text = self.test_plan.filter_by_element_and_get_text( 'Article', 'test_plans:testplan_article_filter', 'All', 'drop_down') else: testplans_found_text = self.test_plan.filter_by_element_and_get_text( 'Article', 'test_plans:testplan_article_filter', random_testplan['articleNo'][0], 'drop_down') for tp_text in testplans_found_text: self.assertIn(str(random_testplan['article'][0]), tp_text) def test022_filter_by_testplan_created_on(self): """ User can filter with created on field LIMS-6476 """ random_testplan = random.choice( self.test_plan_api.get_all_test_plans_json()) date = datetime.datetime.strptime(random_testplan['createdAt'], "%Y-%m-%dT%H:%M:%S.%fZ") date_formatted = datetime.datetime.strftime(date, '%d.%m.%Y') testplans_found_text = self.test_plan.filter_by_element_and_get_text( 'Created On', 'test_plans:testplan_created_on_filter', date_formatted, 'date') for tp_text in testplans_found_text: self.assertIn(date_formatted, tp_text) @parameterized.expand(['ok', 'cancel']) def test023_create_approach_overview_button(self, ok): """ Master data: Create: Overview button Approach: Make sure after I press on the overview button, it redirects me to the active table LIMS-6203 """ self.info("click on create test plan button") self.test_plan.click_create_test_plan_button() self.info("click on Overview, this will display an alert to the user") self.test_plan.click_overview() # switch to the alert if 'ok' == ok: self.info("confirm pop-up") self.test_plan.confirm_overview_pop_up() self.assertEqual(self.base_selenium.get_url(), '{}testPlans'.format(self.base_selenium.url)) self.info('clicking on Overview confirmed') else: self.info("cancel pop-up") self.test_plan.cancel_overview_pop_up() self.assertEqual(self.base_selenium.get_url(), '{}testPlans/add'.format(self.base_selenium.url)) self.info('clicking on Overview cancelled') def test024_edit_approach_overview_button(self): """ Edit: Overview Approach: Make sure after I press on the overview button, it redirects me to the active table LIMS-6202 """ testplan = random.choice(self.test_plan_api.get_all_test_plans_json()) self.info('Navigate to edit page of test plan: {} '.format( testplan['testPlanName'])) self.test_plan.get_test_plan_edit_page_by_id(testplan['id']) testplans_url = self.base_selenium.get_url() self.info('testplans_url : {}'.format(testplans_url)) self.info('click on Overview, it will redirect you to test plans page') self.test_plan.click_overview() self.test_plan.sleep_tiny() self.assertEqual(self.base_selenium.get_url(), '{}testPlans'.format(self.base_selenium.url)) self.info('clicking on Overview confirmed') def test025_testplans_search_then_navigate(self): """ Search Approach: Make sure that you can search then navigate to any other page LIMS-6201 """ testplan = random.choice(self.test_plan_api.get_all_test_plans_json()) search_results = self.test_plan.search(testplan['testPlanName']) self.assertGreater( len(search_results), 1, " * There is no search results for it, Report a bug.") # Navigate to articles page self.info('navigate to articles page') Articles().get_articles_page() self.assertEqual(self.base_selenium.get_url(), '{}articles'.format(self.base_selenium.url)) def test026_hide_all_table_configurations(self): """ Table configuration: Make sure that you can't hide all the fields from the table configuration LIMS-6288 """ self.assertFalse(self.test_plan.deselect_all_configurations()) def test027_test_unit_update_version_in_testplan(self): """ Test plan: Test unit Approach: In case I update category & iteration of test unit that used in test plan with new version, when go to test plan to add the same test unit , I found category & iteration updated LIMS-3703 """ self.test_unit_page = TstUnit() self.info("select random test unit to create the test plan with it") testunit = random.choice(TestUnitAPI().get_testplan_valid_test_unit()) self.info( 'A random test unit is chosen, its name: {}, category: {} and number of iterations: {}' .format(testunit['name'], testunit['categoryName'], testunit['iterations'])) self.info("create the first testplan") first_testplan_name, payload1 = self.test_plan_api.create_testplan() self.info('First test plan create with name: {}'.format( payload1['testPlan']['text'])) self.info( "go to testplan edit to get the number of iterations and test unit category" ) first_testplan_testunit_category, first_testplan_testunit_iteration = \ self.test_plan.get_testunit_category_iterations(payload1['testPlan']['text'], testunit['name']) self.info( "go to test units' active table and search for this test unit") self.test_unit_page.get_test_units_page() self.info('Navigating to test unit {} edit page'.format( testunit['name'])) self.test_unit_page.open_test_unit_edit_page_by_id(testunit['id']) self.test_unit_page.sleep_small() new_iteration = str(int(first_testplan_testunit_iteration) + 1) new_category = self.generate_random_string() self.info("update the iteration to {} and category to {}".format( new_iteration, new_category)) self.test_unit_page.set_category(new_category) self.test_unit_page.set_testunit_iteration(new_iteration) self.info("press save and complete to create a new version") self.test_unit_page.save_and_create_new_version() self.info(" go back to test plans active table") self.test_plan.get_test_plans_page() self.info( " create new testplan with this testunit after creating the new version" ) response, payload2 = self.test_plan_api.create_testplan() self.assertEqual(response["status"], 1) second_testplan_name = payload2['testPlan']['text'] self.info('Second test plan create with name: {}'.format( second_testplan_name)) self.info( "check the iteration and category to be the same as the new version" ) self.info( "go to testplan edit to get the number of iterations and testunit category" ) second_testplan_testunit_category, second_testplan_testunit_iteration = \ self.test_plan.get_testunit_category_iterations(second_testplan_name, testunit['name']) self.info( 'Asserting that the category of the test unit in the first test plan is not updated' ) self.assertNotEqual(first_testplan_testunit_category, new_category) self.info( 'Asserting that the iterations of the test unit in the first test plan is not updated' ) self.assertNotEqual(first_testplan_testunit_iteration, second_testplan_testunit_iteration) self.info( 'Asserting that the category of the test unit in the second new_iteration is the ' 'same as the updated category') self.assertEqual(second_testplan_testunit_category, new_category) self.info( 'Asserting that the iterations of the test unit in the second testplan is the ' 'same as the updated iterations') self.assertEqual(second_testplan_testunit_iteration, new_iteration) def test028_childtable_limits_of_quantification(self): """ Limits of quantification should be viewed in the testplan's child table LIMS-4179 New: Test plan: Limits of quantification Approach: In case I update the limits of quantification this will trigger new version in the active table & version table LIMS-4426 """ self.info( "Create new quantitative test unit with quantification limits") self.test_unit_api = TestUnitAPI() oldUpperLimit = self.generate_random_number(lower=50, upper=100) oldLowerLimit = self.generate_random_number(lower=1, upper=49) tu_response, tu_payload = self.test_unit_api.create_quantitative_testunit( quantificationUpperLimit=oldUpperLimit, quantificationLowerLimit=oldLowerLimit, useQuantification=True, useSpec=False) self.assertEqual(tu_response['status'], 1, tu_payload) testunit_display_old_quantification_limit = '{}-{}'.format( tu_payload['quantificationLowerLimit'], tu_payload['quantificationUpperLimit']) test_plan = self.test_plan_api.create_testplan_from_test_unit_id( tu_response['testUnit']['testUnitId']) self.assertTrue(test_plan, "failed to create test plan") testplan_childtable_data = self.test_plan.search_and_get_childtable_data_for_testplan( test_plan['testPlanEntity']['name']) self.info('Asserting the limits of quantification viewed correctly') self.assertIn(testunit_display_old_quantification_limit, testplan_childtable_data[0].values()) new_quantification_lower_limit, new_quantification_upper_limit = \ self.test_plan.update_upper_lower_limits_of_testunit(test_plan['id']) testunit_display_new_quantification_limit = '{}-{}'.format( new_quantification_lower_limit, new_quantification_upper_limit) self.test_plan.get_test_plans_page() testplan_childtable_data = self.test_plan.search_and_get_childtable_data_for_testplan( test_plan['testPlanEntity']['name']) self.info('Asserting the limits of quantification viewed correctly') self.assertIn(testunit_display_new_quantification_limit, testplan_childtable_data[0].values()) test_plan_data = self.test_plan.get_the_latest_row_data() self.info('Asserting that new version created') self.assertEqual(test_plan_data['Version'], '2')
class TestUnitsTestCases(BaseTest): def setUp(self): super().setUp() self.test_unit_page = TstUnit() self.test_units_page = TstUnits() self.test_plan = TstPlan() self.article_api = ArticleAPI() self.test_unit_api = TestUnitAPI() self.set_authorization(auth=self.article_api.AUTHORIZATION_RESPONSE) self.test_unit_api.set_configuration() self.test_unit_page.get_test_units_page() @attr(series=True) #@skip('waiting for API deleting') def test036_archive_quantifications_limit_field(self): """ User can archive the quantification limits field from the configuration section if not used. "Archive-allowed" LIMS-4164 """ self.test_unit_page.open_configurations() self.test_unit_page.archive_quantification_limit_field() if not self.test_unit_page.is_field_in_use(): self.assertFalse( self.base_selenium.check_element_is_exist('test_unit:configuration_testunit_useQuantification')) self.test_unit_page.get_archived_fields_tab() self.assertTrue(self.base_selenium.check_element_is_exist('test_unit:configuration_testunit_useQuantification')) self.test_unit_page.get_test_units_page() self.test_unit_page.click_create_new_testunit() self.test_unit_page.set_testunit_type(testunit_type='Quantitative') self.assertFalse(self.base_selenium.check_element_is_exist(element='test_unit:use_quantification')) @attr(series=True) def test037_restore_quantifications_limit_field(self): """ User can archive the quantification limits field from the configuration section if not used. "Restore" LIMS-4164 """ self.test_unit_page.open_configurations() self.test_unit_page.archive_quantification_limit_field() if not self.test_unit_page.is_field_in_use(): self.test_unit_page.restore_quantification_limit_field() self.assertFalse( self.base_selenium.check_element_is_exist('test_unit:configuration_testunit_useQuantification')) self.test_unit_page.get_active_fields_tab() self.assertTrue(self.base_selenium.check_element_is_exist('test_unit:configuration_testunit_useQuantification')) self.test_unit_page.get_test_units_page() self.test_unit_page.click_create_new_testunit() self.test_unit_page.set_testunit_type(testunit_type='Quantitative') self.assertTrue(self.base_selenium.check_element_is_exist(element='test_unit:use_quantification')) @attr(series=True) def test038_test_unit_name_is_mandatory(self): """ New: Test unit: Configuration: Test unit Name Approach: Make the test units field as as mandatory field (This mean you can't remove it ) LIMS- 5651 """ self.test_unit_page.open_configurations() self.test_unit_page.open_testunit_name_configurations_options() self.assertTrue(self.test_unit_page.check_all_options_of_search_view_menu()) @parameterized.expand(['Name', 'Method', 'Type', 'No']) @attr(series=True) @skip('https://modeso.atlassian.net/browse/LIMSA-382') def test039_test_unit_name_allow_user_to_search_with_selected_options_testplan(self, search_view_option): """ New: Test Unit: Configuration: Test unit Name Approach: Allow user to search with (name, number, type, method) in the drop down list of the test plan for. LIMS- 6422 """ self.test_unit_page.open_configurations() self.test_unit_page.open_testunit_name_configurations_options() old_values = self.test_unit_page.select_option_to_view_search_with(view_search_options=[search_view_option]) self.info('Create new testunit with qualitative and random generated data') response, payload = self.test_unit_api.create_qualitative_testunit() self.assertEqual(response['status'], 1, payload) self.info('new testunit created with number {}'.format(payload['number'])) self.info('get random In Progrees test plan') test_plan = random.choice(TestPlanAPI().get_inprogress_testplans()) self.assertTrue(test_plan, 'No test plan selected') self.info('Navigate to test plan edit page') self.test_plan.get_test_plan_edit_page_by_id(test_plan['id']) is_name_exist = self.test_plan.search_test_unit_not_set(test_unit=payload['name']) is_number_exist = self.test_plan.search_test_unit_not_set(test_unit=str(payload['number'])) is_type_exist = self.test_plan.search_test_unit_not_set(test_unit='Qualitative') is_method_exist = self.test_plan.search_test_unit_not_set(test_unit=payload['method']) if search_view_option == 'Name': self.assertTrue(is_name_exist) self.assertFalse(is_number_exist) self.assertFalse(is_type_exist) self.assertFalse(is_method_exist) elif search_view_option == 'Type': self.assertFalse(is_name_exist) self.assertFalse(is_number_exist) self.assertTrue(is_type_exist) self.assertFalse(is_method_exist) elif search_view_option == 'Method': self.assertFalse(is_name_exist) self.assertFalse(is_number_exist) self.assertFalse(is_type_exist) self.assertTrue(is_method_exist) elif search_view_option == 'No': self.assertFalse(is_name_exist) self.assertTrue(is_number_exist) self.assertFalse(is_type_exist) self.assertFalse(is_method_exist) @attr(series=True) @skip('https://modeso.atlassian.net/browse/LIMSA-382') def test040_test_unit_name_search_default_options_name_type_in_testplan(self): """ New: Test unit: Configuration: Test units field Approach: Allow name & type to display by default in the test plan form In case I select them from the test unit configuration LIMS-6423 """ # in set_configuration() I set search to be by name and type so I don't need to add this steps here self.info('Create new test unit with qualitative and random generated data') response, payload = self.test_unit_api.create_qualitative_testunit() self.assertEqual(response['status'], 1, payload) self.info('new test unit created with number {}'.format(payload['number'])) self.info('get random In Progress test plan') test_plan = random.choice(TestPlanAPI().get_inprogress_testplans()) self.assertTrue(test_plan, 'No test plan selected') self.info('Navigate to test plan edit page') self.test_plan.get_test_plan_edit_page_by_id(test_plan['id']) self.test_plan.sleep_small() is_name_exist = self.test_plan.search_test_unit_not_set(test_unit=payload['name']) is_number_exist = self.test_plan.search_test_unit_not_set(test_unit=str(payload['number'])) is_type_exist = self.test_plan.search_test_unit_not_set(test_unit='Qualitative') is_method_exist = self.test_plan.search_test_unit_not_set(test_unit=payload['method']) self.assertTrue(is_name_exist) self.assertFalse(is_number_exist) self.assertTrue(is_type_exist) self.assertFalse(is_method_exist) @attr(series=True) @skip('https://modeso.atlassian.net/browse/LIMSA-382') def test041_test_unit_name_view_method_option_multiple_line_in_testplan(self): """ New: Test Unit: Configuration: Test unit Name Approach: In case you select the method to display and you entered long text in it, the method should display into multiple lines (test plan) LIMS-6424 """ self.info('Generate random data for update') new_random_method = self.generate_random_string() + \ self.generate_random_string() + \ self.generate_random_string() self.test_unit_page.open_configurations() self.test_unit_page.open_testunit_name_configurations_options() self.test_unit_page.select_option_to_view_search_with(view_search_options=['Method']) self.info('Create new testunit with qualitative and random generated data') response, payload = self.test_unit_api.create_qualitative_testunit(method=new_random_method) self.assertEqual(response['status'], 1, payload) self.info('new testunit created with number {}'.format(payload['number'])) self.info('get random In Progrees test plan') test_plan = random.choice(TestPlanAPI().get_inprogress_testplans()) self.assertTrue(test_plan, 'No test plan selected') self.info('Navigate to test plan edit page') self.test_plan.get_test_plan_edit_page_by_id(test_plan['id']) self.test_plan.set_test_unit(test_unit=new_random_method) multiple_lines_properties = self.test_plan.get_testunit_in_testplan_title_multiple_line_properties() self.assertEquals(multiple_lines_properties['textOverflow'], 'clip') self.assertEquals(multiple_lines_properties['lineBreak'], 'auto') @parameterized.expand([('Name', 'Type'), ('Name', 'Method'), ('Name', 'No'), ('Type', 'Method'), ('Type', 'No'), ('Method', 'No')]) @attr(series=True) @skip('https://modeso.atlassian.net/browse/LIMSA-382') def test042_test_unit_name_allow_user_to_search_with_selected_two_options_testplan(self, search_view_option1, search_view_option2): """ New: Test Unit: Configuration: Test unit Name Approach: Allow user to search with (name, number, type, method) in the drop down list of the analysis for LIMS- 6426 """ self.test_unit_page.open_configurations() self.test_unit_page.open_testunit_name_configurations_options() self.test_unit_page.select_option_to_view_search_with( view_search_options=[search_view_option1, search_view_option2]) self.info('Create new test unit with qualitative and random generated data') response, payload = self.test_unit_api.create_qualitative_testunit() self.assertEqual(response['status'], 1, payload) self.info('new test unit created with number {}'.format(payload['number'])) self.info('get random In Progress test plan') test_plan = random.choice(TestPlanAPI().get_inprogress_testplans()) self.assertTrue(test_plan, 'No test plan selected') self.info('Navigate to test plan edit page') self.test_plan.get_test_plan_edit_page_by_id(test_plan['id']) self.test_plan.sleep_small() is_name_exist = self.test_plan.search_test_unit_not_set(test_unit=payload['name']) is_number_exist = self.test_plan.search_test_unit_not_set(test_unit=str(payload['number'])) is_type_exist = self.test_plan.search_test_unit_not_set(test_unit='Qualitative') is_method_exist = self.test_plan.search_test_unit_not_set(test_unit=payload['method']) if search_view_option1 == 'Name' and search_view_option2 == 'Type': self.assertTrue(is_name_exist) self.assertFalse(is_number_exist) self.assertTrue(is_type_exist) self.assertFalse(is_method_exist) elif search_view_option1 == 'Name' and search_view_option2 == 'Method': self.assertTrue(is_name_exist) self.assertFalse(is_number_exist) self.assertFalse(is_type_exist) self.assertTrue(is_method_exist) elif search_view_option1 == 'Name' and search_view_option2 == 'No': self.assertTrue(is_name_exist) self.assertTrue(is_number_exist) self.assertFalse(is_type_exist) self.assertFalse(is_method_exist) elif search_view_option1 == 'Type' and search_view_option2 == 'Method': self.assertFalse(is_name_exist) self.assertFalse(is_number_exist) self.assertTrue(is_type_exist) self.assertTrue(is_method_exist) elif search_view_option1 == 'Type' and search_view_option2 == 'No': self.assertFalse(is_name_exist) self.assertTrue(is_number_exist) self.assertTrue(is_type_exist) self.assertFalse(is_method_exist) elif search_view_option1 == 'Method' and search_view_option2 == 'No': self.assertFalse(is_name_exist) self.assertTrue(is_number_exist) self.assertFalse(is_type_exist) self.assertTrue(is_method_exist) @attr(series=True) def test049_filter_by_testunit_changed_by(self): """ New: Test units: Filter Approach: Make sure you can filter by changed by LIMS-6428 """ self.login_page = Login() self.info('Calling the users api to create a new user with username') response, payload = UsersAPI().create_new_user() self.assertEqual(response['status'], 1, payload) self.login_page.logout() self.login_page.login(username=payload['username'], password=payload['password']) self.base_selenium.wait_until_page_url_has(text='dashboard') self.test_units_page.get_test_units_page() new_name = self.generate_random_string() method = self.generate_random_string() test_unit_no = self.test_unit_page.create_qualitative_testunit(name=new_name, method=method) self.test_unit_page.save_and_wait() self.assertTrue(test_unit_no, 'Test unit not created') self.info('New unit is created successfully with number: {}'.format(test_unit_no)) self.test_units_page.sleep_tiny() test_unit_found = self.test_units_page.filter_by_user_get_result(payload['username']) self.assertTrue(test_unit_found) @parameterized.expand([('Name', 'Type'), ('Name', 'Method'), ('Name', 'No'), ('Type', 'Method'), ('Type', 'No'), ('No', 'Method'), ('Unit', 'No'), ('Quantification Limit', '') ]) @attr(series=True) def test051_test_unit_name_allow_user_to_search_with_selected_two_options_order(self, first_search_option, second_search_option): """ Test Unit: Configuration: Test units Name Approach: When the user select any two options from the test unit configuration, this action should reflect on the order form LIMS-6672 Orders: Default filter test unit Approach: Allow the search criteria in the drop down list in the filter section to be same as in the form LIMS-7414 """ options_exist = {} order_page = Order() self.test_unit_page.open_configurations() self.test_unit_page.open_testunit_name_configurations_options() self.test_unit_page.select_option_to_view_search_with( view_search_options=[first_search_option, second_search_option]) self.info('create new quantitative test unit with unit and quantification') response, payload = self.test_unit_api.create_quantitative_testunit( useSpec=False, useQuantification=True, unit='m[g]{o}', quantificationUpperLimit=self.generate_random_number(lower=50, upper=100), quantificationLowerLimit=self.generate_random_number(lower=1, upper=49)) self.assertEqual(response['status'], 1, payload) quantification_limit = '{}-{}'.format(payload['quantificationLowerLimit'], payload['quantificationUpperLimit']) self.info('new test unit created with number {}'.format(payload['number'])) self.info('get random order') radndom_order = random.choice(OrdersAPI().get_all_orders_json()) self.assertTrue(radndom_order, 'No order selected') self.info('navigate to order edit page') order_page.get_order_edit_page_by_id(radndom_order['orderId']) order_page.sleep_small() if first_search_option == "Type": if second_search_option == "Method": checked_text = f'Quantitative: {payload["method"]}' elif second_search_option == "No": checked_text = f'Quantitative: {payload["number"]}' else: checked_text = f'{payload["name"]}: Quantitative' self.info("is test unit options existing?") options_exist['is_name_exist'] = order_page.is_test_unit_option_exist(search_field=payload['name']) options_exist['is_no_exist'] = order_page.is_test_unit_option_exist(search_field=str(payload['number'])) options_exist['is_type_exist'] = order_page.is_test_unit_option_exist(search_field='Quantitative', checked_text=checked_text) options_exist['is_method_exist'] = order_page.is_test_unit_option_exist(search_field=payload['method']) options_exist['is_unit_exist'] = order_page.is_test_unit_option_exist(search_field=payload['unit']) options_exist['is_quantification_limit_exist'] = order_page.is_test_unit_option_exist( search_field=quantification_limit) for key, value in options_exist.items(): if (first_search_option.lower().replace(' ', '_') in key) or (len(second_search_option.lower()) > 0 and second_search_option.lower() in key): self.assertTrue(value, f'{key} value should be True') else: self.assertFalse(value, f'{key} value should be False')