diff --git a/.github/workflows/playground_selenium.yaml b/.github/workflows/playground_selenium.yaml index 6c2dd0f43d..5b7b5a3936 100644 --- a/.github/workflows/playground_selenium.yaml +++ b/.github/workflows/playground_selenium.yaml @@ -2,40 +2,115 @@ name: Playground Selenium Tests on: workflow_dispatch: + inputs: + network: + description: "Select network (dev, qa, test, main)" + required: true + default: dev + type: choice + options: [dev, qa, test, main] + mode: + description: "Select mode (build|remote)" + required: true + default: remote + type: choice + options: [build, remote] schedule: - cron: "0 6 * * *" jobs: selenium-run: runs-on: ubuntu-latest + + # Pass secrets in for Config.ini + env: + TFCHAIN_MNEMONICS: ${{ secrets.TFCHAIN_MNEMONICS }} + TFCHAIN_NODE_MNEMONICS: ${{ secrets.TFCHAIN_NODE_MNEMONICS }} + STELLAR_ADDRESS: ${{ secrets.STELLAR_ADDRESS }} + EMAIL: ${{ secrets.EMAIL }} + steps: - - name: Checkout + - name: Checkout code uses: actions/checkout@v4 - - name: Setting up Python + + - name: Determine network + mode + id: vars + run: | + echo "network=${{ github.event.inputs.network }}" >> $GITHUB_OUTPUT + echo "mode=${{ github.event.inputs.mode }}" >> $GITHUB_OUTPUT + + - name: Set up Python 3.10 uses: actions/setup-python@v5 with: python-version: "3.10" - - name: Install system dependencies - run: sudo apt-get update && sudo apt-get install -y xclip - - name: Installing all necessary packages - run: pip install -r packages/playground/tests/frontend_selenium/requirements.txt - - name: Node install + + - name: Install Python deps (including pytest-html) + run: | + python3 -m pip install --upgrade pip + python3 -m pip install -r packages/playground/tests/frontend_selenium/requirements.txt + python3 -m pip install pytest-html + + - name: Set up Node.js 18 uses: actions/setup-node@v4 with: - node-version: 18 - - name: Yarn install + node-version: "18" + + - name: Install Node deps run: yarn install - - name: Lerna Build - run: yarn lerna run build - - name: Yarn Serve - run: make run project=playground & - - name: Wait for localhost - run: sleep 60 - - name: Run tests - working-directory: ./packages/playground/tests/frontend_selenium + + - name: Build & serve (only build mode) + if: ${{ steps.vars.outputs.mode == 'build' }} + run: | + yarn lerna run build + nohup make run project=playground > server.log 2>&1 & + echo "Waiting for http://localhost:5173…" + for i in {1..60}; do + curl -sf http://localhost:5173 && break + sleep 1 + done + + - name: Generate Config.ini via Python + working-directory: packages/playground/tests/frontend_selenium env: - TFCHAIN_MNEMONICS: ${{ secrets.TFCHAIN_MNEMONICS }} - TFCHAIN_NODE_MNEMONICS: ${{ secrets.TFCHAIN_NODE_MNEMONICS }} - STELLAR_ADDRESS: ${{ secrets.STELLAR_ADDRESS }} - EMAIL: ${{ secrets.EMAIL }} - run: python -m pytest -v + NETWORK: ${{ steps.vars.outputs.network }} + MODE: ${{ steps.vars.outputs.mode }} + run: | + python3 - <<'EOF' + import os, configparser + + def flatten(var): + return os.getenv(var, "").replace("\n", " ").strip() + + net = os.environ["NETWORK"] + mode = os.environ["MODE"] + base_url = ("http://localhost:5173" if mode=="build" + else f"https://dashboard.{net}.grid.tf/") + + cfg = configparser.ConfigParser() + cfg["Base"] = { + "port": "5173", + "net": net, + "base_url": base_url + } + cfg["Utils"] = { + "seed": flatten("TFCHAIN_MNEMONICS"), + "node_seed": flatten("TFCHAIN_NODE_MNEMONICS"), + "address": flatten("STELLAR_ADDRESS"), + "email": flatten("EMAIL") + } + with open("Config.ini", "w") as f: + cfg.write(f) + EOF + + - name: Verify Config.ini exists and contents + working-directory: packages/playground/tests/frontend_selenium + run: | + echo "→ Files in $(pwd):" + ls -1 + echo "" + echo "→ Config.ini contents:" + nl Config.ini + + - name: Run Selenium tests + working-directory: packages/playground/tests/frontend_selenium + run: python3 -m pytest -v --html=report.html diff --git a/packages/playground/tests/frontend_selenium/Config.ini b/packages/playground/tests/frontend_selenium/Config.ini deleted file mode 100644 index da06d9ce46..0000000000 --- a/packages/playground/tests/frontend_selenium/Config.ini +++ /dev/null @@ -1,8 +0,0 @@ -[Base] -port = 5173 -net = local -[Utils] -seed = -node_seed = -address = -email = \ No newline at end of file diff --git a/packages/playground/tests/frontend_selenium/selenium.md b/packages/playground/tests/frontend_selenium/selenium.md index 0ed954b819..d76ccaedcb 100644 --- a/packages/playground/tests/frontend_selenium/selenium.md +++ b/packages/playground/tests/frontend_selenium/selenium.md @@ -28,7 +28,8 @@ There are two ways to run the Automation selenium tests: yarn lerna run build make run project=playground ``` -If the build fails due to a memory issue, please use the following command + + If the build fails due to a memory issue, please use the following command ```bash export NODE_OPTIONS="--max-old-space-size=8192" @@ -70,17 +71,17 @@ export NODE_OPTIONS="--max-old-space-size=8192" - (Not Recommended) 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). -- (Recommended) Or use Virtual Environments: - - create an environment using - `python -m venv myenv` +- (Recommended) Or use Virtual Environments: + - create an environment using + `python -m venv myenv` - activate it using - `source myenv/bin/activate` + `source myenv/bin/activate` - install packages using - `pip install -r requirements.txt`. + `pip install -r requirements.txt`. - You'll also need to install `Xvfb`, Run: - `sudo apt install xvfb`. + `sudo apt install xvfb`. - You can run selenium tests with pytest through the command line using: - `python3 -m pytest -v`. + `python3 -m pytest -v`. ### More options to run tests