class TestDeleteComment(unittest.TestCase): def setUp(self): self.app = Aplication() def tearDown(self): self.app.driver.close() def test_delete_comment(self): # select item comment_for_delete = \ self.app.driver.find_element_by_css_selector("tbody > " "tr:nth-child(1)") text = comment_for_delete.find_element_by_class_name("textcolumn").text number = \ comment_for_delete.find_element_by_class_name("numbercolumn").text categories = \ comment_for_delete.find_element_by_class_name("categorycolumn").text delete_comment = Comment(number, text, categories) self.app.driver.find_element_by_name("SelectedId").click() self.app.delete_button() # check is comment delete list_comments = self.app.all_comments() self.assertNotIn(delete_comment, list_comments) def test_not_selected_delete_comment(self): self.app.driver.find_element_by_xpath("//input[@value = " "'Delete']").click() alert = self.app.driver.switch_to.alert warning = alert.text alert.accept() self.assertEqual(warning, expected_variables["select_one_category"]) def test_two_items_selected(self): # select items self.app.select_first_comment() self.app.select_second_comment() self.app.delete_button() # check is comments delete actual_text = \ self.app.driver.find_element_by_xpath("// *[ @ id = " "'infoField']").text self.assertEqual(actual_text, expected_variables["deleted_successfull"])
def setUp(self): self.app = Aplication()
def setUpClass(cls): TestMainPage.app = Aplication()
class TestDuplicateComment(unittest.TestCase): def setUp(self): self.app = Aplication() def tearDown(self): self.app.driver.close() def test_duplicate_comment(self): self.app.select_first_comment() self.app.duplicate_button() # data duplicate comment duplicate_number = self.app.driver.find_element_by_id("Number") duplicate_number.clear() duplicate_number.send_keys(*data_duplicate_comment[0]) duplicate_text = self.app.driver.find_element_by_id("Text") duplicate_text.clear() duplicate_text.send_keys(*data_duplicate_comment[1]) duplicate_selected_categories = \ self.app.driver.find_element_by_id("selectedCategories").text duplicate_comment = Comment(*data_duplicate_comment[0], *data_duplicate_comment[1], duplicate_selected_categories) self.app.save_return() # check an element list_comments = self.app.all_comments() self.assertIn(duplicate_comment, list_comments) def test_duplicate_comment_without_changes(self): self.app.select_second_comment() self.app.duplicate_button() self.app.save_button() warning = self.app.driver.find_element_by_id("errorfield").text self.assertEqual(warning, expected_variables["unique_number_field"]) def test_not_selected_duplicate_comment(self): self.app.duplicate_button() alert = self.app.driver.switch_to.alert warning = alert.text alert.accept() self.assertEqual(warning, expected_variables["select_one_category"]) def test_two_items_selected(self): # select items for duplicate self.app.select_first_comment() self.app.select_second_comment() self.app.duplicate_button() alert = self.app.driver.switch_to.alert warning = alert.text alert.accept() self.assertEqual(warning, expected_variables["select_one_category"])
class TestNewComment(unittest.TestCase): def setUp(self): self.app = Aplication() def tearDown(self): self.app.driver.close() def test_empty_field_comment(self): self.app.new_button() comment_text_field = self.app.driver.find_element_by_id("Text").text self.assertEqual(comment_text_field, "") def test_empty_field_number(self): self.app.new_button() comment_number_field = \ self.app.driver.find_element_by_id("Number").text self.assertEqual(comment_number_field, "") def test_empty_field_categories(self): self.app.new_button() comment_selected_categories = \ self.app.driver.find_element_by_id("selectedCategories").text self.assertEqual(comment_selected_categories, "") def test_new_comment(self): # check for entering a new comment with a choice of all categories self.app.new_button() self.app.adding_data(Arguments(*new_comment_data[0])) self.app.button_all_categories() self.app.save_return() # check an element list_comments = self.app.all_comments() self.assertIn(expected_variables["first_comment"], list_comments) def test_new_comment_two_categories(self): # check for entering a new comment with two categories self.app.new_button() self.app.adding_data(Arguments(*new_comment_data[1])) self.app.select_two_categories() self.app.save_return() # check an element list_comments = self.app.all_comments() self.assertIn(expected_variables["second_comment"], list_comments) def test_new_comment_without_categories(self): # check for entering a new comment with no categories self.app.new_button() self.app.adding_data(Arguments(*new_comment_data[2])) self.app.save_button() warning = self.app.driver.find_element_by_id("errorfield").text self.assertEqual(warning, expected_variables["at_list_one_category"]) def test_new_comment_text_comment(self): # check for entering a new comment with no text comment self.app.new_button() self.app.adding_data(Arguments(*new_comment_data[3])) self.app.save_button() warning = self.app.driver.find_element_by_id("errorfield").text self.assertEqual(warning, expected_variables["text_field_is_required"]) def test_refresh_button(self): # check for entering a new comment with refresh button self.app.new_button() self.app.adding_data(Arguments(*new_comment_data[0])) self.app.refresh_button() comment_text_field = self.app.driver.find_element_by_id("Text").text comment_number_field = self.app.driver.find_element_by_id( "Number").text comment_selected_categories = \ self.app.driver.find_element_by_id("selectedCategories").text empty_fields = [ comment_text_field, comment_number_field, comment_selected_categories ] self.assertListEqual(empty_fields, expected_variables["empty_list"]) def test_invalid_text_comment(self): # check for entering a new comment with invalid text comment self.app.new_button() self.app.adding_data(Arguments(*new_comment_data[4])) block_warning = \ self.app.driver.find_element_by_class_name("field-" "validation-error") warning = block_warning.find_element_by_tag_name("span").text self.assertEqual(warning, expected_variables["max_text_field"]) def test_negative_number_comment(self): # check for entering a new comment with negative number comment self.app.new_button() self.app.adding_data(Arguments(*new_comment_data[5])) self.app.select_two_categories() self.app.save_button() warning = self.app.driver.find_element_by_id("errorfield").text self.assertEqual(warning, expected_variables["contains_only_digits"]) def test_max_number_comment(self): # check for entering a new comment with max value number comment self.app.new_button() self.app.adding_data(Arguments(*new_comment_data[6])) self.app.select_two_categories() self.app.save_button() warning = self.app.driver.find_element_by_id("errorfield").text self.assertEqual(warning, expected_variables["unique_number_field"])
class TestEditComment(unittest.TestCase): def setUp(self): self.app = Aplication() def tearDown(self): self.app.driver.close() def test_edit_comment(self): self.app.select_first_comment() self.app.edit_button() # data edit comment edit_text = self.app.driver.find_element_by_id("Text") edit_text.clear() edit_text.send_keys(new_data[0][0]) edit_number = self.app.driver.find_element_by_id("Number") edit_number.clear() edit_number.send_keys(new_data[0][1]) edit_selected_categories = \ self.app.driver.find_element_by_id("selectedCategories").text edit_comment = Comment(new_data[0][1], new_data[0][0], edit_selected_categories) self.app.save_return() # check is comment edit list_comments = self.app.all_comments() self.assertIn(edit_comment, list_comments) def test_is_old_comment_change(self): # select item comment_for_edit = \ self.app.driver.find_element_by_css_selector("tbody > " "tr:nth-child(1)") text = \ comment_for_edit.find_element_by_class_name("textcolumn").text number = \ comment_for_edit.find_element_by_class_name("numbercolumn").text categories = \ comment_for_edit.find_element_by_class_name("categorycolumn").text old_comment = Comment(number, text, categories) self.app.driver.find_element_by_name("SelectedId").click() self.app.edit_button() # data edit comment edit_text = self.app.driver.find_element_by_id("Text") edit_text.clear() edit_text.send_keys(new_data[1][0]) edit_number = self.app.driver.find_element_by_id("Number") edit_number.clear() edit_number.send_keys(new_data[1][1]) self.app.save_return() # check is no old comment list_comments = self.app.all_comments() self.assertNotIn(old_comment, list_comments) def test_not_selected_edit_comment(self): self.app.edit_button() alert = self.app.driver.switch_to.alert warning = alert.text alert.accept() self.assertEqual(warning, expected_variables["select_one_category"]) def test_two_items_selected(self): # select items for edit self.app.select_first_comment() self.app.select_second_comment() self.app.edit_button() alert = self.app.driver.switch_to.alert warning = alert.text alert.accept() self.assertEqual(warning, expected_variables["select_one_category"])