Documentation Index
Fetch the curated documentation index at: https://grafana_com_website/llms.txt
Fetch the complete documentation index at: https://grafana_com_website/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: /docs/k6/latest/javascript-api/jslib/testing/retrying-assertions/tohavetitle.md (append .md) or send Accept: text/markdown to /docs/k6/latest/javascript-api/jslib/testing/retrying-assertions/tohavetitle/. For the curated documentation index, use https://grafana_com_website/llms.txt. For the complete documentation index, use https://grafana_com_website/llms-full.txt.
toHaveTitle()
The toHaveTitle() method asserts that a page has a specific title. This is a retrying assertion that automatically waits for the page to have the expected title.
Syntax
await expect(page).toHaveTitle(expected);
await expect(page).not.toHaveTitle(expected);
await expect(page).toHaveTitle(expected, options);Parameters
| Parameter | Type | Description |
|---|---|---|
| expected | string | RegExp | The expected title |
| options | RetryConfig | Optional configuration options |
Returns
| Type | Description |
|---|---|
| Promise | A promise that resolves when the assertion passes |
Description
The toHaveTitle() method checks if a page has a specific title. It retrives the title from the page’s <title> element in the document’s <head>.
When a string is provided, it performs an exact match. When a RegExp is provided, it tests the title against the regular expression pattern.
This is a retrying assertion that will automatically re-check the page’s title until it matches the expected value or the timeout is reached.
Usage
import { browser } from 'k6/browser';
import { expect } from 'https://jslib.k6.io/k6-testing/0.6.1/index.js';
export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
}
};
export default async function () {
const page = await browser.newPage();
// Navigate and check exact title match
await page.goto('https://quickpizza.grafana.com/');
await expect(page).toHaveTitle('QuickPizza');
// Check title with regex pattern
await expect(page).toHaveTitle(/QuickPizza/);
await expect(page).toHaveTitle(/^Quick/);
}Was this page helpful?
Related resources from Grafana Labs

