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 fix selenium failing tests #3212

Merged
merged 9 commits into from
Aug 11, 2024
46 changes: 38 additions & 8 deletions packages/playground/tests/frontend_selenium/pages/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

import time
class BridgePage:

"""
Expand Down Expand Up @@ -86,7 +86,14 @@ def setup_withdraw_tft(self, data):
self.browser.find_element(*self.amount_tft).send_keys(data)

def setup_widthdraw_address(self, data):
balance = self.browser.find_element(*self.balance_text).text[:-4]
balance = 'Loadin'
while(balance == 'Loadin'):
while True:
try:
balance = self.browser.find_element(*self.balance_text).text[:-4]
break # Exit the loop if interaction is successful
except StaleElementReferenceException:
time.sleep(0.5)
self.browser.find_element(*self.withdraw).click()
self.browser.find_element(*self.stellar_address).send_keys(Keys.CONTROL + "a")
self.browser.find_element(*self.stellar_address).send_keys(Keys.DELETE)
Expand All @@ -97,19 +104,22 @@ def check_withdraw_invalid_stellar(self, data):
self.browser.find_element(*self.stellar_address).send_keys(Keys.CONTROL + "a")
self.browser.find_element(*self.stellar_address).send_keys(Keys.DELETE)
self.browser.find_element(*self.stellar_address).send_keys(data)
time.sleep(2)
return self.browser.find_element(*self.submit_button).is_enabled()

def check_withdraw_tft_amount(self, data):
self.browser.find_element(*self.amount_tft).send_keys(Keys.CONTROL + "a")
self.browser.find_element(*self.amount_tft).send_keys(Keys.DELETE)
self.browser.find_element(*self.amount_tft).send_keys(data)
WebDriverWait(self.browser, 30).until(EC.element_to_be_clickable(self.submit_button))
time.sleep(2)
return self.browser.find_element(*self.submit_button).is_enabled()

def check_withdraw_invalid_tft_amount(self, data):
self.browser.find_element(*self.amount_tft).send_keys(Keys.CONTROL + "a")
self.browser.find_element(*self.amount_tft).send_keys(Keys.DELETE)
self.browser.find_element(*self.amount_tft).send_keys(data)
time.sleep(2)
return self.browser.find_element(*self.submit_button).is_enabled()

def check_withdraw(self, address, amount):
Expand All @@ -125,20 +135,40 @@ def check_withdraw(self, address, amount):
return self.browser.find_element(*self.submit_button)

def get_balance(self):
new_balance = self.browser.find_element(*self.balance_text).text[:-4]
while True:
try:
new_balance = self.browser.find_element(*self.balance_text).text[:-4]
break # Exit the loop if interaction is successful
except StaleElementReferenceException:
time.sleep(0.5)
WebDriverWait(self.browser, 30).until(EC.visibility_of_element_located(self.transfer_tft_title))
while('Loadin' in new_balance):
self.wait_for(' Balance: ')
new_balance = self.browser.find_element(*self.balance_text).text[:-4]
while True:
try:
new_balance = self.browser.find_element(*self.balance_text).text[:-4]
break # Exit the loop if interaction is successful
except StaleElementReferenceException:
time.sleep(0.5)
return new_balance

def get_balance_withdraw(self, balance):
new_balance = self.browser.find_element(*self.balance_text).text[:-4]
while True:
try:
new_balance = self.browser.find_element(*self.balance_text).text[:-4]
break # Exit the loop if interaction is successful
except StaleElementReferenceException:
time.sleep(0.5)
self.browser.refresh()
alert = Alert(self.browser)
alert.accept()
# alert = Alert(self.browser)
# alert.accept()
while(new_balance==balance):
new_balance = self.browser.find_element(*self.balance_text).text[:-4]
while True:
try:
new_balance = self.browser.find_element(*self.balance_text).text[:-4]
break # Exit the loop if interaction is successful
except StaleElementReferenceException:
time.sleep(0.5)
return new_balance

def wait_for_button(self, button):
Expand Down
20 changes: 12 additions & 8 deletions packages/playground/tests/frontend_selenium/pages/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class DashboardPage:
usd_price_label = (By.XPATH, '/html/body/div[1]/div/div/main/header/div/div[2]/div/div/div/span[2]')
tft_swap_button = (By.XPATH, '/html/body/div[1]/div/div/main/header/div/div[2]/div/div/div/button/span[3]/i')
tft_info_button = (By.XPATH, '/html/body/div[1]/div/div/main/header/div/div[2]/div/div/div/a/span[3]/i')
stellar_tft_price_label = (By.XPATH, '/html/body/div[2]/div/div[3]/div/div/div[3]/div[1]/div[1]/dl/dd[9]/span')
stellar_tft_price_change_label = (By.XPATH, '/html/body/div[2]/div/div[3]/div/div/div[3]/div[1]/div[1]/dl/dd[9]/span/span[1]')
stellar_tft_price_label = (By.XPATH, "//dt[text()='Current price:']/following-sibling::dd/span[1]")
stellar_tft_price_change_label = (By.XPATH, "//span[contains(@class, 'price-change') and @aria-label]")
mnemonic_input = (By.XPATH, "//input[@placeholder='Please insert your Mnemonic or Hex Seed']")
email_input = (By.XPATH, "//input[@placeholder='email@example.com']")
password_input = (By.XPATH, "(//input[@size='1' and @type='password'])[2]")
Expand All @@ -36,10 +36,10 @@ class DashboardPage:
login_password_input = (By.XPATH, "//label[text()='Password']/following-sibling::input")
accept_terms_condition_button = (By.XPATH, "//button[.//span[text()='Accept terms and conditions']]")
connect_manual_button = (By.XPATH, "//p[@class='mb-4 text-center']/a")
connect_google_button = (By.XPATH, '/html/body/div[2]/div[30]/div[2]/div[2]/div[2]/div[2]/div[2]/section/div/a[1]')
connect_apple_button = (By.XPATH, '/html/body/div[2]/div[30]/div[2]/div[2]/div[2]/div[2]/div[2]/section/div/a[2]')
connect_google_button = (By.XPATH, "//a[@title='play-store']")
connect_apple_button = (By.XPATH, "//a[@title='app-store']")
iframe_load_label = (By.XPATH, "//*[contains(text(), 'THESE TERMS AND CONDITIONS')]")
mnemonic_input_reveal_button = (By.XPATH, '/html/body/div[2]/div[30]/div[2]/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div/div[4]/i')
mnemonic_input_reveal_button = (By.XPATH, "//i[@aria-label='Your Mnemonic appended action']")
mnemonic_login_label = (By.XPATH, "//label[text()='Your Mnemonic']/following-sibling::input")
email_login_label = (By.XPATH, "//label[text()='Email']/following-sibling::input")
id_login_label = (By.XPATH, "//label[text()='Twin ID']/following-sibling::input")
Expand Down Expand Up @@ -82,10 +82,12 @@ def connect_your_wallet(self, email, password):
return self.browser.find_element(*self.connect_button)

def logout_account(self):
time.sleep(3)
self.wait_for_button(self.browser.find_element(*self.logout_button)).click()
WebDriverWait(self.browser, 30).until(EC.visibility_of_element_located(self.find_more_button))
self.browser.refresh()
alert = Alert(self.browser)
alert.accept()
# alert = Alert(self.browser)
# alert.accept()
self.browser.switch_to.window(self.browser.window_handles[0])
WebDriverWait(self.browser, 30).until(EC.visibility_of_element_located(self.profile_load_label))

Expand Down Expand Up @@ -190,7 +192,9 @@ def navigate_to_explore_capacity(self):

def navigate_to_learn_about_grid(self):
WebDriverWait(self.browser, 30).until(EC.visibility_of_element_located(self.learn_about_grid_button))
self.browser.execute_script("window.scrollTo(0,document.body.scrollHeight)")
webdriver.ActionChains(self.browser).send_keys(Keys.END).perform()
webdriver.ActionChains(self.browser).send_keys(Keys.PAGE_DOWN).perform()
time.sleep(3)
self.browser.find_element(*self.learn_about_grid_button).click()
return self.get_link()

Expand Down
49 changes: 35 additions & 14 deletions packages/playground/tests/frontend_selenium/pages/farm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
Expand Down Expand Up @@ -35,7 +36,7 @@ class FarmPage:
save_button = (By.XPATH, "//button[.//span[text()='Add']]")
close_button = (By.XPATH, "//button[.//span[text()='Close']]")
delete_button = (By.XPATH, "//button[.//span[text()=' Delete ']]")
confirm_button = (By.XPATH, "//button[.//span[text()='Confirm']]")
confirm_button = (By.XPATH, "//button[.//span[text()='Delete']]")
zero = (By.XPATH,'//html/body/main/div[1]/div/h1')
table_farm_name=(By.XPATH, '//*[@id="app"]/div[1]/div[2]/div/div[1]/div[4]/div[1]/table/tbody/tr[1]/td[3]')
stellar_payout_address = (By.XPATH, '//table/tbody/tr[2]/td/div[1]/div/div/div[3]/div/div/div[1]/div[2]/p')
Expand Down Expand Up @@ -78,12 +79,31 @@ def create_farm_invalid_name(self, data):
self.browser.find_element(*self.farm_name_text_field).send_keys(data)

def search_functionality(self, farm_name):
tries = 3
table = 'No data available'
while('No data available' in table and tries > 0):
sleep(5)
self.browser.find_element(*self.search_bar).send_keys(Keys.CONTROL + "a")
self.browser.find_element(*self.search_bar).send_keys(Keys.DELETE)
for char in farm_name:
self.browser.find_element(*self.search_bar).send_keys(char)
table = self.browser.find_element(*self.table).text
tries -= 1
sleep(5)
if table.count('NotCertified')>1:
continue
if farm_name in table:
break
return table

def search_functionality_invalid_name(self, farm_name):
sleep(2)
self.browser.find_element(*self.search_bar).send_keys(Keys.CONTROL + "a")
self.browser.find_element(*self.search_bar).send_keys(Keys.DELETE)
self.browser.find_element(*self.search_bar).send_keys(farm_name)
for char in farm_name:
self.browser.find_element(*self.search_bar).send_keys(char)
table = self.browser.find_element(*self.table).text
while('loading farms' in table):
table = self.browser.find_element(*self.table).text
sleep(3)
return table

def display_all_farms(self):
Expand Down Expand Up @@ -223,7 +243,8 @@ def setup_farmpayout_address(self, farm_name):
self.browser.find_element(*self.details_arrow).click()
if(len(self.browser.find_elements(By.XPATH, "//span[contains(@class, 'v-btn__content')]/i[contains(@class, 'mdi-chevron-up')]")) == 0):
self.browser.find_element(*self.details_arrow).click()
self.browser.execute_script("window.scrollBy(0, 250);")
webdriver.ActionChains(self.browser).send_keys(Keys.PAGE_DOWN).perform()
sleep(10)

def reopen_details(self):
WebDriverWait(self.browser, 60).until(EC.visibility_of_element_located((By.XPATH, "//span[contains(@class, 'v-btn__content')]/i[contains(@class, 'mdi-chevron-down')]")))
Expand Down Expand Up @@ -293,12 +314,10 @@ def delete_ip(self, farm_name, ip, gateway):
self.setup_farmpayout_address(farm_name)
WebDriverWait(self.browser, 30).until(EC.visibility_of_element_located((By.XPATH, self.farm_public_ips)))
for i in range(len(self.browser.find_elements(By.XPATH, self.farm_public_ips))):
print(len(self.browser.find_elements(By.XPATH, self.farm_public_ips)))
print(f"{self.farm_public_ips}[{str(i+1)}]/td[1]")
if(self.browser.find_element(By.XPATH, f"{self.farm_public_ips}[{str(i+1)}]/td[2]").text == ip):
if(self.browser.find_element(By.XPATH, f"{self.farm_public_ips}[{str(i+1)}]/td[2]").text == ip):
if(self.browser.find_element(By.XPATH, f"{self.farm_public_ips}[{str(i+1)}]/td[3]").text == gateway):
WebDriverWait(self.browser, 30).until(EC.element_to_be_clickable((By.XPATH, f"{self.farm_public_ips}[{str(i+1)}]/td[1]/div/div/div/input")))
self.browser.find_element(By.XPATH, f"{self.farm_public_ips}[{str(i+1)}]/td[1]/div/div/div/input").click()
#WebDriverWait(self.browser, 30).until(EC.visibility_of_element_located((By.XPATH, f"{self.farm_public_ips}[{str(i+1)}]/td[1]/div/div/div/div/div/input")))
self.browser.find_element(By.XPATH, f"{self.farm_public_ips}[{str(i+1)}]/td[1]/div/div/div/div/div/input").click()
WebDriverWait(self.browser, 30).until(EC.element_to_be_clickable(self.delete_button))
self.browser.find_element(*self.delete_button).click()
WebDriverWait(self.browser, 30).until(EC.element_to_be_clickable(self.confirm_button))
Expand Down Expand Up @@ -329,11 +348,13 @@ def farm_detials(self):
return details

def verify_the_availability_of_zero_os_bootstrap(self):
self.browser.execute_script("window.scrollTo(0,0)")
self.browser.find_element(*self.view_bootstrap_button).click()
WebDriverWait(self.browser, 30).until(EC.number_of_windows_to_be(2))
self.browser.switch_to.window(self.browser.window_handles[1])
return self.browser.current_url
site = self.browser.current_url
self.browser.close()
self.browser.switch_to.window(self.browser.window_handles[0])
return site

def open_create(self):
self.browser.find_element(*self.create_button).click()
Expand All @@ -345,9 +366,9 @@ def close_detail(self):
self.browser.find_element(*self.details_arrow).click()

def wait_for_farm_name(self, keyword):
td_elements = self.browser.find_elements(By.XPATH, "//table[1]//tbody//tr//td[2]")
td_elements = self.browser.find_elements(By.XPATH, "//table[1]//tbody//tr")
td_texts = [td.text for td in td_elements]
return keyword in td_texts
return keyword in td_texts[0]

def wait_for_button(self, button):
WebDriverWait(self.browser, 30).until(EC.element_to_be_clickable(button))
Expand Down
26 changes: 22 additions & 4 deletions packages/playground/tests/frontend_selenium/pages/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,32 @@ def get_twin_id(self):
return twin_id

def get_balance(self):
return self.browser.find_element(*self.balance_text).text[:-4]

balance = 'Loadin'
while(balance == 'Loadin'):
while True:
try:
balance = self.browser.find_element(*self.balance_text).text[:-4]
break # Exit the loop if interaction is successful
except StaleElementReferenceException:
time.sleep(0.5)
return balance

def get_balance_transfer(self, balance):
new_balance = self.browser.find_element(*self.balance_text).text[:-4]
while True:
try:
new_balance = self.browser.find_element(*self.balance_text).text[:-4]
break # Exit the loop if interaction is successful
except StaleElementReferenceException:
time.sleep(0.5)
WebDriverWait(self.browser, 30).until(EC.visibility_of_element_located(self.transfer_tft_title))
while(new_balance == balance or 'Loadin' in new_balance):
self.wait_for(' Balance: ')
new_balance = self.browser.find_element(*self.balance_text).text[:-4]
while True:
try:
new_balance = self.browser.find_element(*self.balance_text).text[:-4]
break # Exit the loop if interaction is successful
except StaleElementReferenceException:
time.sleep(0.5)
return new_balance

def get_address_submit(self):
Expand Down
9 changes: 5 additions & 4 deletions packages/playground/tests/frontend_selenium/pages/twin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TwinPage:
twin_address_text = (By.XPATH, '/html/body/div[1]/div/div/main/div/div[2]/div/div/div/div[2]/div[2]/div[1]/div/div[3]/div[2]/div/div/div/div[1]/span')
twin_relay_text = (By.XPATH, '/html/body/div[1]/div/div/main/div/div[2]/div/div/div/div[2]/div[2]/div[1]/div/div[4]/div[2]/div/div/div')
edit_email_button = (By.XPATH, '/html/body/div[1]/div/div/main/div/div[2]/div/div/div/div[2]/div[2]/div[1]/div/div[2]/div[2]/div/div/div/i')
edit_email_input = (By.XPATH, '/html/body/div[1]/div/div/main/div/div[2]/div/div/div/div[2]/div[2]/div[1]/div/div[2]/div[2]/div/div/form/div/div[1]/div/div[3]/input')
edit_email_input = (By.XPATH, "//input[@placeholder='email@example.com']")
submit_email_button= (By.XPATH, '/html/body/div[1]/div/div/main/div/div[2]/div/div/div/div[2]/div[2]/div[1]/div/div[2]/div[2]/div/div/form/button')
connect_manual_button = (By.XPATH, '/html/body/div[1]/div/div/main/div/div[2]/div/div/div/div[2]/div[2]/div[2]/div[1]/p/a')
connect_google_button = (By.XPATH, '/html/body/div[1]/div/div/main/div/div[2]/div/div/div/div[2]/div[2]/div[2]/div[3]/a[1]')
Expand Down Expand Up @@ -60,7 +60,8 @@ def press_locked_info(self):
def press_edit_btn(self):
email = self.browser.find_element(*self.twin_email_label).text
self.browser.find_element(*self.edit_email_button).click()
self.wait_for(email)
WebDriverWait(self.browser, 30).until(EC.visibility_of_element_located(self.edit_email_input))
return self.browser.find_element(*self.edit_email_input).get_attribute('value')

def edit_twin_email(self, email):
WebDriverWait(self.browser, 30).until(EC.visibility_of_element_located(self.edit_email_input))
Expand All @@ -72,8 +73,8 @@ def press_submit_btn(self):
self.browser.find_element(*self.submit_email_button).click()
WebDriverWait(self.browser, 30).until(EC.visibility_of_element_located(self.edit_email_button))
self.browser.refresh()
alert = Alert(self.browser)
alert.accept()
# alert = Alert(self.browser)
# alert.accept()
self.browser.switch_to.window(self.browser.window_handles[0])
WebDriverWait(self.browser, 30).until(EC.visibility_of_element_located(self.twin_details_label))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pytest==7.4.0
selenium==4.11.2
webdriver_manager==4.0.0
requests==2.31.0
pytest==8.3.2
selenium==4.23.1
webdriver_manager==4.0.2
requests==2.32.3
pyvirtualdisplay==3.0
4 changes: 3 additions & 1 deletion packages/playground/tests/frontend_selenium/selenium.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

- In the root directory, run `yarn install`, then `yarn lerna run build`, and finally `make run project=playground`.
- Change directory to frontend selenium by running `cd packages/playground/tests/frontend_selenium/` in the command line.
- Install the recommended version of the pip package listed above for a stable run, Or you can just install Python 3 and use the command `pip install -r requirements.txt`.
- Install the recommended version of the pip package listed above for a stable run, or you can just install Python 3 and use the command:
- `pip install -r requirements.txt --break-system-packages` (Use this if you don't use any of the listed packages).
- Or use Virtual Environments: First, create an environment using `python -m venv myenv`, then activate it using `source myenv/bin/activate`, and finally, install packages using `pip install -r requirements.txt`.
- Add your configuration either in [config.ini](../frontend_selenium/Config.ini) or by exporting `TFCHAIN_MNEMONICS`, `TFCHAIN_NODE_MNEMONICS`, `STELLAR_ADDRESS`, and `EMAIL`.
- Description of config under `Base` section:
- `port`: the port that the localhost is running on.
Expand Down
Loading
Loading