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

Development selenium add stats page tests 1 #3313

Merged
merged 16 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions packages/playground/tests/frontend_selenium/pages/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,33 @@ def navigate(self):
WebDriverWait(self.browser, 60).until(EC.visibility_of_element_located(self.statistics_label))

def statistics_detials(self):
details = []
details = {}
wait = WebDriverWait(self.browser, 60) # Increased wait time to 60 seconds
elements_to_fetch = [
("Nodes Online", self.nodes_online),
("Dedicated Machines", self.dedicated_machines),
("Farms", self.farms),
("Countries", self.countries),
("CPUs", self.cpus),
("SSD Storage", self.ssd_storage),
("HDD Storage", self.hdd_storage),
("RAM", self.ram),
("GPUs", self.gpus),
("Access Nodes", self.access_nodes),
("Gateways", self.gateways),
("Twins", self.twins),
("Public IPs", self.public_ips),
("Contracts", self.conracts),
("Number of workloads", self.number_of_workloads)
]
for _, locator in elements_to_fetch:
elements_to_fetch = {
"nodes": self.nodes_online,
"dedicatedNodes": self.dedicated_machines,
"farms": self.farms,
"countries": self.countries,
"totalCru": self.cpus,
"totalSru": self.ssd_storage,
"totalHru": self.hdd_storage,
"totalMru": self.ram,
"gpus": self.gpus,
"accessNodes": self.access_nodes,
"gateways": self.gateways,
"twins": self.twins,
"publicIps": self.public_ips,
"contracts": self.conracts,
"workloads_number": self.number_of_workloads
}

for key, locator in elements_to_fetch.items():
try:
element_text = wait.until(EC.visibility_of_element_located(locator)).text
details.append(element_text)
details[key] = element_text
except TimeoutException:
details.append(None) # Add None or some default value to maintain list consistency
details[key] = None # Add None or some default value to maintain dictionary consistency

return details

def get_link(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,53 @@ def before_test_setup(browser):
statistics_page.navigate()
return statistics_page


def test_statistics_details(browser):
"""
TC1503 - Verify Statistics
Steps:
- Navigate to the dashboard.
- Click on TFGrid from side menu.
- Click on Stats.
Result: Assert that the displayed values should match the data from the grid proxy.
"""
statistics_page = before_test_setup(browser)
grid_proxy = GridProxy(browser)
statistics_details = statistics_page.statistics_detials()
grid_statistics_details = grid_proxy.get_stats()
# Convert necessary values from string to integer before comparing
statistics_details_converted = [int(detail.replace(',', '')) if detail is not None and detail.isdigit() else detail for detail in statistics_details]
# Convert necessary values from string to integer for comparison, but keeping the dictionary structure
statistics_details_converted = {
key: int(value.replace(',', '')) if value is not None and value.replace(',', '').isdigit() else value
for key, value in statistics_details.items()
}
# Full set of assertions, comparing UI stats with proxy stats
assert grid_statistics_details['nodes'] == statistics_details_converted[0]
assert grid_statistics_details['dedicatedNodes'] == statistics_details_converted[1]
assert grid_statistics_details['farms'] == statistics_details_converted[2]
assert grid_statistics_details['countries'] == statistics_details_converted[3]
assert grid_statistics_details['totalCru'] == statistics_details_converted[4]
assert math.isclose(convert_to_scaled_float(grid_statistics_details['totalSru']), convert_to_scaled_float(byte_converter(statistics_details_converted[5])), abs_tol=0.002)
assert math.isclose(convert_to_scaled_float(grid_statistics_details['totalHru']), convert_to_scaled_float(byte_converter(statistics_details_converted[6])), abs_tol=0.002)
assert math.isclose(convert_to_scaled_float(grid_statistics_details['totalMru']), convert_to_scaled_float(byte_converter(statistics_details_converted[7])), abs_tol=0.002)
assert grid_statistics_details['gpus'] == statistics_details_converted[8]
assert grid_statistics_details['accessNodes'] == statistics_details_converted[9]
assert grid_statistics_details['gateways'] == statistics_details_converted[10]
assert grid_statistics_details['twins'] == statistics_details_converted[11]
assert grid_statistics_details['publicIps'] == statistics_details_converted[12]
assert grid_statistics_details['contracts'] == statistics_details_converted[13]
assert grid_statistics_details['workloads_number'] == statistics_details_converted[14]
assert grid_statistics_details['nodes'] == statistics_details_converted['nodes']
assert grid_statistics_details['dedicatedNodes'] == statistics_details_converted['dedicatedNodes']
assert grid_statistics_details['farms'] == statistics_details_converted['farms']
assert grid_statistics_details['countries'] == statistics_details_converted['countries']
assert grid_statistics_details['totalCru'] == statistics_details_converted['totalCru']
assert math.isclose(convert_to_scaled_float(grid_statistics_details['totalSru']), convert_to_scaled_float(byte_converter(statistics_details_converted['totalSru'])), abs_tol=0.002)
assert math.isclose(convert_to_scaled_float(grid_statistics_details['totalHru']), convert_to_scaled_float(byte_converter(statistics_details_converted['totalHru'])), abs_tol=0.002)
assert math.isclose(convert_to_scaled_float(grid_statistics_details['totalMru']), convert_to_scaled_float(byte_converter(statistics_details_converted['totalMru'])), abs_tol=0.002)
assert grid_statistics_details['gpus'] == statistics_details_converted['gpus']
assert grid_statistics_details['accessNodes'] == statistics_details_converted['accessNodes']
assert grid_statistics_details['gateways'] == statistics_details_converted['gateways']
assert grid_statistics_details['twins'] == statistics_details_converted['twins']
assert grid_statistics_details['publicIps'] == statistics_details_converted['publicIps']
assert grid_statistics_details['contracts'] == statistics_details_converted['contracts']
assert grid_statistics_details['workloads_number'] == statistics_details_converted['workloads_number']


def test_tfgrid_links(browser):
A-Harby marked this conversation as resolved.
Show resolved Hide resolved
"""
TC2867 - Verify TFGrid links
Steps:
- Navigate to the dashboard.
- Click on TFGrid from side menu.
- Click on Grid Status.
- Click on Node Monitoring.
Result: Assert that The links match the pages.
"""
statistics_page = before_test_setup(browser)
assert statistics_page.grid_status_link() == 'https://status.grid.tf/status/threefold/'
assert statistics_page.node_monitoring_link() == 'https://metrics.grid.tf/d/rYdddlPWkfqwf/zos-host-metrics?orgId=2&refresh=30s/'
19 changes: 12 additions & 7 deletions packages/playground/tests/frontend_selenium/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,20 @@ def convert_to_scaled_float(number):
return scaled_number



def byte_converter(value):
A-Harby marked this conversation as resolved.
Show resolved Hide resolved
# Define the unit and the numeric value before checking conditions
unit = value[-2].upper() # Last character represents the unit (P, T, G)
number_str = value[:-3].strip() # Everything except the last two characters is the number

if value != '0':
if value[-2] == 'P':
return float(value[:-3]) * (1024 ** 5)
elif value[-2] == 'T':
return float(value[:-3]) * (1024 ** 4)
elif value[-2] == 'G':
return float(value[:-3])
# Convert based on the unit
if unit == 'P': # Petabytes
return float(number_str) * (1024 ** 5)
elif unit == 'T': # Terabytes
return float(number_str) * (1024 ** 4)
elif unit == 'G': # Gigabytes
return float(number_str) # No conversion needed, already in gigabytes

A-Harby marked this conversation as resolved.
Show resolved Hide resolved
return float(value)


Expand Down
Loading