Skip to content

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).

login.json
json
[
  {"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 rowStepWhat it does
1gotoOpens the login page.
2fillTypes the email address from the secret LOGIN_EMAIL into the email field.
3fillTypes the password from the secret LOGIN_PASSWORD. The password never appears in the script.
4clickClicks the submit button.
5wait_forWaits up to 5 seconds for the dashboard to appear.
6assert_textChecks that the main heading contains Welcome. If it does not, the check is down.

Before you start#

  • Create the secrets LOGIN_EMAIL and LOGIN_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#

  1. Create a browser monitor as in 7.3. Set start url to your login page.
  2. Add the six rows in the order shown above. Pick each step from the list on its row.
  3. In the two fill rows, pick the secret from the secret… list. It inserts ${LOGIN_EMAIL} or ${LOGIN_PASSWORD} for you.
  4. Leave out timeout_ms on row 5. The dashboard has no per-step timeout.
  5. Raise timeout to 30 seconds. Six steps rarely finish in the default 10 seconds (see 7.7).
  6. 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.

Create the login monitor
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.json

Add your regions to locations and your alert channels to alertChannelIds (see 3.2 and chapter 10).

Last updated