From 944d35e24c1774eb46268280010450f50178ad9b Mon Sep 17 00:00:00 2001 From: Pawel Szkamruk Date: Tue, 3 Oct 2023 13:21:55 +0200 Subject: [PATCH] error handling + more complex scenarios --- ui_tests/config/config.py | 1 + ui_tests/pages/groups_page.py | 14 +- ui_tests/pages/profiles_page.py | 8 +- ...st_error_handling_and_complex_scenarios.py | 502 ++++++++++++++++++ .../tests/test_save_update_configuration.py | 2 +- 5 files changed, 522 insertions(+), 5 deletions(-) create mode 100644 ui_tests/tests/test_error_handling_and_complex_scenarios.py diff --git a/ui_tests/config/config.py b/ui_tests/config/config.py index b0201e634..91353be56 100644 --- a/ui_tests/config/config.py +++ b/ui_tests/config/config.py @@ -27,3 +27,4 @@ def get_execution_type(): # yaml file YAML_FILE_PATH = './new_values.yaml' # YAML_FILE_PATH = './new_values_empty.yaml' +DEFAULT_PORT = 161 diff --git a/ui_tests/pages/groups_page.py b/ui_tests/pages/groups_page.py index 7d1c77b7e..922b45048 100644 --- a/ui_tests/pages/groups_page.py +++ b/ui_tests/pages/groups_page.py @@ -62,12 +62,16 @@ def check_if_groups_is_on_list(self, group_name): def delete_group_from_list(self, group_name): logger.info(f"Removing group from groups list: {group_name}") + self.click_delete_group_button(group_name) + self.confirm_delete() + self.close_delete_popup() + + def click_delete_group_button(self, group_name): + logger.info(f"Clicking delete group button for: {group_name}") delete_btn_for_group_with_name_xpath = f"//div[@data-test='sc4snmp:group' and child::*[text()='{group_name}']]//button[@data-test='sc4snmp:group:delete-group-button']" delete_btn = driver.find_element(By.XPATH, delete_btn_for_group_with_name_xpath) delete_btn.click() time.sleep(1) - self.confirm_delete() - self.close_delete_popup() def close_delete_popup(self): logger.info(f"Closing profile delete popup") @@ -236,3 +240,9 @@ def get_device_security_engine(self, device_ip): community_xpath = f"//td[@data-test='sc4snmp:host-security-engine' and ancestor::tr//td[text()='{device_ip}']]" community = driver.find_element(By.XPATH, community_xpath) return community.text + + def get_warning_message_when_removing_group_which_is_configured_in_inventory(self): + logger.info(f"getting error message while removing group which is configured in inventory") + warning_msg_xpath = f"//div[@data-test-type='warning' and @data-test='message']//div" + warning_msg = driver.find_element(By.XPATH, warning_msg_xpath) + return warning_msg.text diff --git a/ui_tests/pages/profiles_page.py b/ui_tests/pages/profiles_page.py index cf5e41fd0..fe2d29c2e 100644 --- a/ui_tests/pages/profiles_page.py +++ b/ui_tests/pages/profiles_page.py @@ -112,12 +112,16 @@ def check_if_profile_is_configured(self, profile_name): def delete_profile_from_list(self, profile_name): logger.info(f"Removing profile from profiles list: {profile_name}") + self.click_delete_profile_button(profile_name) + self._confirm_delete_profile() + self.close_profile_delete_popup() + + def click_delete_profile_button(self, profile_name): + logger.info(f"click delete profile button -> {profile_name}") delete_btn_for_profile_with_name_xpath = f"//button[@data-test='sc4snmp:profile-row-delete' and ancestor::tr//td[text()='{profile_name}']]" delete_btn = driver.find_element(By.XPATH, delete_btn_for_profile_with_name_xpath) delete_btn.click() time.sleep(1) - self._confirm_delete_profile() - self.close_profile_delete_popup() def _confirm_delete_profile(self): confirm_delete_xpath = "//button[@data-test='sc4snmp:delete-modal:delete-button']" diff --git a/ui_tests/tests/test_error_handling_and_complex_scenarios.py b/ui_tests/tests/test_error_handling_and_complex_scenarios.py new file mode 100644 index 000000000..28dac0952 --- /dev/null +++ b/ui_tests/tests/test_error_handling_and_complex_scenarios.py @@ -0,0 +1,502 @@ +import time + +import pytest + +from config import config +from logger.logger import Logger +from pages.groups_page import GroupsPage +from pages.header_page import HeaderPage +from pages.inventory_page import InventoryPage +from pages.profiles_page import ProfilesPage +from pages.yaml_values_reader import YamlValuesReader +from webdriver.webriver_factory import WebDriverFactory + +logger = Logger().get_logger() +driver = WebDriverFactory().get_driver() +p_header = HeaderPage() +p_profiles = ProfilesPage() +p_groups = GroupsPage() +p_inventory = InventoryPage() +values_reader = YamlValuesReader() + + +@pytest.mark.current +def test_trying_to_configure_profle_with_the_same_name(): + """ + Configure profile + try to configure profile with the same name again + check error message + """ + profile_name = "same_profile" + profile_freq = 10 + + p_header.switch_to_profiles() + p_profiles.click_add_profile_button() + p_profiles.set_profile_name(profile_name) + p_profiles.set_frequency(profile_freq) + p_profiles.add_varBind("IP-MIB", "ifDescr", 1) + p_profiles.click_submit_button() + exist = p_profiles.check_if_profile_is_configured(profile_name) + assert exist is True + + p_profiles.click_add_profile_button() + p_profiles.set_profile_name(profile_name) + p_profiles.set_frequency(profile_freq) + p_profiles.add_varBind("IP-MIB", "ifDescr", 1) + p_profiles.click_submit_button() + + message = p_header.get_popup_error_message() + assert message == f"Profile with name {profile_name} already exists. Profile was not added." + p_header.close_error_popup() + exist = p_profiles.check_if_profile_is_configured(profile_name) + assert exist is True + + p_profiles.delete_profile_from_list(profile_name) + + +@pytest.mark.current +def test_trying_to_configure_group_with_the_same_name(): + """ + Configure group + try to configure group with the same name again + check error message + """ + group_name = "same_group" + + p_header.switch_to_groups() + p_groups.click_add_new_group_button() + p_groups.set_group_name(group_name) + p_groups.click_submit_button_for_add_group() + is_on_list = p_groups.check_if_groups_is_on_list(group_name) + assert is_on_list is True + + # try to add same group again + p_groups.click_add_new_group_button() + p_groups.set_group_name(group_name) + p_groups.click_submit_button_for_add_group() + # check error message + message = p_header.get_popup_error_message() + assert message == f"Group with name {group_name} already exists. Group was not added." + p_header.close_error_popup() + + is_on_list = p_groups.check_if_groups_is_on_list(group_name) + assert is_on_list is True + + p_groups.delete_group_from_list(group_name) + + +@pytest.mark.current +def test_trying_to_add_group_device_which_already_exists(): + """ + Configure group with device + try to add the same device to the group + check error message + """ + group_name = "same_group_device" + device_ip = "10.20.20.10" + port = 324 + snmp_version = "2c" + community_string = "test-device" + + p_header.switch_to_groups() + p_groups.click_add_new_group_button() + p_groups.set_group_name(group_name) + p_groups.click_submit_button_for_add_group() + # add device to grp + p_groups.click_add_device_to_group(group_name) + p_groups.set_device_ip(device_ip) + p_groups.set_device_port(port) + p_groups.set_snmp_version(snmp_version) + p_groups.set_community_string(community_string) + p_groups.click_submit_button_for_add_device() + is_on_list = p_groups.check_if_groups_is_on_list(group_name) + assert is_on_list is True + + # try to add same device again + p_groups.click_add_device_to_group(group_name) + p_groups.set_device_ip(device_ip) + p_groups.set_device_port(port) + p_groups.click_submit_button_for_add_device() + is_configured = p_groups.check_if_device_is_configured(device_ip) + assert is_configured is True + + # check error message + message = p_header.get_popup_error_message() + assert message == f"Host {device_ip}:{port} already exists in group {group_name}. Record was not added." + p_header.close_error_popup() + + is_configured = p_groups.check_if_device_is_configured(device_ip) + assert is_configured is True + + p_groups.delete_group_from_list(group_name) + + +@pytest.mark.current +def test_trying_to_add_inventory_with_host_which_already_exists(): + """ + Configure inventory with host + try to add the same host as another inventory entry + check error message + """ + host_ip = "100.200.100.200" + community_string = "test-device" + + p_header.switch_to_inventory() + p_inventory.click_add_new_device_group_button() + p_inventory.set_host_or_group_name(host_ip) + p_inventory.set_community_string(community_string) + p_inventory.click_submit_button_for_add_entry() + is_on_list = p_inventory.check_if_entry_is_on_list(host_ip) + assert is_on_list is True + + # try to add same device again + p_inventory.click_add_new_device_group_button() + p_inventory.set_host_or_group_name(host_ip) + p_inventory.set_community_string("different_string") + p_inventory.click_submit_button_for_add_entry() + + # check error message + message = p_header.get_popup_error_message() + assert message == f"Host {host_ip}:{config.DEFAULT_PORT} already exists in the inventory. Record was not added." + p_header.close_error_popup() + is_on_list = p_inventory.check_if_entry_is_on_list(host_ip) + assert is_on_list is True + + p_inventory.delete_entry_from_list(host_ip) + + +@pytest.mark.current +def test_trying_to_add_inventory_with_group_which_is_already_added(): + """ + Configure inventory with group + try to add the same group as another inventory entry + check error message + """ + # add group + group_name = f"test-group-inventory" + p_header.switch_to_groups() + p_groups.click_add_new_group_button() + p_groups.set_group_name(group_name) + p_groups.click_submit_button_for_add_group() + + community_string = "public" + p_header.switch_to_inventory() + p_inventory.click_add_new_device_group_button() + p_inventory.select_group_inventory_type() + p_inventory.set_host_or_group_name(group_name) + p_inventory.set_community_string(community_string) + p_inventory.click_submit_button_for_add_entry() + is_on_list = p_inventory.check_if_entry_is_on_list(group_name) + assert is_on_list is True + + # try to add same device again + p_inventory.click_add_new_device_group_button() + p_inventory.select_group_inventory_type() + p_inventory.set_host_or_group_name(group_name) + p_inventory.set_community_string("public_test_same_group") + p_inventory.click_submit_button_for_add_entry() + + # check error message + message = p_header.get_popup_error_message() + assert message == f"Group {group_name} has already been added to the inventory. Record was not added." + p_header.close_error_popup() + is_on_list = p_inventory.check_if_entry_is_on_list(group_name) + assert is_on_list is True + + # delete + p_inventory.delete_entry_from_list(group_name) + p_header.switch_to_groups() + p_groups.delete_group_from_list(group_name) + + +@pytest.mark.current +def test_trying_to_add_inventory_group_with_host_which_is_configured_as_host(): + """ + Configure inventory with group with host + try to add the inventory entry with the same host which is configured in group + check error message + """ + # add group + group_name = f"test-group-inventory" + device_ip = "40.50.60.70" + community_string = "public" + + p_header.switch_to_groups() + p_groups.click_add_new_group_button() + p_groups.set_group_name(group_name) + p_groups.click_submit_button_for_add_group() + + p_groups.click_add_device_to_group(group_name) + p_groups.set_device_ip(device_ip) + p_groups.click_submit_button_for_add_device() + is_on_list = p_groups.check_if_groups_is_on_list(group_name) + assert is_on_list is True + + p_header.switch_to_inventory() + p_inventory.click_add_new_device_group_button() + p_inventory.select_group_inventory_type() + p_inventory.set_host_or_group_name(group_name) + p_inventory.set_community_string(community_string) + p_inventory.click_submit_button_for_add_entry() + is_on_list = p_inventory.check_if_entry_is_on_list(group_name) + assert is_on_list is True + + # try to add the same host as inventory entry again + p_inventory.click_add_new_device_group_button() + p_inventory.set_host_or_group_name(device_ip) + p_inventory.set_community_string("public_test_same_host") + p_inventory.click_submit_button_for_add_entry() + + # check error message + message = p_header.get_popup_error_message() + assert message == f"Host {device_ip}:{config.DEFAULT_PORT} already exists in group {group_name}. Record was not added." + p_header.close_error_popup() + is_on_list = p_inventory.check_if_entry_is_on_list(group_name) + assert is_on_list is True + + # delete + p_inventory.delete_entry_from_list(group_name) + p_header.switch_to_groups() + p_groups.delete_group_from_list(group_name) + + +@pytest.mark.current +def test_removing_group_which_is_configured_in_inventory(): + """ + Configure inventory -> add group as inventory entry + remove group which was added into inventory + check that upon removing group inventory entry is also removed + """ + # add group + group_name = f"test-group-inventory" + community_string = "public" + + p_header.switch_to_groups() + p_groups.click_add_new_group_button() + p_groups.set_group_name(group_name) + p_groups.click_submit_button_for_add_group() + + p_header.switch_to_inventory() + p_inventory.click_add_new_device_group_button() + p_inventory.select_group_inventory_type() + p_inventory.set_host_or_group_name(group_name) + p_inventory.set_community_string(community_string) + p_inventory.click_submit_button_for_add_entry() + is_on_list = p_inventory.check_if_entry_is_on_list(group_name) + assert is_on_list is True + + # delete group + p_header.switch_to_groups() + # p_groups.delete_group_from_list(group_name) + p_groups.click_delete_group_button(group_name) + message = p_groups.get_warning_message_when_removing_group_which_is_configured_in_inventory() + assert message == "WARNING: This group is configured in the inventory" + p_groups.confirm_delete() + p_groups.close_delete_popup() + + # check inventory is also removed + is_on_list = p_groups.check_if_groups_is_on_list(group_name) + assert is_on_list is False + p_header.switch_to_inventory() + is_on_list = p_inventory.check_if_entry_is_on_list(group_name) + assert is_on_list is False + + +@pytest.mark.current +def test_removing_profile_which_is_configured_in_inventory(): + """ + Configure inventory with profile + remove profile which was added into inventory + check that upon removing profile, this profile in inventory entry is also removed + """ + # add group + profile_name = "removing_profile" + host = "99.99.99.99" + community_string = "public" + + p_header.switch_to_profiles() + p_profiles.click_add_profile_button() + p_profiles.set_profile_name(profile_name) + p_profiles.add_varBind("IP-MIB", "ifDescr", 1) + p_profiles.click_submit_button() + exist = p_profiles.check_if_profile_is_configured(profile_name) + assert exist is True + + p_header.switch_to_inventory() + p_inventory.click_add_new_device_group_button() + p_inventory.set_host_or_group_name(host) + p_inventory.select_profiles([profile_name]) + p_inventory.set_community_string(community_string) + p_inventory.click_submit_button_for_add_entry() + is_on_list = p_inventory.check_if_entry_is_on_list(host) + assert is_on_list is True + + # delete profile + p_header.switch_to_profiles() + p_profiles.click_delete_profile_button(profile_name) + + message = p_groups.get_warning_message_when_removing_group_which_is_configured_in_inventory() + assert message == "WARNING: This profile is configured in some records in the inventory" + p_profiles._confirm_delete_profile() + p_profiles.close_profile_delete_popup() + exist = p_profiles.check_if_profile_is_configured(profile_name) + assert exist is False + + # check inventory - no profile + p_header.switch_to_inventory() + is_on_list = p_inventory.check_if_entry_is_on_list(host) + assert is_on_list is True + received_profiles = p_inventory.get_profiles_for_entry(host) + assert "" == received_profiles + # delete inventory entry + p_inventory.delete_entry_from_list(host) + + +@pytest.mark.current +def test_try_to_add_to_inventory_group_which_does_not_exist(): + """ + Configure inventory with group which does not exist + check error message + """ + + group_name = "does_not_exist" + community_string = "abcd" + p_header.switch_to_inventory() + + p_inventory.click_add_new_device_group_button() + p_inventory.select_group_inventory_type() + p_inventory.set_host_or_group_name(group_name) + p_inventory.set_community_string(community_string) + p_inventory.click_submit_button_for_add_entry() + + # check error message + message = p_header.get_popup_error_message() + assert message == f"Group {group_name} doesn't exist in the configuration. Record was not added." + p_header.close_error_popup() + is_on_list = p_inventory.check_if_entry_is_on_list(group_name) + assert is_on_list is False + + +@pytest.mark.current +def test_trying_to_edit_profile_name_into_profile_name_that_exists(): + """ + Configure two profiles + try to change one profile to the second + check error message + """ + profile_name_1 = "profile_1" + profile_name_2 = "profile_2" + + p_header.switch_to_profiles() + p_profiles.click_add_profile_button() + p_profiles.set_profile_name(profile_name_1) + p_profiles.add_varBind("IP-MIB", "ifDescr", 1) + p_profiles.click_submit_button() + + p_profiles.click_add_profile_button() + p_profiles.set_profile_name(profile_name_2) + p_profiles.add_varBind("IP-MIB") + p_profiles.click_submit_button() + + # edit profile name + p_profiles.click_edit_profile(profile_name_1) + p_profiles.set_profile_name(profile_name_2) + p_profiles.click_submit_button() + + message = p_header.get_popup_error_message() + assert message == f"Profile with name {profile_name_2} already exists. Profile was not edited." + p_header.close_error_popup() + exist = p_profiles.check_if_profile_is_configured(profile_name_1) + assert exist is True + exist = p_profiles.check_if_profile_is_configured(profile_name_2) + assert exist is True + + p_profiles.delete_profile_from_list(profile_name_1) + p_profiles.delete_profile_from_list(profile_name_2) + + +@pytest.mark.current +def test_trying_to_edit_group_name_into_another_group_name(): + """ + Configure two groups + try to change one group to the second + check error message + """ + group_name_1 = "group_1" + group_name_2 = "group_2" + + p_header.switch_to_groups() + p_groups.click_add_new_group_button() + p_groups.set_group_name(group_name_1) + p_groups.click_submit_button_for_add_group() + + p_groups.click_add_new_group_button() + p_groups.set_group_name(group_name_2) + p_groups.click_submit_button_for_add_group() + + # edit group name + p_groups.edit_group_name(group_name_1, group_name_2) + + message = p_header.get_popup_error_message() + assert message == f"Group with name {group_name_2} already exists. Group was not edited." + p_header.close_error_popup() + is_on_list = p_groups.check_if_groups_is_on_list(group_name_1) + assert is_on_list is True + is_on_list = p_groups.check_if_groups_is_on_list(group_name_2) + assert is_on_list is True + + p_groups.delete_group_from_list(group_name_1) + p_groups.delete_group_from_list(group_name_2) + + +@pytest.mark.current +def test_trying_to_edit_inventory_host_into_host_which_exists(): + """ + Configure two inventory hosts + try to change one host to the second + check error message + """ + host_1 = "11.11.11.11" + community_1 = "com1" + host_2 = "22.22.22.22" + community_2 = "abcs" + + p_header.switch_to_inventory() + p_inventory.click_add_new_device_group_button() + p_inventory.set_host_or_group_name(host_1) + p_inventory.set_community_string(community_1) + p_inventory.click_submit_button_for_add_entry() + + p_inventory.click_add_new_device_group_button() + p_inventory.set_host_or_group_name(host_2) + p_inventory.set_community_string(community_2) + p_inventory.click_submit_button_for_add_entry() + + # edit inventory host + p_inventory.clik_edit_inventory_entry(host_1) + p_inventory.set_host_or_group_name(host_2, True) + p_inventory.click_submit_button_for_add_entry() + + message = p_header.get_popup_error_message() + assert message == f"Host {host_2}:{config.DEFAULT_PORT} already exists in the inventory. Record was not edited." + p_header.close_error_popup() + is_on_list = p_inventory.check_if_entry_is_on_list(host_1) + assert is_on_list is True + is_on_list = p_inventory.check_if_entry_is_on_list(host_2) + assert is_on_list is True + + p_inventory.delete_entry_from_list(host_1) + p_inventory.delete_entry_from_list(host_2) +# host +# group +# inventory entry +# adding ip in group and then adding it one more time as host + +# change name to the name which exists profile, group, inventory + +# removing group when configured in inventory +# removing profile when configured in inventory + +# try to add group which does not exist +# try to add profile which does not exist - will not work - need to select from list +# change name to the name that already exist diff --git a/ui_tests/tests/test_save_update_configuration.py b/ui_tests/tests/test_save_update_configuration.py index 256a49d48..920f1e195 100644 --- a/ui_tests/tests/test_save_update_configuration.py +++ b/ui_tests/tests/test_save_update_configuration.py @@ -164,7 +164,7 @@ def test_check_that_group_config_is_stored_upon_applying_configuration(): assert "{}\n" == groups # groups should be empty -@pytest.mark.current +# @pytest.mark.current def test_check_that_inventory_config_is_stored_upon_applying_configuration(): """ add inventory entry