Skip to content

Commit

Permalink
changes after review part - 3
Browse files Browse the repository at this point in the history
  • Loading branch information
pszkamruk-splunk committed Nov 28, 2023
1 parent b703dab commit 152f795
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 58 deletions.
37 changes: 19 additions & 18 deletions ui_tests/pages/groups_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,32 +225,33 @@ def set_snmp_version(self, snmp_version):

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

def get_device_snmp_version(self, device_ip):
logger.info(f"get device snmp_version: {device_ip}")
version_xpath = f"//td[@data-test='sc4snmp:host-version' and ancestor::tr//td[text()='{device_ip}']]"
version = driver.find_element(By.XPATH, version_xpath)
return version.text
self._get_group_field_value("snmp_version", device_ip)

def get_device_community_string(self, device_ip):
logger.info(f"get device community string: {device_ip}")
community_xpath = f"//td[@data-test='sc4snmp:host-community' and ancestor::tr//td[text()='{device_ip}']]"
community = driver.find_element(By.XPATH, community_xpath)
return community.text
self._get_group_field_value("community_string", 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_secret(self, device_ip):
logger.info(f"get device secret: {device_ip}")
self._get_group_field_value("secret", device_ip)

def get_device_security_engine(self, device_ip):
logger.info(f"get device security engine {device_ip}")
self._get_group_field_value("security_engine", 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)
def _get_group_field_value(self, field, device_ip):
xpath = {
"port": f"//td[@data-test='sc4snmp:host-port' and ancestor::tr//td[text()='{device_ip}']]",
"snmp_version": f"//td[@data-test='sc4snmp:host-version' and ancestor::tr//td[text()='{device_ip}']]",
"community_string": f"//td[@data-test='sc4snmp:host-community' and ancestor::tr//td[text()='{device_ip}']]",
"secret": f"//td[@data-test='sc4snmp:host-secret' and ancestor::tr//td[text()='{device_ip}']]",
"security_engine": f"//td[@data-test='sc4snmp:host-security-engine' and ancestor::tr//td[text()='{device_ip}']]"
}
community = driver.find_element(By.XPATH, xpath[field])
return community.text

def get_warning_message_when_removing_group_which_is_configured_in_inventory(self):
Expand Down
68 changes: 28 additions & 40 deletions ui_tests/pages/inventory_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ def click_add_new_device_group_button(self):
add_grp_device_btn.click()
time.sleep(3)

def set_host_or_group_name(self, host_ip, edit=False):
logger.info(f"Set host/group item name: {host_ip}")
group_device_input_field_xpath = (
"//div[@data-test='sc4snmp:form:group-ip-input']//span//input"
)
grp_device_input_field = driver.find_element(
By.XPATH, group_device_input_field_xpath
)
if edit:
helper.clear_input(grp_device_input_field)
grp_device_input_field.send_keys(host_ip)

def click_submit_button_for_add_entry(self):
self._click_submit_button()

Expand Down Expand Up @@ -148,28 +136,25 @@ def select_group_inventory_type(self):

def get_host_missing_error(self):
logger.info(f"Get host missing error")
host_error_xpath = f"//p[@data-test='sc4snmp:ip-group-error']"
try:
host_error = driver.find_element(By.XPATH, host_error_xpath)
return host_error.text
except selenium.common.exceptions.NoSuchElementException:
return None
self._get_error_for_missing_or_invalid_inventory_field("host_missing")

def get_community_string_missing_error(self):
logger.info(f"Get community string missing error")
community_error_xpath = f"//p[@data-test='sc4snmp:community-error']"
try:
community_error = driver.find_element(By.XPATH, community_error_xpath)
return community_error.text
except selenium.common.exceptions.NoSuchElementException:
return None
self._get_error_for_missing_or_invalid_inventory_field("community_string_missing")

def get_walk_invalid_value_error(self):
logger.info(f"Get walk interval invalid value error")
walk_interval_error_xpath = f"//p[@data-test='sc4snmp:walk-interval-error']"
self._get_error_for_missing_or_invalid_inventory_field("walk_invalid_value")

def _get_error_for_missing_or_invalid_inventory_field(self, field):
xpath = {
"host_missing": f"//p[@data-test='sc4snmp:ip-group-error']",
"community_string_missing": f"//p[@data-test='sc4snmp:community-error']",
"walk_invalid_value": f"//p[@data-test='sc4snmp:walk-interval-error']"
}
try:
walk_interval_error = driver.find_element(By.XPATH, walk_interval_error_xpath)
return walk_interval_error.text
error_msg = driver.find_element(By.XPATH, xpath[field])
return error_msg.text
except selenium.common.exceptions.NoSuchElementException:
return None

Expand Down Expand Up @@ -198,25 +183,28 @@ def select_snmp_version(self, snmp_version):
option = driver.find_element(By.XPATH, options[snmp_version])
option.click()

def set_host_or_group_name(self, host_ip, edit=False):
logger.info(f"Set host/group item name: {host_ip}")
self._set_inventory_field("host_group_name", host_ip, edit)

def set_secret(self, secret, edit=False):
logger.info(f"set inventory device secret: {secret}")
secret_field_xpath = (
"//div[@data-test='sc4snmp:form:secret-input']//span//input"
)
secret_field = driver.find_element(By.XPATH, secret_field_xpath)
if edit:
helper.clear_input(secret_field)
secret_field.send_keys(secret)
self._set_inventory_field("secret", secret, edit)

def set_security_engine(self, security_engine, edit=False):
logger.info(f"set inventory device security engine: {security_engine}")
sec_engine_field_xpath = (
"//div[@data-test='sc4snmp:form:security-engine-input']//span//input"
)
sec_engine = driver.find_element(By.XPATH, sec_engine_field_xpath)
self._set_inventory_field("security_engine", security_engine, edit)

def _set_inventory_field(self, field, value, edit=False):
xpath = {
"host_group_name": "//div[@data-test='sc4snmp:form:group-ip-input']//span//input",
"secret": "//div[@data-test='sc4snmp:form:secret-input']//span//input",
"security_engine": "//div[@data-test='sc4snmp:form:security-engine-input']//span//input"
}
field_input = driver.find_element(By.XPATH, xpath[field])
if edit:
helper.clear_input(sec_engine)
sec_engine.send_keys(security_engine)
helper.clear_input(field_input)
field_input.send_keys(value)

def set_walk_interval(self, walk_interval):
logger.info(f"set/edit inventory device walk interval: {walk_interval}")
Expand Down

0 comments on commit 152f795

Please sign in to comment.