Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TE-1713 / 13.3 / Fixed test issues and test instabilities #10016

Merged
merged 15 commits into from
May 6, 2024
Merged
145 changes: 45 additions & 100 deletions tests/bdd/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
import time
import xpaths
from configparser import ConfigParser
from function import get, post
from function import (
get,
post,
wait_on_element,
wait_on_element_disappear,
is_element_present,
attribute_value_exist
)
from platform import system
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.common.exceptions import (
ElementClickInterceptedException,
NoSuchElementException,
TimeoutException
ElementClickInterceptedException
)
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options

# random hostname
hostname = f'uitest{"".join(random.choices(string.digits, k=3))}'
Expand Down Expand Up @@ -70,26 +72,18 @@ def iso_version():


def browser():
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.dir", "/tmp")
# this is the place to add file type to autosave
# application/x-tar is use for .tar
# application/gzip is use for .tgz
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-tar,application/gzip,application/json")
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.alwaysOpenPanel", False)
# browser.link.open_newwindow is frozen 2 the only way to change it is like bellow
profile.DEFAULT_PREFERENCES["frozen"]["browser.link.open_newwindow"] = 3
binary = '/usr/bin/firefox' if system() == "Linux" else '/usr/local/bin/firefox'
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['firefox_profile'] = profile.encoded
firefox_capabilities['binary'] = binary
web_driver = webdriver.Firefox(capabilities=firefox_capabilities)
web_driver.set_window_size(1920, 1080)
# web_driver.implicitly_wait(2)
return web_driver
options = Options()
options.set_preference("browser.download.folderList", 2)
options.set_preference("browser.download.dir", "/tmp")
options.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-tar,application/gzip")
options.set_preference("browser.download.manager.showWhenStarting", False)
options.set_preference("browser.link.open_newwindow", 3)
binary = '/snap/firefox/current/usr/lib/firefox/firefox' if system() == "Linux" else '/usr/local/bin/firefox'
geckodriver = '/snap/firefox/current/usr/lib/firefox/geckodriver' if system() == "Linux" else '/usr/local/bin/geckodriver'
options.binary_location = binary
driver = webdriver.Firefox(options=options, executable_path=geckodriver)
driver.set_window_size(1920, 1080)
return driver


web_driver = browser()
Expand Down Expand Up @@ -126,7 +120,7 @@ def pytest_runtest_makereport(item):
validation_error = '//h1[normalize-space(text())="ValidationErrors"]'
call_error = '//h1[normalize-space(text())="CallError"]'
# This looks for plugins install error box and will close the dialog.
if element_exist(error_xpath) or element_exist(failed_xpath) or element_exist(download_xpath) or element_exist(validation_error) or element_exist(call_error):
if is_element_present(web_driver, error_xpath) or is_element_present(web_driver, failed_xpath) or is_element_present(web_driver, download_xpath) or is_element_present(web_driver, validation_error) or is_element_present(web_driver, call_error):
web_driver.find_element_by_xpath('//div[@ix-auto="button__backtrace-toggle"]').click()
time.sleep(2)
save_traceback(traceback_name)
Expand All @@ -140,15 +134,15 @@ def pytest_runtest_makereport(item):
ActionChains(web_driver).send_keys(Keys.ESCAPE).perform()
save_screenshot(screenshot_name)
# This looks for plugins install error box and will close the dialog.
if element_exist('//mat-dialog-container[contains(.,"Install") and contains(.,"Error")]'):
if is_element_present(web_driver, '//mat-dialog-container[contains(.,"Install") and contains(.,"Error")]'):
try:
web_driver.find_element_by_xpath('//button[@ix-auto="button__CLOSE"]').click()
except ElementClickInterceptedException:
# if can't click Close ESCAPE
ActionChains(web_driver).send_keys(Keys.ESCAPE).perform()

# To make sure we are not stuck on a combobox to stop other test to fail
if element_exist('//mat-option'):
if is_element_present(web_driver, '//mat-option'):
ActionChains(web_driver).send_keys(Keys.TAB).perform()
# If the current tab is not the initial tab close the tab
# and switch to initial tab
Expand Down Expand Up @@ -183,80 +177,31 @@ def save_traceback(name):
traceback_file.close()


