diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6b79ed0..6067753 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: Java CI with Maven +name: Java CI with Maven and Docker on: pull_request: @@ -9,62 +9,97 @@ on: - main jobs: - build: - name: 'Run tests' + test: + name: Run Selenium Tests runs-on: ubuntu-latest + services: + selenium-hub: + image: selenium/hub:4.5.0-20221004 + ports: + - "4444:4444" + + chrome: + image: selenium/node-chrome:4.5.0-20221004 + shm_size: 2gb + environment: + SE_EVENT_BUS_HOST: selenium-hub + SE_EVENT_BUS_PUBLISH_PORT: 4442 + SE_EVENT_BUS_SUBSCRIBE_PORT: 4443 + steps: - - name: Git clone + - name: Checkout code uses: actions/checkout@v4 - - name: Setup JDK 17 + - name: Set up JDK 11 uses: actions/setup-java@v4 with: java-version: '11' - distribution: 'adopt' + distribution: 'temurin' cache: 'maven' - - - name: Set up Docker Compose + - name: Install Chrome run: | - sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - sudo chmod +x /usr/local/bin/docker-compose + sudo apt-get update + sudo apt-get install -y google-chrome-stable + google-chrome --version - - name: Create config.properties - run: | - echo "login=${{ secrets.login }}" > src/test/resources/test.conf - echo "password=${{ secrets.password }}" >> src/test/resources/test.conf + - name: Set up ChromeDriver + uses: nanasess/setup-chromedriver@v1 + with: + chromedriver-version: 'latest' + + - name: Cache Maven packages + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - - name: Build with Docker Compose - run: docker-compose build - - name: Start Docker Compose services - run: docker-compose up + - name: Create test.conf + run: | + echo "key=${{ secrets.login }}" > src/test/resources/test.conf + echo "token=${{ secrets.password }}" >> src/test/resources/test.conf + echo "remote.url=http://selenium-hub:4444/wd/hub" >> src/test/resources/test.conf + echo "headless=true" >> src/test/resources/test.conf + echo "browser=chrome" >> src/test/resources/test.conf + echo "headless=true" >> src/test/resources/test.conf + echo "timeout=30" >> src/test/resources/test.conf + + - name: Run Selenium Tests + run: | + export DISPLAY=:99 + Xvfb :99 -screen 0 1920x1080x16 & + mvn test -B + killall Xvfb - name: Attach screenshots if: failure() uses: actions/upload-artifact@v4 with: - name: screenshots - path: ${{ github.workspace }}/screenshots + name: screenshots + path: ${{ github.workspace }}/screenshots - name: Get Allure history uses: actions/checkout@v4 if: always() continue-on-error: true with: - ref: gh-pages - path: gh-pages + ref: gh-pages + path: gh-pages - name: Build Allure report uses: simple-elf/allure-report-action@master if: always() id: allure-report with: - allure_results: target/allure-results - gh_pages: gh-pages - allure_report: allure-report - allure_history: allure-history + allure_results: target/allure-results + gh_pages: gh-pages + allure_report: allure-report + allure_history: allure-history - name: Check Allure results run: ls -la target/allure-results @@ -73,13 +108,10 @@ jobs: if: ${{ success() || failure() }} uses: peaceiris/actions-gh-pages@v2 env: - PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PUBLISH_BRANCH: gh-pages - PUBLISH_DIR: allure-history + PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PUBLISH_BRANCH: gh-pages + PUBLISH_DIR: allure-history - name: Stop Docker Compose services if: always() - run: docker-compose down - - - + run: docker-compose down \ No newline at end of file diff --git a/.gitignore b/.gitignore index 813baa4..0494bce 100644 --- a/.gitignore +++ b/.gitignore @@ -50,4 +50,6 @@ build/ ###Properties & Conf ### .conf -.properties \ No newline at end of file +.properties + +Dockerfile diff --git a/Dockerfile b/Dockerfile index f644fb7..e9a3825 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,12 @@ FROM maven:3.9.6-eclipse-temurin-17-alpine -# Устанавливаем рабочую директорию +# Set working directory WORKDIR /app -# Копируем файлы проекта +# Copy COPY . . -# Выполняем тесты -CMD ["mvn", "test"] \ No newline at end of file + + +# Run tests +CMD ["mvn", "test", "-DsuiteXmlFile=src/test/resources/testng.xml"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 7fd7035..598c259 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,8 +5,9 @@ services: build: . image: trello-api-tests container_name: test-container + environment: + key: $key + token: $token volumes: - ./target/allure-results:/app/target/allure-results - - ./src/test/resources/test.conf:/app/src/test/resources/test.conf - - + - ./src/test/resources/config.properties:/app/src/test/resources/test.conf \ No newline at end of file diff --git a/src/test/java/automation/tests/LoginTest.java b/src/test/java/automation/tests/LoginTest.java index 76c7764..e753e1b 100644 --- a/src/test/java/automation/tests/LoginTest.java +++ b/src/test/java/automation/tests/LoginTest.java @@ -15,7 +15,6 @@ import static io.qameta.allure.SeverityLevel.CRITICAL; - @Epic("Create account") @Feature("Login") public class LoginTest extends BaseTest { diff --git a/src/test/resources/test.conf b/src/test/resources/test.conf index a9839af..eb4b49d 100644 --- a/src/test/resources/test.conf +++ b/src/test/resources/test.conf @@ -1,3 +1,2 @@ - login = "standard_user" password = "secret_sauce" diff --git a/src/test/resources/testng.xml b/src/test/resources/testng.xml new file mode 100644 index 0000000..9438b83 --- /dev/null +++ b/src/test/resources/testng.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file