-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from grafana/browser-tests
Browser tests
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Browser Workflow | ||
on: [push] | ||
|
||
jobs: | ||
k6_browser_test: | ||
name: k6 browser test | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install k6 in Ubuntu | ||
run: | | ||
sudo gpg -k | ||
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69 | ||
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list | ||
sudo apt-get update | ||
sudo apt-get install k6 | ||
# Install Chrome (or chromium) when using ACT, as the default ACT image does not include it. | ||
# Note that running the browser in a container like Snap or Flatpak is not supported. | ||
- name: Install chrome | ||
if: ${{ env.ACT }} | ||
run: | | ||
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add - | ||
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' | ||
sudo apt update && sudo apt install -y google-chrome-stable | ||
# If you plan to run ACT on Apple Silicon, be aware that Chrome has not yet released an arm64 version. In this case, you have to: | ||
# 1. Enable the option on Docker Desktop: `Use Rosetta for x86/amd64 emulation on Apple Silicon` | ||
# 2. Run ACT using the `--container-architecture linux/amd64` flag. For example: | ||
# act -W .github/workflows/browser.yml --container-architecture linux/amd64 | ||
|
||
- name: Run browser test | ||
run: | | ||
export K6_BROWSER_HEADLESS=true | ||
export K6_BROWSER_ARGS='no-sandbox' | ||
if [ "$ACT" = "true" ]; then | ||
export K6_BROWSER_EXECUTABLE_PATH=/usr/bin/google-chrome | ||
fi | ||
k6 run browser/script.js | ||
env: | ||
ACT: ${{ env.ACT }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { browser } from "k6/experimental/browser"; | ||
import { check } from "k6"; | ||
|
||
export const options = { | ||
scenarios: { | ||
ui: { | ||
executor: "shared-iterations", | ||
options: { | ||
browser: { | ||
type: "chromium", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default async function () { | ||
const page = browser.newPage(); | ||
|
||
try { | ||
await page.goto('https://test.k6.io/'); | ||
check(page, { | ||
header: | ||
page.locator("title").textContent() == | ||
"Demo website for load testing", | ||
}); | ||
|
||
} finally { | ||
page.close(); | ||
} | ||
} |