def element_exist(xpath):
try:
web_driver.find_element_by_xpath(xpath)
return True
except NoSuchElementException:
return False


def wait_on_element(wait, xpath, condition=None):
if condition == 'clickable':
try:
WebDriverWait(web_driver, wait).until(ec.element_to_be_clickable((By.XPATH, xpath)))
return True
except TimeoutException:
return False
if condition == 'presence':
try:
WebDriverWait(web_driver, wait).until(ec.presence_of_element_located((By.XPATH, xpath)))
return True
except TimeoutException:
return False
else:
try:
WebDriverWait(web_driver, wait).until(ec.visibility_of_element_located((By.XPATH, xpath)))
return True
except TimeoutException:
return False


def wait_on_element_disappear(wait, xpath):
timeout = time.time() + wait
while time.time() <= timeout:
if not element_exist(xpath):
return True
# this just to slow down the loop
time.sleep(0.1)
else:
return False


def attribute_value_exist(xpath, attribute, value):
element = web_driver.find_element_by_xpath(xpath)
class_attribute = element.get_attribute(attribute)
if value in class_attribute:
return True
else:
return False


def enable_failover():
# make sure to scroll back up the mat-list-item
element = web_driver.find_element_by_xpath('//span[contains(.,"root")]')
web_driver.execute_script("arguments[0].scrollIntoView();", element)
time.sleep(0.5)
web_driver.find_element_by_xpath('//mat-list-item[@ix-auto="option__System"]').click()
wait_on_element(5, '//mat-list-item[@ix-auto="option__Failover"]')
wait_on_element(web_driver, 5, '//mat-list-item[@ix-auto="option__Failover"]')
web_driver.find_element_by_xpath('//mat-list-item[@ix-auto="option__Failover"]').click()
wait_on_element(5, '//h4[contains(.,"Failover Configuration")]')
wait_on_element(web_driver, 5, '//h4[contains(.,"Failover Configuration")]')
element = web_driver.find_element_by_xpath('//mat-checkbox[@ix-auto="checkbox__Disable Failover"]')
class_attribute = element.get_attribute('class')
if 'mat-checkbox-checked' in class_attribute:
web_driver.find_element_by_xpath('//mat-checkbox[@ix-auto="checkbox__Disable Failover"]').click()
wait_on_element(5, '//button[@ix-auto="button__SAVE"]')
wait_on_element(web_driver, 5, '//button[@ix-auto="button__SAVE"]')
web_driver.find_element_by_xpath('//button[@ix-auto="button__SAVE"]').click()
wait_on_element(5, '//h1[contains(.,"Settings saved")]')
if element_exist('//button[@ix-auto="button__CLOSE"]'):
wait_on_element(web_driver, 5, '//h1[contains(.,"Settings saved")]')
if is_element_present(web_driver, '//button[@ix-auto="button__CLOSE"]'):
web_driver.find_element_by_xpath('//button[@ix-auto="button__CLOSE"]').click()
time.sleep(1)
# make sure to scroll back up the mat-list-item
element = web_driver.find_element_by_xpath('//span[contains(.,"root")]')
web_driver.execute_script("arguments[0].scrollIntoView();", element)
time.sleep(0.5)
web_driver.find_element_by_xpath('//mat-list-item[@ix-auto="option__Dashboard"]').click()
wait_on_element(90, '//mat-icon[@svgicon="ha_enabled"]')
wait_on_element(web_driver, 90, '//mat-icon[@svgicon="ha_enabled"]')


def disable_active_directory():
Expand All @@ -273,36 +218,36 @@ def disable_active_directory():


