From e0f553c15a12f805123a820988012f0de22b5132 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Mon, 13 Jan 2025 19:06:48 +0000 Subject: [PATCH] Add tests via TestDriverAI (#1957) (#2005) * initial Commit * update prerun * tweak the prompt * update the test * finetune prompt * change the prompt * minor change to retry test * add debug --------- # Description Please provide a summary of the changes, including relevant motivation and context. Closes #(issue_number) ## Checklist - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] My changes generate no new warnings - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) --------- Signed-off-by: GitHub Action Signed-off-by: dependabot[bot] Signed-off-by: Ludovic Ortega Co-authored-by: Tarun Kumar S Co-authored-by: Ian Jennings Co-authored-by: Corbinian Grimm <23664150+pixma140@users.noreply.github.com> Co-authored-by: albanobattistella <34811668+albanobattistella@users.noreply.github.com> Co-authored-by: Eric <71648843+sbplat@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: GitHub Action Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] Co-authored-by: Manuel Mora Gordillo Co-authored-by: Manu Co-authored-by: Ludy Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Florian Fish Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Dimitrios Kaitantzidis Co-authored-by: Rania Amina Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Ludovic Ortega Co-authored-by: Philip H. <47042125+pheiduck@users.noreply.github.com> Co-authored-by: Saud Fatayerji Co-authored-by: MaratheHarshad <97970262+MaratheHarshad@users.noreply.github.com> Co-authored-by: Harshad Marathe Co-authored-by: ninjat Co-authored-by: Peter Dave Hello Co-authored-by: Rafael Encinas Co-authored-by: Renan <82916964+thisisrenan@users.noreply.github.com> Co-authored-by: leo-jmateo <128976497+leo-jmateo@users.noreply.github.com> Co-authored-by: S. Neuhaus Co-authored-by: Dimitris Kaitantzidis <44621809+DimK10@users.noreply.github.com> --- .github/workflows/testdriver.yml | 154 ++++++++++++++++++ .../software/SPDF/EE/EEAppConfig.java | 2 +- .../api/security/WatermarkController.java | 1 + testdriver/test.yml | 140 ++++++++++++++++ 4 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/testdriver.yml create mode 100644 testdriver/test.yml diff --git a/.github/workflows/testdriver.yml b/.github/workflows/testdriver.yml new file mode 100644 index 00000000..55600f0c --- /dev/null +++ b/.github/workflows/testdriver.yml @@ -0,0 +1,154 @@ +name: UI test with TestDriverAI + +on: + push: + branches: ["master", "UITest", "testdriver"] + +permissions: + contents: read + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Harden Runner + uses: step-security/harden-runner@c95a14d0e5bab51a9f56296a4eb0e416910cd350 # v2.10.3 + with: + egress-policy: audit + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Build with Gradle + run: ./gradlew clean build + env: + DOCKER_ENABLE_SECURITY: false + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0 + + - name: Get version number + id: versionNumber + run: | + VERSION=$(grep "^version =" build.gradle | awk -F'"' '{print $2}') + echo "versionNumber=$VERSION" >> $GITHUB_OUTPUT + + - name: Login to Docker Hub + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_API }} + + - name: Build and push test image + uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/test:test-${{ github.sha }} + build-args: VERSION_TAG=${{ steps.versionNumber.outputs.versionNumber }} + platforms: linux/amd64 + + - name: Set up SSH + run: | + mkdir -p ~/.ssh/ + echo "${{ secrets.VPS_SSH_KEY }}" > ../private.key + sudo chmod 600 ../private.key + + - name: Deploy to VPS + run: | + cat > docker-compose.yml << EOF + version: '3.3' + services: + stirling-pdf: + container_name: stirling-pdf-test-${{ github.sha }} + image: ${{ secrets.DOCKER_HUB_USERNAME }}/test:test-${{ github.sha }} + ports: + - "1337:8080" + volumes: + - /stirling/test-${{ github.sha }}/data:/usr/share/tessdata:rw + - /stirling/test-${{ github.sha }}/config:/configs:rw + - /stirling/test-${{ github.sha }}/logs:/logs:rw + environment: + DOCKER_ENABLE_SECURITY: "false" + SECURITY_ENABLELOGIN: "false" + SYSTEM_DEFAULTLOCALE: en-GB + UI_APPNAME: "Stirling-PDF Test" + UI_HOMEDESCRIPTION: "Test Deployment" + UI_APPNAMENAVBAR: "Test" + SYSTEM_MAXFILESIZE: "100" + METRICS_ENABLED: "true" + SYSTEM_GOOGLEVISIBILITY: "false" + SYSTEM_ENABLEANALYTICS: "false" + restart: on-failure:5 + EOF + + scp -i ../private.key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null docker-compose.yml ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }}:/tmp/docker-compose.yml + + ssh -i ../private.key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }} << EOF + mkdir -p /stirling/test-${{ github.sha }}/{data,config,logs} + mv /tmp/docker-compose.yml /stirling/test-${{ github.sha }}/docker-compose.yml + cd /stirling/test-${{ github.sha }} + docker-compose pull + docker-compose up -d + EOF + + test: + needs: deploy + runs-on: ubuntu-latest + + steps: + - name: Harden Runner + uses: step-security/harden-runner@c95a14d0e5bab51a9f56296a4eb0e416910cd350 # v2.10.3 + with: + egress-policy: audit + + - uses: actions/checkout@v4 + + - name: Run TestDriver.ai + uses: testdriverai/action@47e87c5d50beeeb3da624b2d9b5c1391269d6d22 #1.0.0 + with: + key: ${{secrets.TESTDRIVER_API_KEY}} + prerun: | + npm install + npm run build + npm install dashcam-chrome --save + Start-Process "C:/Program Files/Google/Chrome/Application/chrome.exe" -ArgumentList "--start-maximized", "--load-extension=$(pwd)/node_modules/dashcam-chrome/build", "http://${{ secrets.VPS_HOST }}:1337" + Start-Sleep -Seconds 20 + prompt: | + 1. /run testdriver/test.yml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + FORCE_COLOR: "3" + + cleanup: + needs: [deploy, test] + runs-on: ubuntu-latest + if: always() + + steps: + - name: Harden Runner + uses: step-security/harden-runner@c95a14d0e5bab51a9f56296a4eb0e416910cd350 # v2.10.3 + with: + egress-policy: audit + + - name: Set up SSH + run: | + mkdir -p ~/.ssh/ + echo "${{ secrets.VPS_SSH_KEY }}" > ../private.key + sudo chmod 600 ../private.key + + - name: Cleanup deployment + run: | + ssh -i ../private.key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }} << EOF + cd /stirling/test-${{ github.sha }} + docker-compose down + cd /stirling + rm -rf test-${{ github.sha }} + EOF diff --git a/src/main/java/stirling/software/SPDF/EE/EEAppConfig.java b/src/main/java/stirling/software/SPDF/EE/EEAppConfig.java index 4648c033..ab504b90 100644 --- a/src/main/java/stirling/software/SPDF/EE/EEAppConfig.java +++ b/src/main/java/stirling/software/SPDF/EE/EEAppConfig.java @@ -25,7 +25,7 @@ public class EEAppConfig { @Bean(name = "runningEE") public boolean runningEnterpriseEdition() { - return licenseKeyChecker.getEnterpriseEnabledResult(); + return licenseKeyChecker.getEnterpriseEnabledResult(); } @Bean(name = "SSOAutoLogin") diff --git a/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java b/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java index 6bf0f96b..3e1be815 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/security/WatermarkController.java @@ -214,6 +214,7 @@ public class WatermarkController { + Math.abs(watermarkHeight * Math.cos(radians))); // Calculating the number of rows and columns. + int watermarkRows = (int) (pageHeight / newWatermarkHeight + 1); int watermarkCols = (int) (pageWidth / newWatermarkWidth + 1); diff --git a/testdriver/test.yml b/testdriver/test.yml new file mode 100644 index 00000000..101abc11 --- /dev/null +++ b/testdriver/test.yml @@ -0,0 +1,140 @@ +version: 4.0.44 +steps: + - prompt: open chrome + commands: + - command: focus-application + name: Google Chrome + - prompt: click on view PDF + commands: + - command: focus-application + name: Google Chrome + - command: hover-text + text: View PDF + description: button to view PDF + action: click + - prompt: click on view PDF + commands: + - command: wait + timeout: 5000 + - command: assert + expect: a pdf is open + - prompt: go back to the previous page + commands: + - command: focus-application + name: Google Chrome + - command: press-keys + keys: + - alt + - left + - prompt: go back to the previous page + commands: + - command: assert + expect: it is in homepage + - prompt: >- + click on sun icon in the header section and make sure the theme of the + website changes, if it does then change it back by clicking on the moon + icon at the exact same place + commands: + - command: focus-application + name: Google Chrome + - command: hover-image + description: sun icon in the header section + action: click + - command: assert + expect: the theme of the website has changed + - command: hover-image + description: moon icon in the header section + action: click + - prompt: >- + click on search icon in the header section and search for "rotate", click + on it in the drop down, you will be taken to the rotate pdf page, if so + then go back to the homepage + commands: + - command: focus-application + name: Google Chrome + - command: hover-image + description: search icon in the header section + action: click + - command: type + text: rotate + - command: wait + timeout: 2000 + - command: hover-text + text: Rotate + description: dropdown option for rotate + action: click + - command: wait + timeout: 5000 + - command: assert + expect: the page title is "Rotate PDF" + - command: press-keys + keys: + - alt + - left + - prompt: >- + click on search bar and search for "rotate", click on it in the drop down, + you will be taken to the rotate pdf page, if so then go back to the + homepage + commands: + - command: focus-application + name: Google Chrome + - command: hover-text + text: Search for features... + description: search bar + action: click + - command: type + text: rotate + - command: wait + timeout: 2000 + - command: hover-text + text: Rotate + description: dropdown option for rotate + action: click + - command: wait + timeout: 5000 + - command: assert + expect: the page title is "Rotate PDF" + - command: press-keys + keys: + - alt + - left + - command: wait + timeout: 2000 + - prompt: >- + click on Tools button in the header section and Check if the background of + the merge button is highlighted when hovered over, similarly hover over a + few other buttons and check for the background of the button is highlighted + when hovered over + commands: + - command: focus-application + name: Google Chrome + - command: hover-text + text: Tools + description: Tools button in the header section + action: click + - command: assert + expect: the Tools dropdown is open + - command: hover-text + text: Merge + description: Merge button + action: hover + - command: assert + expect: the background of the Merge button is highlighted + - command: hover-text + text: PDF to Image + description: PDF to Image button + action: hover + - command: assert + expect: the background of the PDF to Image button is highlighted + - command: hover-text + text: PDF to CSV + description: PDF to CSV button + action: hover + - command: assert + expect: the background of the PDF to CSV button is highlighted + - command: hover-text + text: Sign + description: Sign button + action: hover + - command: assert + expect: the background of the Sign button is highlighted