7.6Example: check that users can log in
This script opens the login page and signs in with a test account. It then checks that the dashboard appears. The email address and password are team secrets named LOGIN_EMAIL and LOGIN_PASSWORD (see 7.8).
[
{"kind": "goto", "url": "https://app.example.com/login"},
{"kind": "fill", "selector": "input[name=email]",
"value": "${LOGIN_EMAIL}"},
{"kind": "fill", "selector": "input[name=password]",
"value": "${LOGIN_PASSWORD}"},
{"kind": "click", "selector": "button[type=submit]"},
{"kind": "wait_for", "selector": ".dashboard", "timeout_ms": 5000},
{"kind": "assert_text", "selector": "h1", "contains": "Welcome"}
]| Editor row | Step | What it does |
|---|---|---|
| 1 | goto | Opens the login page. |
| 2 | fill | Types the email address from the secret LOGIN_EMAIL into the email field. |
| 3 | fill | Types the password from the secret LOGIN_PASSWORD. The password never appears in the script. |
| 4 | click | Clicks the submit button. |
| 5 | wait_for | Waits up to 5 seconds for the dashboard to appear. |
| 6 | assert_text | Checks that the main heading contains Welcome. If it does not, the check is down. |
Before you start#
- Create the secrets
LOGIN_EMAILandLOGIN_PASSWORD(chapter 8). - Add
app.example.com, or*.example.com, to each secret's allowed sites (8.4). - Make sure the login page uses
https://. - Use a test account with as little access as possible, not a real person's account.
Build it in the dashboard#
- Create a browser monitor as in 7.3. Set start url to your login page.
- Add the six rows in the order shown above. Pick each step from the list on its row.
- In the two
fillrows, pick the secret from the secret… list. It inserts${LOGIN_EMAIL}or${LOGIN_PASSWORD}for you. - Leave out
timeout_mson row 5. The dashboard has no per-step timeout. - Raise timeout to 30 seconds. Six steps rarely finish in the default 10 seconds (see 7.7).
- Select create monitor →.
Create it through the API#
Save the script above as login.json. This example uses the jq tool to put the script into scriptJson as a string.
jq -n --rawfile script login.json '{
name: "login",
startUrl: "https://app.example.com/login",
intervalSeconds: 300,
timeoutMs: 30000,
locations: [],
assertions: [],
alertChannelIds: [],
scriptJson: $script
}' > monitor.json
API=https://www.obsrvly.com/api/gw/monitor/obsrvly.v1.MonitorConfigService
curl -s "$API/CreateBrowserMonitor" \
-H "Authorization: Bearer $OBSRVLY_KEY" \
-H "Content-Type: application/json" \
-d @monitor.jsonAdd your regions to locations and your alert channels to alertChannelIds (see 3.2 and chapter 10).