def disable_ldap():
wait_on_element(5, '//span[contains(.,"root")]')
wait_on_element(web_driver, 5, '//span[contains(.,"root")]')
element = web_driver.find_element_by_xpath('//span[contains(.,"root")]')
web_driver.execute_script("arguments[0].scrollIntoView();", element)
wait_on_element(7, '//mat-list-item[@ix-auto="option__Directory Services"]', 'clickable')
wait_on_element(web_driver, 7, '//mat-list-item[@ix-auto="option__Directory Services"]', 'clickable')
web_driver.find_element_by_xpath('//mat-list-item[@ix-auto="option__Directory Services"]').click()
wait_on_element(7, '//mat-list-item[@ix-auto="option__LDAP"]', 'clickable')
wait_on_element(web_driver, 7, '//mat-list-item[@ix-auto="option__LDAP"]', 'clickable')
web_driver.find_element_by_xpath('//mat-list-item[@ix-auto="option__LDAP"]').click()
assert wait_on_element(5, '//li[span/a/text()="LDAP"]')
assert wait_on_element(5, '//div[contains(.,"Server Credentials")]')
assert wait_on_element(web_driver, 5, '//li[span/a/text()="LDAP"]')
assert wait_on_element(web_driver, 5, '//div[contains(.,"Server Credentials")]')
wait_on_element(5, '//mat-checkbox[@ix-auto="checkbox__Enable"]', 'clickable')
value_exist = attribute_value_exist('//mat-checkbox[@ix-auto="checkbox__Enable"]', 'class', 'mat-checkbox-checked')
value_exist = attribute_value_exist(web_driver, '//mat-checkbox[@ix-auto="checkbox__Enable"]', 'class', 'mat-checkbox-checked')
if value_exist:
web_driver.find_element_by_xpath('//mat-checkbox[@ix-auto="checkbox__Enable"]').click()
wait_on_element(5, '//button[@ix-auto="button__SAVE"]', 'clickable')
web_driver.find_element_by_xpath('//button[@ix-auto="button__SAVE"]').click()
assert wait_on_element_disappear(60, '//h6[contains(.,"Please wait")]')
assert wait_on_element(7, '//div[contains(.,"Settings saved.")]')
assert wait_on_element_disappear(web_driver, 60, '//h6[contains(.,"Please wait")]')
assert wait_on_element(web_driver, 7, '//div[contains(.,"Settings saved.")]')


def disable_nis():
"""click on Directory Services and select NIS, then disable NIS."""
assert wait_on_element(5, xpaths.sideMenu.directory_services, 'clickable')
web_driver.find_element_by_xpath(xpaths.sideMenu.directory_services).click()
assert wait_on_element(7, xpaths.sideMenu.directory_services_nis)
assert wait_on_element(web_driver, 7, xpaths.sideMenu.directory_services_nis)
web_driver.find_element_by_xpath(xpaths.sideMenu.directory_services_nis).click()
assert wait_on_element(5, '//li[span/a/text()="NIS"]')
assert wait_on_element(5, '//h4[contains(.,"Network Information Service (NIS)")]')
assert wait_on_element(5, xpaths.checkbox.enable, 'clickable')
assert wait_on_element(web_driver, 5, '//li[span/a/text()="NIS"]')
assert wait_on_element(web_driver, 5, '//h4[contains(.,"Network Information Service (NIS)")]')
assert wait_on_element(web_driver, 5, xpaths.checkbox.enable, 'clickable')
web_driver.find_element_by_xpath(xpaths.checkbox.enable).click()
assert wait_on_element(5, xpaths.button.save, 'clickable')
web_driver.find_element_by_xpath(xpaths.button.save).click()
assert wait_on_element_disappear(30, xpaths.popupTitle.please_wait)
assert wait_on_element(7, '//div[contains(.,"Settings saved.")]')
assert wait_on_element_disappear(web_driver, 30, xpaths.popup.please_wait)
assert wait_on_element(web_driver, 7, '//div[contains(.,"Settings saved.")]')
15 changes: 2 additions & 13 deletions tests/bdd/core/test_NAS_T1007.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,13 @@ def the_service_page_should_open(driver):
def if_the_smb_service_is_not_started_start_the_service(driver):
"""if the SMB service is not started, start the service."""
assert wait_on_element(driver, 7, '//services')
assert wait_on_element(driver, 7, '//button[@ix-auto="button__S3_Actions"]')
# Scroll to SMB service
element = driver.find_element_by_xpath('//button[@ix-auto="button__S3_Actions"]')
driver.execute_script("arguments[0].scrollIntoView();", element)
time.sleep(1)
driver.find_element_by_xpath('//div[@ix-auto="value__SMB"]')
value_exist = attribute_value_exist(driver, '//mat-slide-toggle[@ix-auto="slider__SMB_Running"]', 'class', 'mat-checked')
if not value_exist:
driver.find_element_by_xpath('//div[@ix-auto="overlay__SMB_Running"]').click()
time.sleep(2)
rsc.set_service_toggle(driver, 'SMB')


