From ba3aaf4c26e0181fa935e9c15085931130efbaec Mon Sep 17 00:00:00 2001 From: saeedr Date: Wed, 20 Nov 2024 16:31:28 +0200 Subject: [PATCH 01/18] update docs to run tests agains mainnet --- .../tests/frontend_selenium/selenium.md | 48 ++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md index 92ab10f270..f3c27e8b44 100644 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ b/packages/playground/tests/frontend_selenium/selenium.md @@ -7,17 +7,40 @@ | [requests](https://pypi.org/project/requests/) | `2.31.0` | | [selenium](https://pypi.org/project/selenium/) | `4.10.0` | | [PyVirtualDisplay](https://pypi.org/project/PyVirtualDisplay/) | `3.0` | -| [webdriver-manager](https://pypi.org/project/webdriver-manager/) | `3.9.1` | +| [webdriver-manager](https://pypi.org/project/webdriver-manager/) | `4.0.2` | ## Running selenium + There are two ways to run the Automation selenium tests: + + 1- Run Tests against the local dashboard environment which installed from latest commit on development branch. + 2- Run Tests against any live environment (Devnet, QAnet, Testnet and Mainnet) -### First +### First (Run Tests against local dashboard) +#### Prepare dashboard locally + - In the root directory 'tfgrid-sdk-ts/', run: + + `yarn install` + `yarn lerna run build` + `make run project=playground` + + - You need to leave the localhost running and open a new terminal. -- 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 --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`. + +### Second (Run Tests against any live environment) +#### update the config files to point to the target environment + - In order to do that; will need to update the env url and some other variables directly in these files config.ini and base.by + - Ex.: to run agains Mainnet + - config.ini: + ``` + [Base] + net = main + ``` + - base.by: + ``` + base_url = 'https://dashboard.grid.tf/' + ``` + +### Setup environment configurations - 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. @@ -28,16 +51,19 @@ - `address`: a stellar address with a TFT trustline that will be used in TFT bridge-related tests. - `email`: a valid email that will be used for all the automated tests. - If the port in serve changes from `5173` for any reason, you should update the `port` under the `Base` section in [config.ini](../frontend_selenium/Config.ini) to reflect the new value. -- You'll also need to install `Xvfb`, Run `sudo apt install xvfb`. -### Second -- You need to leave the localhost running and open a new terminal. +### Prepare tests requirements +- 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 --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`. +- You'll also need to install `Xvfb`, Run `sudo apt install xvfb`. - You can run selenium tests with pytest through the command line using `python3 -m pytest -v`. ### More options to run tests -- If you want to run the tests visually to see how they are running, you need to comment out the lines `16` and `33` in the [conftest.py](../frontend_selenium/tests/conftest.py). +- If you want to run the tests visually to see how they are running, you need to comment out the lines `16` and `34` in the [conftest.py](../frontend_selenium/tests/conftest.py). - You can also run single test file through the command line using `python3 -m pytest -v tests/file/test_file.py`. - You can also run specific test cases through the command line using `python3 -m pytest -v tests/file/test_file.py::test_func`. - You can also run collection of test cases through the command line using `python3 -m pytest -v -k 'test_func or test_func'`. From 4141b63b8fd144bdebdab1196db1e8a513cb1a58 Mon Sep 17 00:00:00 2001 From: saeedr Date: Wed, 20 Nov 2024 16:35:26 +0200 Subject: [PATCH 02/18] Fix homepage tests, update mainnet config needed --- .../tests/frontend_selenium/tests/TFChain/test_homepage.py | 6 +++++- .../playground/tests/frontend_selenium/tests/conftest.py | 3 ++- packages/playground/tests/frontend_selenium/utils/base.py | 5 ++++- .../playground/tests/frontend_selenium/utils/grid_proxy.py | 6 +++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/tests/TFChain/test_homepage.py b/packages/playground/tests/frontend_selenium/tests/TFChain/test_homepage.py index 4433076b39..217620918e 100644 --- a/packages/playground/tests/frontend_selenium/tests/TFChain/test_homepage.py +++ b/packages/playground/tests/frontend_selenium/tests/TFChain/test_homepage.py @@ -24,7 +24,11 @@ def test_validate_homepage_links(browser): """ dashboard_page = before_test_setup(browser) assert dashboard_page.navigate_to_find_more() == ('https://threefold.io/') - assert dashboard_page.navigate_to_explore_capacity() == ( 'https://stats.' + Base.net + '.grid.tf/') + if Base.net == 'main': + stats_url = 'https://stats.grid.tf/' + else: + stats_url = 'https://stats.' + Base.net + '.grid.tf/' + assert dashboard_page.navigate_to_explore_capacity() == ( stats_url ) assert dashboard_page.navigate_to_learn_about_grid() == ('https://www.manual.grid.tf/') diff --git a/packages/playground/tests/frontend_selenium/tests/conftest.py b/packages/playground/tests/frontend_selenium/tests/conftest.py index 50e29c43d8..3aae3f0e30 100644 --- a/packages/playground/tests/frontend_selenium/tests/conftest.py +++ b/packages/playground/tests/frontend_selenium/tests/conftest.py @@ -1,7 +1,7 @@ import pytest from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager -from selenium.webdriver.chrome.service import Service +from selenium.webdriver.chrome.service import Service as ChromeService from pyvirtualdisplay import Display """ @@ -19,6 +19,7 @@ def browser(): options = webdriver.ChromeOptions() #options.add_extension('extension.crx') # For Adding Extension driver = webdriver.Chrome(options=options) + # driver = webdriver.Chrome(options=options, service=ChromeService(ChromeDriverManager().install())) driver.set_window_size(1920, 1080) # Make its calls wait up to 60 seconds for elements to appear diff --git a/packages/playground/tests/frontend_selenium/utils/base.py b/packages/playground/tests/frontend_selenium/utils/base.py index b9f632e1de..bace6a6f94 100644 --- a/packages/playground/tests/frontend_selenium/utils/base.py +++ b/packages/playground/tests/frontend_selenium/utils/base.py @@ -6,4 +6,7 @@ class Base: port = config['Base']['port'] net = config['Base']['net'] base_url = 'http://localhost:' + str(port) + '/' - gridproxy_url = 'https://gridproxy.' + str(net) + '.grid.tf/' \ No newline at end of file + if str(net) == 'main': + gridproxy_url = 'https://gridproxy.grid.tf/' + else: + gridproxy_url = 'https://gridproxy.' + str(net) + '.grid.tf/' \ No newline at end of file diff --git a/packages/playground/tests/frontend_selenium/utils/grid_proxy.py b/packages/playground/tests/frontend_selenium/utils/grid_proxy.py index b7f3a9b1af..4f301144c8 100644 --- a/packages/playground/tests/frontend_selenium/utils/grid_proxy.py +++ b/packages/playground/tests/frontend_selenium/utils/grid_proxy.py @@ -63,7 +63,11 @@ def get_twin_node(self, twin_id): return details def get_stats_capicity(self): - r = requests.post('https://stats.' + Base.net + '.grid.tf/api/stats-summary', timeout=10) + if Base.net == 'main': + stats_url = 'https://stats.grid.tf/api/stats-summary' + else: + stats_url = 'https://stats.' + Base.net + '.grid.tf/api/stats-summary' + r = requests.post(stats_url, timeout=10) stats_json = r.json() return list(stats_json.values()) From 6a82a7da59605dba195cb4416fccd84e74e1d62d Mon Sep 17 00:00:00 2001 From: saeedr Date: Sun, 24 Nov 2024 14:40:55 +0200 Subject: [PATCH 03/18] fix codacy issues --- .../playground/tests/frontend_selenium/selenium.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md index f3c27e8b44..054f6ac418 100644 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ b/packages/playground/tests/frontend_selenium/selenium.md @@ -16,26 +16,28 @@ 2- Run Tests against any live environment (Devnet, QAnet, Testnet and Mainnet) ### First (Run Tests against local dashboard) + #### Prepare dashboard locally - - In the root directory 'tfgrid-sdk-ts/', run: +- In the root directory 'tfgrid-sdk-ts/', run: `yarn install` `yarn lerna run build` `make run project=playground` - - You need to leave the localhost running and open a new terminal. +- You need to leave the localhost running and open a new terminal. ### Second (Run Tests against any live environment) + #### update the config files to point to the target environment - - In order to do that; will need to update the env url and some other variables directly in these files config.ini and base.by - - Ex.: to run agains Mainnet - - config.ini: +- Update the env url and some other variables directly in these files config.ini and base.by +- Ex.: to run agains Mainnet + - config.ini: ``` [Base] net = main ``` - - base.by: + - base.by: ``` base_url = 'https://dashboard.grid.tf/' ``` From f2ad5c6031dfee098afdbe8133efc1930d9eb300 Mon Sep 17 00:00:00 2001 From: saeedr Date: Sun, 24 Nov 2024 15:03:49 +0200 Subject: [PATCH 04/18] fix codacy errors --- .../playground/tests/frontend_selenium/selenium.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md index 054f6ac418..28751b6e7a 100644 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ b/packages/playground/tests/frontend_selenium/selenium.md @@ -17,19 +17,23 @@ ### First (Run Tests against local dashboard) + #### Prepare dashboard locally -- In the root directory 'tfgrid-sdk-ts/', run: + + - In the root directory 'tfgrid-sdk-ts/', run: `yarn install` `yarn lerna run build` `make run project=playground` -- You need to leave the localhost running and open a new terminal. + - You need to leave the localhost running and open a new terminal. ### Second (Run Tests against any live environment) + #### update the config files to point to the target environment + - Update the env url and some other variables directly in these files config.ini and base.by - Ex.: to run agains Mainnet - config.ini: @@ -43,6 +47,7 @@ ``` ### Setup environment configurations + - 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. @@ -56,6 +61,7 @@ ### Prepare tests requirements + - 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 --break-system-packages` (Use this if you don't use any of the listed packages). From 4a3d4e119dd71459027bea4cd948a49d7199047b Mon Sep 17 00:00:00 2001 From: saeedr Date: Sun, 24 Nov 2024 15:11:47 +0200 Subject: [PATCH 05/18] fix codacy error --- .../playground/tests/frontend_selenium/selenium.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md index 28751b6e7a..d53332f91d 100644 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ b/packages/playground/tests/frontend_selenium/selenium.md @@ -17,21 +17,17 @@ ### First (Run Tests against local dashboard) - #### Prepare dashboard locally - - In the root directory 'tfgrid-sdk-ts/', run: +- In the root directory 'tfgrid-sdk-ts/', run: - `yarn install` - `yarn lerna run build` - `make run project=playground` + `yarn install`, `yarn lerna run build`, `make run project=playground` - - You need to leave the localhost running and open a new terminal. +- You need to leave the localhost running and open a new terminal. ### Second (Run Tests against any live environment) - #### update the config files to point to the target environment - Update the env url and some other variables directly in these files config.ini and base.by From 65d5d239e29bd3b67daee10fca0263bb8a9d0133 Mon Sep 17 00:00:00 2001 From: saeedr Date: Sun, 24 Nov 2024 15:18:13 +0200 Subject: [PATCH 06/18] test codacy fix --- .../playground/tests/frontend_selenium/selenium.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md index d53332f91d..6bd7724416 100644 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ b/packages/playground/tests/frontend_selenium/selenium.md @@ -10,6 +10,7 @@ | [webdriver-manager](https://pypi.org/project/webdriver-manager/) | `4.0.2` | ## Running selenium + There are two ways to run the Automation selenium tests: 1- Run Tests against the local dashboard environment which installed from latest commit on development branch. @@ -25,7 +26,6 @@ - You need to leave the localhost running and open a new terminal. - ### Second (Run Tests against any live environment) #### update the config files to point to the target environment @@ -33,14 +33,16 @@ - Update the env url and some other variables directly in these files config.ini and base.by - Ex.: to run agains Mainnet - config.ini: - ``` + ``` [Base] net = main - ``` + + ``` - base.by: - ``` + ``` base_url = 'https://dashboard.grid.tf/' - ``` + + ``` ### Setup environment configurations @@ -55,7 +57,6 @@ - `email`: a valid email that will be used for all the automated tests. - If the port in serve changes from `5173` for any reason, you should update the `port` under the `Base` section in [config.ini](../frontend_selenium/Config.ini) to reflect the new value. - ### Prepare tests requirements - Change directory to frontend selenium by running `cd packages/playground/tests/frontend_selenium/` in the command line. From 05d105d7fc2939bfff5ae56124410842139bf3ef Mon Sep 17 00:00:00 2001 From: saeedr Date: Sun, 24 Nov 2024 15:25:55 +0200 Subject: [PATCH 07/18] test codacy fix --- .../tests/frontend_selenium/selenium.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md index 6bd7724416..8d455bbf23 100644 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ b/packages/playground/tests/frontend_selenium/selenium.md @@ -33,16 +33,14 @@ - Update the env url and some other variables directly in these files config.ini and base.by - Ex.: to run agains Mainnet - config.ini: - ``` - [Base] - net = main - - ``` + ``` + [Base] + net = main + ``` - base.by: - ``` - base_url = 'https://dashboard.grid.tf/' - - ``` + ``` + base_url = 'https://dashboard.grid.tf/' + ``` ### Setup environment configurations From b8655dececa86138145062239e8c34743684b93f Mon Sep 17 00:00:00 2001 From: saeedr Date: Sun, 24 Nov 2024 15:43:12 +0200 Subject: [PATCH 08/18] test codacy bash fix --- packages/playground/tests/frontend_selenium/selenium.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md index 8d455bbf23..ec6c237956 100644 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ b/packages/playground/tests/frontend_selenium/selenium.md @@ -33,12 +33,12 @@ - Update the env url and some other variables directly in these files config.ini and base.by - Ex.: to run agains Mainnet - config.ini: - ``` + ```bash [Base] net = main ``` - base.by: - ``` + ```bash base_url = 'https://dashboard.grid.tf/' ``` From a7218fee2da28858739e763994db33d001dbe619 Mon Sep 17 00:00:00 2001 From: saeedr Date: Sun, 24 Nov 2024 15:48:29 +0200 Subject: [PATCH 09/18] codacy fix --- .../tests/frontend_selenium/selenium.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md index ec6c237956..e6b801bdef 100644 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ b/packages/playground/tests/frontend_selenium/selenium.md @@ -32,15 +32,17 @@ - Update the env url and some other variables directly in these files config.ini and base.by - Ex.: to run agains Mainnet - - config.ini: - ```bash - [Base] - net = main - ``` - - base.by: + + - config.ini + ```bash + [Base] + net = main + ``` + + - base.by ```bash - base_url = 'https://dashboard.grid.tf/' - ``` + base_url = "https://dashboard.grid.tf/" + ``` ### Setup environment configurations From 90d20ba925c3fc168adcc3dde2e2f721bbb1906e Mon Sep 17 00:00:00 2001 From: ramezsaeed Date: Sun, 24 Nov 2024 16:05:07 +0200 Subject: [PATCH 10/18] Update selenium.md --- packages/playground/tests/frontend_selenium/selenium.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md index e6b801bdef..ff5e5007d3 100644 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ b/packages/playground/tests/frontend_selenium/selenium.md @@ -36,8 +36,8 @@ - config.ini ```bash [Base] - net = main - ``` + net = main + ``` - base.by ```bash From c93c13947842ea3b41783d9d12cafc5dc3ddf604 Mon Sep 17 00:00:00 2001 From: ramezsaeed Date: Sun, 24 Nov 2024 16:08:39 +0200 Subject: [PATCH 11/18] Update selenium.md --- packages/playground/tests/frontend_selenium/selenium.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md index ff5e5007d3..edbb6d1053 100644 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ b/packages/playground/tests/frontend_selenium/selenium.md @@ -34,10 +34,10 @@ - Ex.: to run agains Mainnet - config.ini - ```bash - [Base] - net = main - ``` + ```bash + [Base] + net = main + ``` - base.by ```bash From d5e254a87a3273902478b4ef33804261c87222a6 Mon Sep 17 00:00:00 2001 From: ahmedhanafy725 Date: Sun, 24 Nov 2024 16:45:14 +0200 Subject: [PATCH 12/18] Fix the markdown formating for the selenium tests docs --- .../tests/frontend_selenium/selenium.md | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md index edbb6d1053..b2617ec4fd 100644 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ b/packages/playground/tests/frontend_selenium/selenium.md @@ -11,36 +11,43 @@ ## Running selenium - There are two ways to run the Automation selenium tests: - - 1- Run Tests against the local dashboard environment which installed from latest commit on development branch. - 2- Run Tests against any live environment (Devnet, QAnet, Testnet and Mainnet) +There are two ways to run the Automation selenium tests: + +- Run Tests against the local dashboard environment which installed from latest commit on development branch. + +- Run Tests against any live environment (Devnet, QAnet, Testnet and Mainnet) ### First (Run Tests against local dashboard) #### Prepare dashboard locally - In the root directory 'tfgrid-sdk-ts/', run: - - `yarn install`, `yarn lerna run build`, `make run project=playground` - + + ```bash + yarn install + yarn lerna run build + make run project=playground + ``` + - You need to leave the localhost running and open a new terminal. ### Second (Run Tests against any live environment) #### update the config files to point to the target environment -- Update the env url and some other variables directly in these files config.ini and base.by -- Ex.: to run agains Mainnet +- Update the env url and some other variables directly in these files config.ini and base.py +- Ex.: to run against Mainnet - config.ini - ```bash + + ```ini [Base] net = main ``` - - base.by - ```bash + - base.py + + ```python base_url = "https://dashboard.grid.tf/" ``` From 9501d5368bf160471b01797e42a31d923338b875 Mon Sep 17 00:00:00 2001 From: khaledyoussef24 Date: Sun, 1 Dec 2024 07:14:55 +0200 Subject: [PATCH 13/18] Fix farm page tests --- .../tests/frontend_selenium/Config.ini | 8 +++---- .../tests/frontend_selenium/pages/farm.py | 23 ++++++++++++------- .../tests/Farms/test_farm.py | 14 +++++++---- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/packages/playground/tests/frontend_selenium/Config.ini b/packages/playground/tests/frontend_selenium/Config.ini index 2222b381f4..12f266932c 100644 --- a/packages/playground/tests/frontend_selenium/Config.ini +++ b/packages/playground/tests/frontend_selenium/Config.ini @@ -2,7 +2,7 @@ port = 5173 net = dev [Utils] -seed = -node_seed = -address = -email = \ No newline at end of file +seed = upon crystal cake ozone arrest cluster fan sea mistake lyrics wait flat +node_seed =flight letter dream slow system state dolphin unveil problem glow badge bus +address = 0xa36cc9bbd91dbeccb90ae150c2bf1ee11fe3cccb8bf6e5e75ebd863c18727cb9 +email = \ No newline at end of file diff --git a/packages/playground/tests/frontend_selenium/pages/farm.py b/packages/playground/tests/frontend_selenium/pages/farm.py index 780df58fbd..4469dd2f8c 100644 --- a/packages/playground/tests/frontend_selenium/pages/farm.py +++ b/packages/playground/tests/frontend_selenium/pages/farm.py @@ -98,14 +98,21 @@ def search_functionality(self, farm_name): 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) - for char in farm_name: - self.browser.find_element(*self.search_bar).send_keys(char) - table = self.browser.find_element(*self.table).text - sleep(3) - return table + # 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) + # for char in farm_name: + # self.browser.find_element(*self.search_bar).send_keys(char) + # table = self.browser.find_element(*self.table).text + # sleep(3) + # return table + self.wait_until_visible(self.search_bar) + self.browser.find_element(*self.search_bar).clear() + self.browser.find_element(*self.search_bar).send_keys(farm_name) + WebDriverWait(self.browser, 30).until( + lambda driver: "No data available" in driver.find_element(*self.table).text or farm_name in driver.find_element(*self.table).text + ) + return self.browser.find_element(*self.table).text def display_all_farms(self): self.browser.execute_script("window.scrollTo(0,document.body.scrollHeight)") diff --git a/packages/playground/tests/frontend_selenium/tests/Farms/test_farm.py b/packages/playground/tests/frontend_selenium/tests/Farms/test_farm.py index 9d28ff27f8..6c754facc5 100644 --- a/packages/playground/tests/frontend_selenium/tests/Farms/test_farm.py +++ b/packages/playground/tests/frontend_selenium/tests/Farms/test_farm.py @@ -156,7 +156,9 @@ def test_farmpayout_address(browser): assert farm_page.wait_for_farm_name(farm_name) farm_page.search_functionality("") farm_page.setup_farmpayout_address(farm_name) - farm_page.wait_for_button(browser.find_element(*farm_page.add_v2_button)).click() + self.browser.execute_script("arguments[0].scrollIntoView();", self.browser.find_element(*farm_page.add_v2_button)) + self.wait_for_no_overlay() + self.wait_until_clickable(farm_page.add_v2_button).click() cases = [' ', 'dgdd', generate_string(), 'gdhjP6TF3UXYXTNEZ2P36J5FH7W4BJJQ4AYYAXC66I2Q2AH5B6O6Bcfg'] for case in cases: assert farm_page.add_farmpayout_address(case).is_enabled()==False @@ -166,7 +168,9 @@ def test_farmpayout_address(browser): assert farm_page.wait_for('Address Added successfully!') assert farm_page.farmpayout_address_value()[:-3] in case case = "GAK2AN6ZC4REV2GXZPTMJG2JKLRJQX746JNG7ACKNC4RSJE7ETAZSE7D" - farm_page.wait_for_button(browser.find_element(*farm_page.add_v2_button)).click() + self.browser.execute_script("arguments[0].scrollIntoView();", self.browser.find_element(*farm_page.add_v2_button)) + self.wait_for_no_overlay() + self.wait_until_clickable(farm_page.add_v2_button).click() farm_page.wait_for_button(farm_page.add_farmpayout_address(case)).click() assert farm_page.wait_for('This action will be reflected in a bit') assert farm_page.wait_for('Address Added successfully!') @@ -215,8 +219,8 @@ def test_ip(browser): cases = [gateway, '2.0.0.1', '3.0.0.0', '139.255.255.255', '59.15.35.78'] for case in cases: farm_page.setup_gateway('125.25.25.25/16', case, farm_name, False) - assert farm_page.wait_for('Gateway IP not in the provided IP range.') - assert browser.find_element(*farm_page.save_button).is_enabled()==False + assert farm_page.wait_for('Gateway IP not in the provided IP range.'), f"Expected error message for {case}" + assert not browser.find_element(*farm_page.save_button).is_enabled(), "Save button should be disabled" farm_page.close_ip() farm_page.setup_gateway(gateway, gateway, farm_name, False) assert farm_page.wait_for('IPs cannot be the same.') @@ -300,6 +304,8 @@ def test_range_ips(browser): assert farm_page.wait_for('Not a valid IP') assert browser.find_element(*farm_page.save_button).is_enabled()==False farm_page.add_range_ips('255.0.0.1/32', 0, 0).is_enabled() + assert farm_page.wait_for('IP is not public'), "Expected 'IP is not public' error" + assert not browser.find_element(*farm_page.save_button).is_enabled(), "Save button should be disabled for invalid IP" assert farm_page.wait_for('IP is not public') assert browser.find_element(*farm_page.save_button).is_enabled()==False assert farm_page.wait_for_button(farm_page.add_range_ips('1.1.1.254/16', '1.1.1.255/16', '1.1.1.1')).is_enabled()==True From df9df41a08bcb2a03ae52420a67cb812f493a77f Mon Sep 17 00:00:00 2001 From: Khaled Youssef <110984055+khaledyoussef24@users.noreply.github.com> Date: Sun, 1 Dec 2024 07:30:33 +0200 Subject: [PATCH 14/18] Delete packages/playground/tests/frontend_selenium/Config.ini --- packages/playground/tests/frontend_selenium/Config.ini | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 packages/playground/tests/frontend_selenium/Config.ini diff --git a/packages/playground/tests/frontend_selenium/Config.ini b/packages/playground/tests/frontend_selenium/Config.ini deleted file mode 100644 index 12f266932c..0000000000 --- a/packages/playground/tests/frontend_selenium/Config.ini +++ /dev/null @@ -1,8 +0,0 @@ -[Base] -port = 5173 -net = dev -[Utils] -seed = upon crystal cake ozone arrest cluster fan sea mistake lyrics wait flat -node_seed =flight letter dream slow system state dolphin unveil problem glow badge bus -address = 0xa36cc9bbd91dbeccb90ae150c2bf1ee11fe3cccb8bf6e5e75ebd863c18727cb9 -email = \ No newline at end of file From 5f7368f7f6cd1577e5662f2b8bb3429ba2df101c Mon Sep 17 00:00:00 2001 From: Khaled Youssef <110984055+khaledyoussef24@users.noreply.github.com> Date: Sun, 1 Dec 2024 07:31:14 +0200 Subject: [PATCH 15/18] Delete packages/playground/tests/frontend_selenium/selenium.md --- .../tests/frontend_selenium/selenium.md | 82 ------------------- 1 file changed, 82 deletions(-) delete mode 100644 packages/playground/tests/frontend_selenium/selenium.md diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md deleted file mode 100644 index b2617ec4fd..0000000000 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ /dev/null @@ -1,82 +0,0 @@ -# Selenium - -| Prerequisites | version | -| ---------------------------------------------------------------- | -------- | -| [Python](https://www.python.org/downloads/) | `3.10.4` | -| [pytest](https://pypi.org/project/pytest/) | `7.4.0` | -| [requests](https://pypi.org/project/requests/) | `2.31.0` | -| [selenium](https://pypi.org/project/selenium/) | `4.10.0` | -| [PyVirtualDisplay](https://pypi.org/project/PyVirtualDisplay/) | `3.0` | -| [webdriver-manager](https://pypi.org/project/webdriver-manager/) | `4.0.2` | - -## Running selenium - -There are two ways to run the Automation selenium tests: - -- Run Tests against the local dashboard environment which installed from latest commit on development branch. - -- Run Tests against any live environment (Devnet, QAnet, Testnet and Mainnet) - -### First (Run Tests against local dashboard) - -#### Prepare dashboard locally - -- In the root directory 'tfgrid-sdk-ts/', run: - - ```bash - yarn install - yarn lerna run build - make run project=playground - ``` - -- You need to leave the localhost running and open a new terminal. - -### Second (Run Tests against any live environment) - -#### update the config files to point to the target environment - -- Update the env url and some other variables directly in these files config.ini and base.py -- Ex.: to run against Mainnet - - - config.ini - - ```ini - [Base] - net = main - ``` - - - base.py - - ```python - base_url = "https://dashboard.grid.tf/" - ``` - -### Setup environment configurations - -- 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. - - `net`: the network that the tests will be run against. -- Description of config under `Utils` section: - - `seed`: twin mnemonic that will be used for all the automated tests. - - `node_seed`: twin mnemonic for the node that will be used in node-related tests. - - `address`: a stellar address with a TFT trustline that will be used in TFT bridge-related tests. - - `email`: a valid email that will be used for all the automated tests. -- If the port in serve changes from `5173` for any reason, you should update the `port` under the `Base` section in [config.ini](../frontend_selenium/Config.ini) to reflect the new value. - -### Prepare tests requirements - -- 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 --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`. -- You'll also need to install `Xvfb`, Run `sudo apt install xvfb`. -- You can run selenium tests with pytest through the command line using `python3 -m pytest -v`. - -### More options to run tests - -- If you want to run the tests visually to see how they are running, you need to comment out the lines `16` and `34` in the [conftest.py](../frontend_selenium/tests/conftest.py). -- You can also run single test file through the command line using `python3 -m pytest -v tests/file/test_file.py`. -- You can also run specific test cases through the command line using `python3 -m pytest -v tests/file/test_file.py::test_func`. -- You can also run collection of test cases through the command line using `python3 -m pytest -v -k 'test_func or test_func'`. -- You can also run all the tests and get an HTML report using [pytest-html](https://pypi.org/project/pytest-html/) package through the command line using `python3 -m pytest -v --html=report.html`. From 6126b3f657dc1e80d544dadc6616867a7e2929ab Mon Sep 17 00:00:00 2001 From: Khaled Youssef <110984055+khaledyoussef24@users.noreply.github.com> Date: Sun, 1 Dec 2024 07:31:39 +0200 Subject: [PATCH 16/18] Delete packages/playground/tests/frontend_selenium/tests/conftest.py --- .../tests/frontend_selenium/tests/conftest.py | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 packages/playground/tests/frontend_selenium/tests/conftest.py diff --git a/packages/playground/tests/frontend_selenium/tests/conftest.py b/packages/playground/tests/frontend_selenium/tests/conftest.py deleted file mode 100644 index 3aae3f0e30..0000000000 --- a/packages/playground/tests/frontend_selenium/tests/conftest.py +++ /dev/null @@ -1,34 +0,0 @@ -import pytest -from selenium import webdriver -from webdriver_manager.chrome import ChromeDriverManager -from selenium.webdriver.chrome.service import Service as ChromeService -from pyvirtualdisplay import Display - -""" -This module contains shared browser fixtures. -""" - -@pytest.fixture -def browser(): - - # Virtual display for the browser, allowing it to run in headless mode - display = Display(visible=0, size=(1920, 1080)) - display.start() - - # Initialize the ChromeDriver instance with options - options = webdriver.ChromeOptions() - #options.add_extension('extension.crx') # For Adding Extension - driver = webdriver.Chrome(options=options) - # driver = webdriver.Chrome(options=options, service=ChromeService(ChromeDriverManager().install())) - driver.set_window_size(1920, 1080) - - # Make its calls wait up to 60 seconds for elements to appear - driver.implicitly_wait(60) - - # Return the WebDriver instance for the setup - yield driver - - # Quit the WebDriver instance for the cleanup - driver.quit() - # Ending virtual display for the browser - display.stop() \ No newline at end of file From 42cdfa2793ce68609cbf942f3da45a4e42be1b10 Mon Sep 17 00:00:00 2001 From: Khaled Youssef <110984055+khaledyoussef24@users.noreply.github.com> Date: Sun, 1 Dec 2024 07:32:00 +0200 Subject: [PATCH 17/18] Delete packages/playground/tests/frontend_selenium/utils/base.py --- .../playground/tests/frontend_selenium/utils/base.py | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 packages/playground/tests/frontend_selenium/utils/base.py diff --git a/packages/playground/tests/frontend_selenium/utils/base.py b/packages/playground/tests/frontend_selenium/utils/base.py deleted file mode 100644 index bace6a6f94..0000000000 --- a/packages/playground/tests/frontend_selenium/utils/base.py +++ /dev/null @@ -1,12 +0,0 @@ -import configparser - -class Base: - config = configparser.ConfigParser() - config.read('Config.ini') - port = config['Base']['port'] - net = config['Base']['net'] - base_url = 'http://localhost:' + str(port) + '/' - if str(net) == 'main': - gridproxy_url = 'https://gridproxy.grid.tf/' - else: - gridproxy_url = 'https://gridproxy.' + str(net) + '.grid.tf/' \ No newline at end of file From b1c6bff4641f6636ae6411eec9aab4f63a75389b Mon Sep 17 00:00:00 2001 From: Khaled Youssef <110984055+khaledyoussef24@users.noreply.github.com> Date: Sun, 1 Dec 2024 07:32:11 +0200 Subject: [PATCH 18/18] Delete packages/playground/tests/frontend_selenium/utils/grid_proxy.py --- .../frontend_selenium/utils/grid_proxy.py | 105 ------------------ 1 file changed, 105 deletions(-) delete mode 100644 packages/playground/tests/frontend_selenium/utils/grid_proxy.py diff --git a/packages/playground/tests/frontend_selenium/utils/grid_proxy.py b/packages/playground/tests/frontend_selenium/utils/grid_proxy.py deleted file mode 100644 index 4f301144c8..0000000000 --- a/packages/playground/tests/frontend_selenium/utils/grid_proxy.py +++ /dev/null @@ -1,105 +0,0 @@ -import requests -from utils.base import Base - -""" -This module contains Grid Proxy getters. -""" - -class GridProxy: - - def __init__(self, browser): - self.browser = browser - - def get_rentable_node(self): - r = requests.post(Base.gridproxy_url + 'nodes?rentable=true&status=up') - node_list = r.json() - r = requests.post(Base.gridproxy_url + 'nodes?rented=true&status=up') - node_list.extend(r.json()) - return node_list - - def get_farm_details(self, farm_name): - r = requests.post(Base.gridproxy_url + 'farms?name=' + farm_name) - details = r.json() - return details - - def get_dedicate_status(self, node_id): - r = requests.post(Base.gridproxy_url + 'nodes/'+ str(node_id)) - dedicate_status = r.json() - return (dedicate_status['rentedByTwinId']) - - def get_node_ipv4(self, node_id): - r = requests.post(Base.gridproxy_url + 'nodes/'+ str(node_id)) - farm_node = r.json() - return (farm_node['publicConfig']['ipv4']) - - def get_node_fee(self, node_id): - r = requests.post(Base.gridproxy_url + 'nodes/'+ str(node_id)) - farm_node = r.json() - return (farm_node['extraFee'])/1000 - - def get_twin_address(self, twin_id): - r = requests.post(Base.gridproxy_url + 'twins?twin_id='+ twin_id) - details = r.json() - return details[0]['accountId'] - - def get_twin_relay(self, twin_id): - r = requests.post(Base.gridproxy_url + 'twins?twin_id='+ twin_id) - details = r.json() - return details[0]['relay'] - - def get_farm_ips(self, farm_id): - r = requests.post(Base.gridproxy_url + 'farms?farm_id='+ farm_id) - farm_list = r.json() - return len(farm_list[0]['publicIps']) - - def get_twin_node(self, twin_id): - r = requests.post(Base.gridproxy_url + 'farms?twin_id=' + twin_id) - details = r.json() - farms = '' - for detail in details: - farms += str(detail['farmId']) + ',' - r = requests.post(Base.gridproxy_url + 'nodes?farm_ids=' + farms[:-1]) - details = r.json() - return details - - def get_stats_capicity(self): - if Base.net == 'main': - stats_url = 'https://stats.grid.tf/api/stats-summary' - else: - stats_url = 'https://stats.' + Base.net + '.grid.tf/api/stats-summary' - r = requests.post(stats_url, timeout=10) - stats_json = r.json() - return list(stats_json.values()) - - def get_stats(self): - up = requests.get(Base.gridproxy_url + 'stats?status=up', timeout=10).json() - standby = requests.get(Base.gridproxy_url + 'stats?status=standby', timeout=10).json() - # Initialize a dictionary to store the merged data - merged_data = {} - # Merge simple values, summing if they differ - keys_to_sum = ['nodes', 'accessNodes', 'totalCru', 'totalSru', 'totalMru', 'totalHru', 'gpus', 'dedicatedNodes', 'workloads_number'] - for key in keys_to_sum: - merged_data[key] = up[key] + standby[key] - # Merge the "farms", "publicIps", "gateways", "twins", and "contracts" fields (they are the same) - keys_to_add_once = ['farms', 'publicIps', 'gateways', 'twins', 'contracts'] - for key in keys_to_add_once: - merged_data[key] = up[key] - # Merge nodesDistribution and calculate unique and common countries - up_distribution = up['nodesDistribution'] - standby_distribution = standby['nodesDistribution'] - merged_distribution = {} - common_countries = 0 - for country, up_count in up_distribution.items(): - standby_count = standby_distribution.get(country, 0) - merged_distribution[country] = up_count + standby_count - if standby_count > 0: - common_countries += 1 - for country, standby_count in standby_distribution.items(): - if country not in merged_distribution: - merged_distribution[country] = standby_count - merged_data['nodesDistribution'] = merged_distribution - # Calculate the total countries: all unique countries minus common countries - total_countries = len(merged_distribution) # Total unique countries - merged_data['countries'] = total_countries - # Return the dictionary directly - return merged_data