diff --git a/.github/first_test.py b/.github/first_test.py index e473bc00..95eadc83 100644 --- a/.github/first_test.py +++ b/.github/first_test.py @@ -1,18 +1,40 @@ + +import sys + from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time +import pyautogui +import os + + + + try: # Set up the webdriver to connect to the remote Selenium server options = webdriver.ChromeOptions() + + + # Configure Chrome preferences to allow downloads + prefs = { + "download.default_directory": "/home/seluser/Downloads", + "download.prompt_for_download": False, + "safebrowsing.enabled": True, + "safebrowsing.disable_download_protection": True + } + options.add_argument('--headless') # Enable headless mode + options.add_argument('--disable-gpu') # Disable GPU acceleration in headless mode + options.add_experimental_option("prefs", prefs) options.add_argument('--no-sandbox') options.add_argument('--disable-dev-shm-usage') - # Disable headless mode to show the Chrome UI # options.add_argument('--headless=false') + options.add_argument("--allow-running-insecure-content") # Allow insecure content + options.add_argument("--unsafely-treat-insecure-origin-as-secure=http://localhost:4000") # Remote WebDriver URL (provided by the selenium/standalone-chrome service) driver = webdriver.Remote( command_executor='http://localhost:4444/wd/hub', @@ -20,7 +42,9 @@ ) # Open the browser and go to the URL - driver.get('http://IP:4000') + + driver.get('http://localhost:4000') + # time.sleep(120) @@ -38,16 +62,55 @@ ) # Wait for the "Open" menu item to be clickable and click it - code_menu_item = WebDriverWait(driver, 20).until( + open_menu_item = WebDriverWait(driver, 20).until( EC.element_to_be_clickable((By.XPATH, "//ul[@role='menu' and @aria-label='File']//li[text()='Open']")) ) - code_menu_item.click() + open_menu_item.click() + + # Wait for the file input element to be present in the dialog + file_input = WebDriverWait(driver, 20).until( + EC.presence_of_element_located((By.XPATH, "//input[@type='file']")) + ) + + # Use pyautogui to handle the file upload dialog + time.sleep(2) # Wait for the file dialog to appear + pyautogui.write('/home/seluser/Demo_Autoparking_ROS2_1.vc3') + pyautogui.press('enter') + + time.sleep(2) + + # Wait for the "File" button to be clickable and click it + basic_button = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'menu-button') and .//span[text()='File']]")) + ) + basic_button.click() + + # Wait for the dropdown menu to be visible + dropdown_menu = WebDriverWait(driver, 10).until( + EC.visibility_of_element_located((By.XPATH, "//ul[@role='menu' and @aria-label='File']")) + ) + + # Wait for the "Open" menu item to be clickable and click it + + open_menu_item = WebDriverWait(driver, 20).until( + EC.element_to_be_clickable((By.XPATH, "//ul[@role='menu' and @aria-label='File']//li[text()='Build and Download']")) + ) + open_menu_item.click() + - time.sleep(20) + + time.sleep(20) + + download_directory = "/home/seluser/Downloads" + zip_files = [f for f in os.listdir(download_directory) if f.endswith('.zip')] + if zip_files: + print("Test Passed: .zip file downloaded successfully.") + sys.exit(0) # Exit with code 0 for success + else: + print("Test Failed: No .zip file found.") + sys.exit(1) # Exit with code 1 for failure - # Capture a screenshot - driver.get_screenshot_as_file('screenshot.png') finally: # Close the browser diff --git a/.github/workflows/CI_Workflow.yml b/.github/workflows/CI_Workflow.yml index 3ff45e6a..65b49094 100644 --- a/.github/workflows/CI_Workflow.yml +++ b/.github/workflows/CI_Workflow.yml @@ -32,11 +32,10 @@ jobs: restore-keys: | ${{ runner.os }}-node- - - name: Set up Python uses: actions/setup-python@v5 with: - python-version: '3.x' + python-version: '3.x' - name: Create virtual environment run: python -m venv .venv @@ -53,7 +52,7 @@ jobs: run: cp backend/.env.template backend/.env - name: Generate static files - run: python backend/manage.py collectstatic + run: python backend/manage.py collectstatic --noinput - name: Save venv uses: actions/upload-artifact@v4 @@ -61,9 +60,47 @@ jobs: name: venv path: .venv - frontend-tests: + test-1: + runs-on: ubuntu-latest + needs: setup + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Restore Node modules cache + id: restore-node-modules + uses: actions/cache@v4 + with: + path: frontend/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('**/frontend/package-lock.json') }} + + - name: Install frontend dependencies + if: steps.restore-node-modules.outputs.cache-hit != 'true' + working-directory: frontend + run: npm ci --legacy-peer-deps + + - name: Permissions for node_modules + run: chmod -R +x frontend/node_modules/.bin + + - name: Verify node_modules restoration + run: | + ls -la frontend/node_modules + ls -la frontend/node_modules/.bin + + - name: Run frontend test + run: npm test -- --watchAll=false + working-directory: frontend + + tests-2: runs-on: ubuntu-latest needs: setup + + services: + selenium: + image: selenium/standalone-chrome + ports: + - 4444:4444 + steps: - name: Checkout code uses: actions/checkout@v4 @@ -90,4 +127,101 @@ jobs: - name: Run frontend test run: npm test -- --watchAll=false - working-directory: frontend \ No newline at end of file + working-directory: frontend + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Restore backend artifacts + uses: actions/download-artifact@v4 + with: + name: venv + path: .venv + + - name: Activate virtual environment + run: source .venv/bin/activate + + - name: Install Selenium dependencies + run: | + python -m pip install --upgrade pip + pip install selenium pyautogui + + - name: Install Xvfb + run: sudo apt-get install -y xvfb + + - name: Add .env file + run: cp backend/.env.template backend/.env + + - name: Verify Python path + run: | + which python + python --version + + - name: Reinstall dependencies (ensure Django is installed) + run: pip install -r backend/requirements.txt + + - name: Check if Django is installed + run: python3 -m django --version + + - name: Generate static files + run: python3 backend/manage.py collectstatic --noinput + + - name: Start backend server + run: python3 manage.py runserver 8080 & + working-directory: backend + + + + - name: Start frontend server + run: npm start > frontend_server.log & + working-directory: frontend + + - name: Wait for servers to start + run: sleep 30 + + - name: Start backend server + run: python backend/manage.py runserver 8080 > backend_server.log & + working-directory: backend + + - name: Wait for servers to start + run: sleep 15 + + - name: Upload server logs + uses: actions/upload-artifact@v4 + with: + name: server-logs + path: | + frontend/frontend_server.log + backend/backend_server.log + + - name: Start Xvfb + run: | + Xvfb :99 -screen 0 1280x1024x16 & + echo "DISPLAY=:99" >> $GITHUB_ENV + + - name: Check if server is running on port 8080 + run: curl -I http://127.0.0.1:8080 + + - name: Check if server is running on port 4000 + run: curl -I http://localhost:4000 + + - name: Run Selenium tests + run: xvfb-run -a python .github/first_test.py > selenium_test.log + + - name: Upload Selenium logs + uses: actions/upload-artifact@v4 + with: + name: selenium-logs + path: selenium_test.log + + + - name: Upload Selenium logs 1 + uses: actions/upload-artifact@v4 + with: + name: selenium-logs + path: | + frontend/chromedriver.log + frontend/geckodriver.log +