@then('click on the SMB Start Automatically checkbox')
def click_on_the_smb_start_automatically_checkbox(driver):
"""click on the SMB Start Automatically checkbox."""
value_exist = attribute_value_exist(driver, '//mat-checkbox[@ix-auto="checkbox__SMB_Start Automatically"]', 'class', 'mat-checkbox-checked')
if not value_exist:
driver.find_element_by_xpath('//mat-checkbox[@ix-auto="checkbox__SMB_Start Automatically"]').click()
rsc.set_service_checkbox(driver, 'SMB')


@then(parsers.parse('send a file to the share with ip/"{smbname}" and "{user}"%"{password}"'))
Expand Down
15 changes: 2 additions & 13 deletions tests/bdd/core/test_NAS_T1010.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,13 @@ def the_service_page_should_open(driver):
def if_the_smb_service_is_not_started_start_the_service(driver):
"""if the SMB service is not started, start the service."""
assert wait_on_element(driver, 7, '//services')
assert wait_on_element(driver, 7, '//button[@ix-auto="button__S3_Actions"]')
# Scroll to SMB service
element = driver.find_element_by_xpath('//button[@ix-auto="button__S3_Actions"]')
driver.execute_script("arguments[0].scrollIntoView();", element)
time.sleep(1)
driver.find_element_by_xpath('//div[@ix-auto="value__SMB"]')
value_exist = attribute_value_exist(driver, '//mat-slide-toggle[@ix-auto="slider__SMB_Running"]', 'class', 'mat-checked')
if not value_exist:
driver.find_element_by_xpath('//div[@ix-auto="overlay__SMB_Running"]').click()
time.sleep(2)
rsc.set_service_toggle(driver, 'SMB')


@then('click on the SMB Start Automatically checkbox')
def click_on_the_smb_start_automatically_checkbox(driver):
"""click on the SMB Start Automatically checkbox."""
value_exist = attribute_value_exist(driver, '//mat-checkbox[@ix-auto="checkbox__SMB_Start Automatically"]', 'class', 'mat-checkbox-checked')
if not value_exist:
driver.find_element_by_xpath('//mat-checkbox[@ix-auto="checkbox__SMB_Start Automatically"]').click()
rsc.set_service_checkbox(driver, 'SMB')


@then(parsers.parse('send a file to the share with ip/"{smbname}" and "{ad_user}"%"{ad_password}"'))
Expand Down
11 changes: 1 addition & 10 deletions tests/bdd/core/test_NAS_T1013.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,7 @@ def the_service_page_should_open(driver):
@then('if the SMB service is not started, start the service')
def if_the_smb_service_is_not_started_start_the_service(driver):
"""if the SMB service is not started, start the service."""
assert wait_on_element(driver, 7, '//button[@ix-auto="button__S3_Actions"]')
# Scroll to SMB service
element = driver.find_element_by_xpath('//button[@ix-auto="button__S3_Actions"]')
driver.execute_script("arguments[0].scrollIntoView();", element)
time.sleep(1)
driver.find_element_by_xpath('//div[@ix-auto="value__SMB"]')
value_exist = attribute_value_exist(driver, '//mat-slide-toggle[@ix-auto="slider__SMB_Running"]', 'class', 'mat-checked')
if not value_exist:
driver.find_element_by_xpath('//div[@ix-auto="overlay__SMB_Running"]').click()
time.sleep(5)
rsc.set_service_toggle(driver, 'SMB')


