Skip to content

Commit

Permalink
changes after review part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
pszkamruk-splunk committed Nov 27, 2023
1 parent 2882313 commit 1658a91
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 73 deletions.
16 changes: 8 additions & 8 deletions ui_tests/pages/groups_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def check_if_groups_is_on_list(self, group_name):
group_entry_on_list_xpath = "//div[@data-test='sc4snmp:group']//p"
groups_entries = driver.find_elements(By.XPATH, group_entry_on_list_xpath)
for el in groups_entries:
logger.info(f"group name > |{el.text}|") # debug
# logger.info(f"group name > |{el.text}|") # debug
if group_name == el.text:
return True
logger.info("Group has not been found on list")
Expand Down Expand Up @@ -136,7 +136,7 @@ def edit_group_name(self, group_name, new_group_name):
add_grp_input.send_keys(new_group_name)
self.click_submit_button_for_add_group()

def get_submit_editeg_group_name_popup_message(self):
def get_submit_edited_group_name_popup_message(self):
logger.info(f"Get submit edited group name popup text")
edited_group_popup_text_xpath = f"//div[@data-test='modal']//div//p"
edited_group_popup_text = driver.find_element(
Expand Down Expand Up @@ -253,15 +253,15 @@ def get_device_community_string(self, device_ip):
community = driver.find_element(By.XPATH, community_xpath)
return community.text

def get_device_secret(self, device_ip):
logger.info(f"get device secret: {device_ip}")
community_xpath = f"//td[@data-test='sc4snmp:host-secret' and ancestor::tr//td[text()='{device_ip}']]"
def get_device_secret(self, device_secret):
logger.info(f"get device secret: {device_secret}")
community_xpath = f"//td[@data-test='sc4snmp:host-secret' and ancestor::tr//td[text()='{device_secret}']]"
community = driver.find_element(By.XPATH, community_xpath)
return community.text

def get_device_security_engine(self, device_ip):
logger.info(f"get device security engine {device_ip}")
community_xpath = f"//td[@data-test='sc4snmp:host-security-engine' and ancestor::tr//td[text()='{device_ip}']]"
def get_device_security_engine(self, device_security_engine):
logger.info(f"get device security engine {device_security_engine}")
community_xpath = f"//td[@data-test='sc4snmp:host-security-engine' and ancestor::tr//td[text()='{device_security_engine}']]"
community = driver.find_element(By.XPATH, community_xpath)
return community.text

Expand Down
6 changes: 3 additions & 3 deletions ui_tests/pages/inventory_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@


class InventoryPage:
def checkIfInventoryTableIsDisplayed(self):
logger.info("Check if groups page is displayed")
def check_if_inventory_table_is_displayed(self):
logger.info("Check if inventory page is displayed")
inventory_table_xpath = "//div[@data-test='sc4snmp:inventory-table']"
inventory_container = driver.find_element(By.XPATH, inventory_table_xpath)
return inventory_container.is_displayed()
Expand All @@ -24,7 +24,7 @@ def check_if_entry_is_on_list(self, host_ip):
entries = driver.find_elements(By.XPATH, entries_on_list_xpath)
logger.info(f"list length: {len(entries)}")
for el in entries:
logger.info(f"entry name > |{el.text}|") # debug
# logger.info(f"entry name > |{el.text}|") # debug
if host_ip == el.text:
return True
logger.info("Entry has not been found on list")
Expand Down
6 changes: 3 additions & 3 deletions ui_tests/pages/profiles_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


class ProfilesPage:
def checkIfProfilesTableIsDisplayed(self):
logger.info("Check if groups page is displayed")
def check_if_profiles_table_is_displayed(self):
logger.info("Check if profiles page is displayed")
profiles_table_xpath = "//div[@data-test='sc4snmp:profiles-table']"
profiles_container = driver.find_element(By.XPATH, profiles_table_xpath)
return profiles_container.is_displayed()
Expand Down Expand Up @@ -195,7 +195,7 @@ def check_if_frequency_setting_field_is_visible(self):
return False

def add_condition(self, field_value, operation, value):
logger.info(f"Checking if frequency setting field is visible")
logger.info(f"Adding condition: {field_value}, {operation}, {value}")
add_condition_button_xpath = (
"//div[@data-test='sc4snmp:form:add-conditional-profile']//button"
)
Expand Down
57 changes: 2 additions & 55 deletions ui_tests/splunk_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,59 +55,6 @@ def check_events_from_splunk(
return events


def check_metrics_from_splunk(
index="metrics",
start_time="-1h@h",
end_time="now",
url="",
user="",
password="",
metric_name="",
):
"""
send a search api request to splunk to check for values associated with a given metric and dimension
"""
logger.debug("Calling _collect_metrics ")
events = _collect_metrics(
start_time, end_time, url, user, password, index, metric_name
)

return events


def create_index_in_splunk(index="", url="", user="", password=""):
"""
Send a request to a Splunk instance to create an index
@param: index (index to be deleted)
@param: url (splunkd rest api url)
@param: user (splunk username)
@param: password (splunk password)
returns True/False
"""

search_url = "{}/services/data/indexes/{}?output_mode=json".format(url, index)
logger.debug("requesting: %s", search_url)
data = {"name": index}

create_job = _requests_retry_session().post(
search_url, auth=(user, password), verify=False, data=data
)

if create_job.status_code == 201:
logger.info("The index: %s successfully created", index)
elif create_job.status_code == 409:
logger.info("The index: %s already exits", index)
else:
logger.info(
"The index: {} not created, exit code is {}".format(
index, create_job.status_code
)
)
return False

return True


def _collect_events(query, start_time, end_time, url="", user="", password=""):
"""
Collect events by running the given search query
Expand All @@ -132,7 +79,7 @@ def _collect_events(query, start_time, end_time, url="", user="", password=""):

json_res = create_job.json()
job_id = json_res["sid"]
events = _wait_for_job_and__get_events(job_id, url, user, password)
events = _wait_for_job_and_get_events(job_id, url, user, password)

return events

Expand Down Expand Up @@ -176,7 +123,7 @@ def _collect_metrics(
return events


def _wait_for_job_and__get_events(job_id, url="", user="", password=""):
def _wait_for_job_and_get_events(job_id, url="", user="", password=""):
"""
Wait for the search job to finish and collect the result events
@param: job_id
Expand Down
4 changes: 2 additions & 2 deletions ui_tests/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_check_selected_tab_behaviour():
p_header.switch_to_profiles()
url = driver.current_url
assert "/?tab=Profiles" in url
assert p_profiles.checkIfProfilesTableIsDisplayed()
assert p_profiles.check_if_profiles_table_is_displayed()
driver.refresh()
url = driver.current_url
assert "/?tab=Profiles" in url
Expand All @@ -50,7 +50,7 @@ def test_check_selected_tab_behaviour():
p_header.switch_to_inventory()
url = driver.current_url
assert "/?tab=Inventory" in url
assert p_inventory.checkIfInventoryTableIsDisplayed()
assert p_inventory.check_if_inventory_table_is_displayed()
driver.refresh()
url = driver.current_url
assert "/?tab=Inventory" in url
2 changes: 1 addition & 1 deletion ui_tests/tests/test_groups_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_change_group_name():
assert is_on_list_new is False
# edit name
p_groups.edit_group_name(group_name, new_group_name)
message = p_groups.get_submit_editeg_group_name_popup_message() # common method?
message = p_groups.get_submit_edited_group_name_popup_message() # common method?
expected_message = (
f"{group_name} was also renamed to {new_group_name} in the inventory"
)
Expand Down
1 change: 0 additions & 1 deletion ui_tests/webdriver/webriver_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def get_driver(cls):
options=chrome_options,
)

# if config.EXECUTION_TYPE != "local":
cls._driver.maximize_window()
cls._driver.implicitly_wait(config.IMPLICIT_WAIT_TIMER)
cls._driver.get(config.UI_URL)
Expand Down

0 comments on commit 1658a91

Please sign in to comment.