diff --git a/.github/workflows/test-build-windows.yml b/.github/workflows/test-build-windows.yml new file mode 100644 index 000000000000..cb263034f7c3 --- /dev/null +++ b/.github/workflows/test-build-windows.yml @@ -0,0 +1,163 @@ +# Copyright 2019-2024 Tauri Programme within The Commons Conservancy +# SPDX-License-Identifier: Apache-2.0 +# SPDX-License-Identifier: MIT +name: Build EXE for TestDriver + +env: + DEBUG: napi:* + +on: + pull_request: + +jobs: + build: + name: build windows + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + + - run: corepack enable + + - name: Install pnpm explicitly + run: | + npm install -g pnpm + pnpm --version # Verify pnpm is installed and available + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + architecture: x64 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: x86_64-pc-windows-msvc + + - name: Install dependencies (root) + run: pnpm install --frozen-lockfile --ignore-scripts + + - name: Install dependencies (examples/api) + working-directory: examples/api + run: pnpm i + + - name: Build CLI + run: pnpm run build:cli + shell: bash + + - name: Build API + run: pnpm run build:api + shell: bash + + - name: Run app in dev mode (background) + working-directory: examples/api + run: Start-Process -NoNewWindow -FilePath "cmd.exe" -ArgumentList "/c pnpm tauri dev" + shell: powershell + + - name: Build API Example App + working-directory: examples/api + run: pnpm tauri build + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: bindings-x86_64-pc-windows-msvc + path: target\release\bundle\nsis\* + if-no-files-found: error + + - name: Set environment variables + run: | + echo "GITHUB_REPOSITORY=${{ github.repository }}" >> $GITHUB_ENV + echo "GITHUB_RUN_ID=${{ github.run_id }}" >> $GITHUB_ENV + + - uses: testdriverai/action@main + with: + key: ${{ secrets.TESTDRIVER_API_KEY }} + prompt: | + 1. /run testdriver/tauri_api_install.yml + 2. /run testdriver/create_window.yml + 3. /run testdriver/dark_light_mode.yml + 4. /run testdriver/set_window_title.yml + #1. /run testdriver/minimize_window.yml + #1. /run testdriver/comm_echo.yml + #1. /run testdriver/comm_send_event_rust.yml + #1. /run testdriver/comm_spam.yml + #1. /run testdriver/comm_call_request_api.yml + #1. /run testdriver/comm_call_log_api.yml + + prerun: | + $headers = @{ + Authorization = "token ${{ secrets.GITHUB_TOKEN }}" + } + + $downloadFolder = "./download" + $artifactName = "bindings-x86_64-pc-windows-msvc" + Write-Host "Starting the artifact download process..." + + # Create the download directory if it doesn't exist + if (-not (Test-Path -Path $downloadFolder)) { + Write-Host "Creating download folder..." + mkdir $downloadFolder + } else { + Write-Host "Download folder already exists." + } + + # Fetch the artifact upload URL (no need for GITHUB_RUN_ID) + Write-Host "Fetching the artifact upload URL..." + $artifactUrl = (Invoke-RestMethod -Uri "https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts" -Headers $headers).artifacts[0].archive_download_url + + if ($artifactUrl) { + Write-Host "Artifact URL successfully fetched: $artifactUrl" + } else { + Write-Error "Failed to fetch the artifact URL." + exit 1 + } + + # Download the artifact (zipped file) + Write-Host "Starting artifact download..." + $artifactZipPath = "$env:TEMP\artifact.zip" + try { + Invoke-WebRequest -Uri $artifactUrl ` + -Headers $headers ` + -OutFile $artifactZipPath ` + -MaximumRedirection 5 + Write-Host "Artifact downloaded successfully to $artifactZipPath" + } catch { + Write-Error "Error downloading artifact: $_" + exit 1 + } + + # Unzip the artifact + $artifactUnzipPath = "$env:TEMP\artifact" + Write-Host "Unzipping the artifact to $artifactUnzipPath..." + try { + Expand-Archive -Path $artifactZipPath -DestinationPath $artifactUnzipPath -Force + Write-Host "Artifact unzipped successfully to $artifactUnzipPath" + } catch { + Write-Error "Failed to unzip the artifact: $_" + exit 1 + } + + # Find the installer or app executable + $artifactInstallerPath = Get-ChildItem -Path $artifactUnzipPath -Filter *.exe -Recurse | Select-Object -First 1 + if ($artifactInstallerPath) { + Write-Host "Executable file found: $($artifactInstallerPath.FullName)" + } else { + Write-Error "Executable file not found. Exiting." + exit 1 + } + + # Run the installer and log the result + Write-Host "Running the installer: $($artifactInstallerPath.FullName)..." + try { + Start-Process -FilePath $artifactInstallerPath.FullName + Write-Host "Installer ran successfully." + } catch { + Write-Error "Failed to run the installer: $_" + exit 1 + } + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + FORCE_COLOR: "3" diff --git a/testdriver/README.md b/testdriver/README.md new file mode 100644 index 000000000000..3e977f265179 --- /dev/null +++ b/testdriver/README.md @@ -0,0 +1,61 @@ +# Tauri API with TestDriver.ai + +Hello! I'm going to show you how to create a new [TestDriver.ai](http://TestDriver.ai) regression test and implement it into the TestDriver.ai github action, specifically for the Tauri API Validation app. + +## How it works + +In the Tauri repo there is a directory called '**testdriver**' which holds all of our created TestDriver.ai regression tests. + +Right now, the file .github/workflows/test-build-windows.yml is our main TestDrivier. workflow for building and testing the Tauri API validation application. + +TestDriver.ai github action uses this workflow to spin up an ephemeral VM, open the app, and test it by starting up a local TestDriver.ai agent and using our regression tests passed into the workflow file from the '**testdriver**' directory. (Reference testdrivers workflow docs [here](https://docs.testdriver.ai/continuous-integration/github-setup)). + +Of course, before being able to test the API example app we need to build and install the app on our VM. Which already happens in our [prerun script](https://docs.testdriver.ai/continuous-integration/prerun-scripts) in the workflow. + +In the workflow, we can see `/run` commands under the `prompt:` we use these to run our tests sequentially after the app has been built and launched ([parallel testing](https://docs.testdriver.ai/continuous-integration/parallel-testing) can also be done). + +## Creating regression tests + +After [installing TestDriver.ai](https://docs.testdriver.ai/overview/installing-via-npm) on your local machine, navigate to the root of your local Tauri repo. + +Once at the root, it may be beneficial to select your desired preferences for TestDriver.ai by using `testdriverai init` ,there you can select whether to receive desktop notifications, minimize the terminal when creating tests (this helps TestDriver.ai resolve quicker), and more. + +Then use `testdriverai testdriver/[new test name].yml` to create a new test within the '**testdriver'** directory. + +Now, TestDriver.ai should start and be awaiting a prompt. So, let's open the Tauri API validation app, and place it next to our terminal, and begin creating a test. + +If we give TestDriver.ai a prompt like '**click the Communication tab in the sidebar**', TestDriver.ai will do so, and give us something like this resulting YAML. + +``` + - prompt: click the Communication tab in the sidebar + commands: + - command: hover-text + text: Communication + description: >- + Communication tab in the sidebar of the Tauri API Validation + application + action: click + +``` + +When we give another prompt, like '**click the spam button**', TestDriver.ai will generate something like: + +``` + - prompt: Click the Spam button + commands: + - command: hover-text + text: Spam + description: >- + Spam button in the Communication section of the + Tauri API Validation application + action: click + +``` + +And then automatically append it to our previously generated YAML! + +([CLI commands](https://docs.testdriver.ai/reference/cli-commands) like `/undo` and `assert` are also important!) + +We can do `/save` to ensure our YAML is saved. Then we can run the regression test we've just created with `/run testdriver/[new test name].yml` just like how the prompts are being run in the workflow file. + +If we want to implement this test into our github action workflow, all we have to do is add the `/run testdriver/[new test name].yml` under a `prompt:` in the workflow. ([workflow doc](https://docs.testdriver.ai/continuous-integration/github-setup)) diff --git a/testdriver/comm_call_log_api.yml b/testdriver/comm_call_log_api.yml new file mode 100644 index 000000000000..18ce3018e687 --- /dev/null +++ b/testdriver/comm_call_log_api.yml @@ -0,0 +1,33 @@ +version: 4.1.58 +session: 679ed1b8a1ad2d40a789e790 +steps: + - prompt: focus tauri API Validation + commands: + - command: hover-text + text: Tauri API Validation + description: window title of the Tauri API Validation application + action: click + - prompt: click the Communication tab in the sidebar + commands: + - command: hover-text + text: Communication + description: >- + Communication tab in the sidebar of the Tauri API Validation + application + action: click + - prompt: Click the Call Log API button + commands: + - command: hover-text + text: Call Log API + description: >- + Call Log API button in the Communication section of the + Tauri API Validation application + action: click + - prompt: Wait 5 seconds + commands: + - command: wait + timeout: 5000 + - prompt: Assert that the console shows a successful response + commands: + - command: assert + expect: the console shows a response diff --git a/testdriver/comm_call_request_api.yml b/testdriver/comm_call_request_api.yml new file mode 100644 index 000000000000..42c5a0000e7e --- /dev/null +++ b/testdriver/comm_call_request_api.yml @@ -0,0 +1,33 @@ +version: 4.1.58 +session: 679ed1b8a1ad2d40a789e790 +steps: + - prompt: focus tauri API Validation + commands: + - command: hover-text + text: Tauri API Validation + description: window title of the Tauri API Validation application + action: click + - prompt: click the Communication tab in the sidebar + commands: + - command: hover-text + text: Communication + description: >- + Communication tab in the sidebar of the Tauri API Validation + application + action: click + - prompt: Click the Call Request (async) API button + commands: + - command: hover-text + text: Call Request (async) API + description: >- + Call Request (async) API button in the Communication section of the + Tauri API Validation application + action: click + - prompt: Wait 5 seconds + commands: + - command: wait + timeout: 5000 + - prompt: Assert that the console shows a successful response + commands: + - command: assert + expect: the console shows "message response" diff --git a/testdriver/comm_echo.yml b/testdriver/comm_echo.yml new file mode 100644 index 000000000000..1e879a070c47 --- /dev/null +++ b/testdriver/comm_echo.yml @@ -0,0 +1,33 @@ +version: 4.1.58 +session: 679ed1b8a1ad2d40a789e790 +steps: + - prompt: focus tauri API Validation + commands: + - command: hover-text + text: Tauri API Validation + description: window title of the Tauri API Validation application + action: click + - prompt: click the Communication tab in the sidebar + commands: + - command: hover-text + text: Communication + description: >- + Communication tab in the sidebar of the Tauri API Validation + application + action: click + - prompt: Click the Echo button + commands: + - command: hover-text + text: Echo + description: >- + Echo button in the Communication section of the + Tauri API Validation application + action: click + - prompt: Wait 5 seconds + commands: + - command: wait + timeout: 5000 + - prompt: Assert that the console shows a successful response + commands: + - command: assert + expect: the console shows a response with "Tauri JSON request!" and "1, 2, 3" diff --git a/testdriver/comm_send_event_rust.yml b/testdriver/comm_send_event_rust.yml new file mode 100644 index 000000000000..f506ed8cd14d --- /dev/null +++ b/testdriver/comm_send_event_rust.yml @@ -0,0 +1,33 @@ +version: 4.1.58 +session: 679ed1b8a1ad2d40a789e790 +steps: + - prompt: focus tauri API Validation + commands: + - command: hover-text + text: Tauri API Validation + description: window title of the Tauri API Validation application + action: click + - prompt: click the Communication tab in the sidebar + commands: + - command: hover-text + text: Communication + description: >- + Communication tab in the sidebar of the Tauri API Validation + application + action: click + - prompt: Click the Send event to Rust button + commands: + - command: hover-text + text: Send event to Rust + description: >- + Send Event to Rust button in the Communication section of the + Tauri API Validation application + action: click + - prompt: Wait 5 seconds + commands: + - command: wait + timeout: 5000 + - prompt: Assert that the console shows a successful response + commands: + - command: assert + expect: the console shows a response with an "event", "payload", and "id" diff --git a/testdriver/comm_spam.yml b/testdriver/comm_spam.yml new file mode 100644 index 000000000000..d55072689872 --- /dev/null +++ b/testdriver/comm_spam.yml @@ -0,0 +1,33 @@ +version: 4.1.58 +session: 679ed1b8a1ad2d40a789e790 +steps: + - prompt: focus tauri API Validation + commands: + - command: hover-text + text: Tauri API Validation + description: window title of the Tauri API Validation application + action: click + - prompt: click the Communication tab in the sidebar + commands: + - command: hover-text + text: Communication + description: >- + Communication tab in the sidebar of the Tauri API Validation + application + action: click + - prompt: Click the Spam button + commands: + - command: hover-text + text: Spam + description: >- + Spam button in the Communication section of the + Tauri API Validation application + action: click + - prompt: Wait 5 seconds + commands: + - command: wait + timeout: 5000 + - prompt: Assert that the console shows a successful response + commands: + - command: assert + expect: the console shows a response with value 1000 diff --git a/testdriver/create_window.yml b/testdriver/create_window.yml new file mode 100644 index 000000000000..ebc5f37394d5 --- /dev/null +++ b/testdriver/create_window.yml @@ -0,0 +1,48 @@ +version: 4.1.42 +steps: + - prompt: focus tauri API Validation + commands: + - command: hover-text + text: Tauri API Validation + description: window title of the Tauri API Validation application + action: click + - prompt: Click the Window button + commands: + - command: hover-text + text: Window + description: Window button in the Tauri API sidebar + action: click + - prompt: Type 'test' for New window label, then click create + commands: + - command: focus-application + name: Tauri API Validation + - command: hover-text + text: New window label + description: input field for new window label + action: click + - command: type + text: test + - command: hover-text + text: Create + description: button to create a new window + action: click + - prompt: assert that a new tauri app window has been created + commands: + - command: hover-text + text: Tauri App + description: window title of the Tauri application + action: hover + - command: assert + expect: the Tauri app window is visible + - prompt: >- + close the newly created Tauri App window, ensuring only one Tauri window + is open + commands: + - command: hover-text + text: Tauri App + description: title of the Tauri App window + action: click + - command: press-keys + keys: + - command + - w diff --git a/testdriver/dark_light_mode.yml b/testdriver/dark_light_mode.yml new file mode 100644 index 000000000000..5abd8d266b92 --- /dev/null +++ b/testdriver/dark_light_mode.yml @@ -0,0 +1,29 @@ +version: 4.1.58 +session: 679fdccba1ad2d40a789f609 +steps: + - prompt: focus tauri API Validation + commands: + - command: hover-text + text: Tauri API Validation + description: window title of the Tauri API Validation application + action: click + - prompt: Click the dark mode button + commands: + - command: hover-text + text: Switch to Dark mode + description: Dark mode button in the Tauri API sidebar + action: click + - prompt: Assert that the Tauri application is dark mode + commands: + - command: assert + expect: Tauri application says Switch to Light Mode + - prompt: Click the light mode button + commands: + - command: hover-text + text: Switch to Light mode + description: Light mode button in the Tauri API sidebar + action: click + - prompt: Assert that the Tauri application is light mode + commands: + - command: assert + expect: Tauri application says Switch to Dark mode diff --git a/testdriver/minimize_window.yml b/testdriver/minimize_window.yml new file mode 100644 index 000000000000..8ef4377ea842 --- /dev/null +++ b/testdriver/minimize_window.yml @@ -0,0 +1,42 @@ +version: 4.1.42 +steps: + - prompt: minimize the Tauri API app + commands: + - command: hover-text + text: Minimize + description: minimize button in the Tauri API app window + action: click + - prompt: minimize the Tauri API app + commands: + - command: hover-text + text: Tauri API + description: Tauri API app window title bar + action: click + - command: press-keys + keys: + - command + - m + - prompt: assert the tauri app is minimized + commands: + - command: assert + expect: the Tauri app is minimized + - prompt: restore the tauri app by searching for it + commands: + - command: press-keys + keys: + - command + - space + - prompt: restore the tauri app by searching for it + commands: + - command: type + text: Tauri + - prompt: restore the tauri app by searching for it + commands: + - command: hover-text + text: Tauri API + description: Tauri app in Spotlight Search results + action: click + - prompt: assert that the tauri window is visible + commands: + - command: assert + expect: the Tauri window is visible diff --git a/testdriver/set_window_title.yml b/testdriver/set_window_title.yml new file mode 100644 index 000000000000..0f6b94dc89c3 --- /dev/null +++ b/testdriver/set_window_title.yml @@ -0,0 +1,47 @@ +version: 4.1.42 +steps: + - prompt: click window in the Tauri App sidebar + commands: + - command: focus-application + name: Tauri API Validation + - command: hover-text + text: Window + description: window option in the Tauri App sidebar + action: click + - prompt: Click Set under Set Window Title + commands: + - command: focus-application + name: Tauri API Validation + - command: hover-text + text: Set + description: set button under Set Window Title in the Tauri App + action: click + - prompt: assert that the Tauri App windows title says Awesome Tauri Example! + commands: + - command: focus-application + name: Tauri API Validation + - command: assert + expect: the window title is "Awesome Tauri Example!" + - prompt: >- + In the field under Set Window Title, erase the existing test and type + Tauri API Validation and then click Set + commands: + - command: focus-application + name: Tauri API Validation + - command: hover-text + text: Awesome Tauri Example! + description: input field under Set Window Title + action: click + - command: press-keys + keys: + - command + - a + - command: press-keys + keys: + - backspace + - command: type + text: Tauri API Validation + - command: hover-text + text: Set + description: set button under Set Window Title + action: click diff --git a/testdriver/tauri_api_install.yml b/testdriver/tauri_api_install.yml new file mode 100644 index 000000000000..4518f6876347 --- /dev/null +++ b/testdriver/tauri_api_install.yml @@ -0,0 +1,39 @@ +version: 4.1.58 +session: 679ff568a1ad2d40a789f778 +steps: + - prompt: Click next in the Tauri API Setup + commands: + - command: focus-application + name: Tauri API Setup + - command: hover-text + text: Next > + description: next button in the Tauri API Setup + action: click + - prompt: Click next again in the Tauri API Setup + commands: + - command: focus-application + name: Tauri API + - command: hover-text + text: Next > + description: next button in the Tauri API Setup + action: click + - prompt: Click Next again in the Tauri API Setup + commands: + - command: focus-application + name: Tauri API + - command: hover-text + text: Next > + description: next button in the Tauri API Setup + action: click + - prompt: Click Finish in Tauri API Setup + commands: + - command: focus-application + name: Tauri API + - command: hover-text + text: Finish + description: finish button in the Tauri API Setup + action: click + - prompt: assert that the Tauri API program is open + commands: + - command: assert + expect: the Tauri API program is open