@then(parsers.parse('send a file to the share with ip/{smbname} and {ldap_user}%{ldap_password}'))
Expand Down
11 changes: 1 addition & 10 deletions tests/bdd/core/test_NAS_T1016.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,7 @@ def the_service_page_should_open(driver):
def if_the_smb_service_is_not_started_start_the_service(driver):
"""if the SMB service is not started, start the service."""
assert wait_on_element(driver, 7, '//services')
assert wait_on_element(driver, 7, '//button[@ix-auto="button__S3_Actions"]')
# Scroll to SMB service
element = driver.find_element_by_xpath('//button[@ix-auto="button__S3_Actions"]')
driver.execute_script("arguments[0].scrollIntoView();", element)
time.sleep(1)
driver.find_element_by_xpath('//div[@ix-auto="value__SMB"]')
value_exist = attribute_value_exist(driver, '//mat-slide-toggle[@ix-auto="slider__SMB_Running"]', 'class', 'mat-checked')
if not value_exist:
driver.find_element_by_xpath('//div[@ix-auto="overlay__SMB_Running"]').click()
time.sleep(2)
rsc.set_service_toggle(driver, 'SMB')


@then(parsers.parse('send a file to the share with NAS IP/{smb_name} and {user}%{password}'))
Expand Down
11 changes: 1 addition & 10 deletions tests/bdd/core/test_NAS_T1018.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,7 @@ def the_service_page_should_open(driver):
def if_the_smb_service_is_not_started_start_the_service(driver):
"""if the SMB service is not started, start the service."""
assert wait_on_element(driver, 7, '//services')
assert wait_on_element(driver, 7, '//button[@ix-auto="button__S3_Actions"]')
# Scroll to SMB service
element = driver.find_element_by_xpath('//button[@ix-auto="button__S3_Actions"]')
driver.execute_script("arguments[0].scrollIntoView();", element)
time.sleep(1)
driver.find_element_by_xpath('//div[@ix-auto="value__SMB"]')
value_exist = attribute_value_exist(driver, '//mat-slide-toggle[@ix-auto="slider__SMB_Running"]', 'class', 'mat-checked')
if not value_exist:
driver.find_element_by_xpath('//div[@ix-auto="overlay__SMB_Running"]').click()
time.sleep(2)
rsc.set_service_toggle(driver, 'SMB')


@then(parsers.parse('send a file to the share with NAS IP/{smb_name} and {user}%{password}'))
Expand Down
16 changes: 1 addition & 15 deletions tests/bdd/core/test_NAS_T1041.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,7 @@ def click_on_service_on_the_side_menu_the_service_page_should_open(driver):
@then('if the SMB service is not started, start the service')
def if_the_smb_service_is_not_started_start_the_service(driver):
"""if the SMB service is not started, start the service."""
if is_element_present(driver, '//li[@aria-label="page 4"]'):
assert wait_on_element(driver, 7, '//li[@aria-label="page 3"]', 'clickable')
driver.find_element_by_xpath('//li[@aria-label="page 3"]').click()
else:
# Scroll to SMB service
assert wait_on_element(driver, 7, '//div[@ix-auto="overlay__S3_Running"]')
element = driver.find_element_by_xpath('//button[@ix-auto="button__S3_Actions"]')
driver.execute_script("arguments[0].scrollIntoView();", element)
time.sleep(0.5)
assert wait_on_element(driver, 7, '//div[@ix-auto="overlay__SMB_Running"]', 'clickable')
value_exist = attribute_value_exist(driver, '//mat-slide-toggle[@ix-auto="slider__SMB_Running"]', 'class', 'mat-checked')
if not value_exist:
driver.find_element_by_xpath('//div[@ix-auto="overlay__SMB_Running"]').click()
# This sleep is to make sure the system ready for smbclient
time.sleep(2)
rsc.set_service_toggle(driver, 'SMB')


@then(parsers.parse('send a file to the share with ip/"{smbname}" and "{user}"%password'))
Expand Down
Loading
Loading