Skip to navigation

goTo

The goTo action navigates the browser to a specified URL. This is typically used to start a test at a specific page or navigate between pages during a test.

You can specify the target URL directly as a string, or use an object for more options:

  • String Shorthand: Provide the URL directly as the value for the goTo key. Use an absolute URL, a path that starts with one /, or a value that starts with a variable, such as $BASE_URL/docs. Doc Detective joins a path to the global origin from the configuration.
  • Object Format: Use an object with the following properties:
    • url: (Required) The URL to navigate to, in the same three forms.
    • origin: (Optional) Protocol and domain prepended to url when url is a path. Overrides the global origin if set.
    • params: (Optional) Query parameters to append to the resolved URL. Merged with config-level originParams.
    • surface: (Optional) The browser (session, window, or tab) to navigate. Omit to navigate the active tab. Naming a browser that isn’t open yet opens it. To open a browser with explicit launch options (headless, window size, viewport) before navigating, use startSurface.
    • newTab / newWindow: (Optional) Open the URL in a new tab or window instead of navigating the current one. goTo is the only action that opens tabs and windows.

For comprehensive options, see the goTo reference.

Examples

The docs tests run the two full-URL examples below and the ID, class, or attribute example under Wait conditions. The other examples on this page are illustration-only. The relative-path examples depend on the current page or a configured origin.

{
"tests": [
{
"steps": [
{
"description": "Navigate to example.com.",
"goTo": "https://example.com"
}
]
}
]
}

Assumes a global origin, such as https://example.com, is set in the configuration. Without an origin, the step fails.

{
"tests": [
{
"steps": [
{
"description": "Navigate to the /about path.",
"goTo": "/about"
}
]
}
]
}
{
"tests": [
{
"steps": [
{
"description": "Navigate to example.com using object format.",
"goTo": {
"url": "https://example.com"
}
}
]
}
]
}
{
"tests": [
{
"steps": [
{
"description": "Navigate to Google search using a specific origin.",
"goTo": {
"url": "/search",
"origin": "https://www.google.com"
}
}
]
}
]
}

Query parameters

You can append query parameters to a URL using the params option. This is useful for authentication tokens or tracking parameters.

  • Step-level params: An object specifying query parameters to append to the URL. Applies to all URLs, both relative and absolute. Values support environment variable substitution with $VAR syntax.
  • Config-level originParams: Default query parameters in your configuration file that apply to relative URLs resolved against origin. Step-level params merge on top, with step keys taking precedence on collision.

When your URL contains a fragment such as /page#section, query parameters are inserted before the fragment, giving /page?token=value#section.

Doc Detective embeds params and originParams values in request URLs. A value you write directly in these fields appears in test results, logs, and reports. To keep a secret out of output, reference an environment variable, such as "token": "$API_TOKEN". The request uses the real value, and output shows ***API_TOKEN***. See Keep secrets out of logs, reports, and captures.

Append query parameters to a URL

Append a testing token to a dashboard path using step-level params.

{
"tests": [
{
"steps": [
{
"description": "Navigate to dashboard with testing token.",
"goTo": {
"url": "/dashboard",
"origin": "https://my-app.com",
"params": {
"__clerk_testing_token": "$CLERK_TESTING_TOKEN"
}
}
}
]
}
]
}

Use config-level default parameters

Set originParams in your configuration file to avoid repeating parameters on every step. For example, when testing a Clerk-protected application, set the testing token once:

Configuration file:

{
"origin": "https://my-app.com",
"originParams": {
"__clerk_testing_token": "$CLERK_TESTING_TOKEN"
}
}

Test specification:

{
"tests": [
{
"steps": [
{
"description": "Navigate to dashboard (testing token applied automatically).",
"goTo": "/dashboard"
}
]
}
]
}

Tabs, windows, and browsers

goTo is the only action that opens new tabs, windows, and browsers. Name what you open, then any later step can act in it with a surface reference.

  • newTab: Open the URL in a new tab of the target window and focus it. true opens an anonymous tab; a string (or { "name": … }) names the tab. false disables.
  • newWindow: Open the URL in a new window and focus it. true, a name string, or { "name": …, "tab": … }, where tab names the window’s first tab. false disables.
  • newTab and newWindow are mutually exclusive on one step.
  • surface: Without an opener, this selects the browser, window, or tab to navigate. It opens the browser if it isn’t running yet. With newTab, it selects the window the tab opens in.

Open a second browser

Open a second, named browser session for the administrator account, then select a browser by its bare engine keyword.

{
"tests": [
{
"steps": [
{
"description": "Open a second, named browser session for the administrator account.",
"goTo": {
"url": "https://my-app.com/admin",
"surface": { "browser": "firefox", "name": "admin" }
}
},
{
"description": "A bare engine keyword opens (or selects) a browser of that engine.",
"goTo": { "url": "https://my-app.com", "surface": "chrome" }
}
]
}
]
}

Open a named tab, then act in it

Open the checkout in a named tab, then target that tab by name from a later step.

{
"tests": [
{
"steps": [
{
"description": "Open the checkout in a new tab named 'cart'.",
"goTo": {
"url": "https://my-app.com/checkout",
"newTab": "cart"
}
},
{
"description": "Click in the cart tab by name.",
"click": {
"elementText": "Place order",
"surface": { "browser": "chrome", "tab": "cart" }
}
}
]
}
]
}

Open a named window with a named first tab

Open the administrator console in its own window and name its first tab.

{
"tests": [
{
"steps": [
{
"description": "Open the administrator console in its own window.",
"goTo": {
"url": "https://my-app.com/admin",
"newWindow": { "name": "admin", "tab": "overview" }
}
}
]
}
]
}

Open an anonymous tab or window

Set newTab or newWindow to true to open and focus a new tab or window without naming it. Later steps then act on it as the active surface. Name it instead when a later step needs to select it by name.

{
"tests": [
{
"steps": [
{
"description": "Open a page in a new, unnamed tab.",
"goTo": {
"url": "https://my-app.com/preview",
"newTab": true
}
}
]
}
]
}

Navigate an already-open window by naming it in surface.

{
"tests": [
{
"steps": [
{
"description": "Navigate the admin window to the orders page.",
"goTo": {
"url": "https://my-app.com/orders",
"surface": { "browser": "chrome", "window": "admin" }
}
}
]
}
]
}

See Test across multiple tabs, windows, and browsers for the full selector grammar. It covers names, indexes, -1 for newest, and title and URL criteria. It also covers addressing tabs a page opens itself, and driving multiple browsers at once.

Wait conditions

The goTo action supports advanced waiting conditions after navigation to ensure pages are fully loaded and ready before the next step runs.

When using the object format, you can configure:

  • timeout: (Optional) Maximum time in milliseconds to wait for all conditions to be met. If exceeded, the goTo action fails (default: 30000).
  • waitUntil: (Optional) Object specifying conditions to wait for:
    • networkIdleTime: (Optional) Wait for network activity to be idle, meaning no new requests, for this duration in milliseconds. This check always runs and you can’t skip it. Set it to 0 to treat the page as network-idle as soon as the first check completes, rather than waiting for a quiet period. Defaults to 500.
    • domIdleTime: (Optional) Wait for DOM mutations to stop for this duration in milliseconds. This check always runs; you can’t skip it. Set it to 0 to treat the DOM as stable as soon as the first check completes rather than waiting for a quiet period (default: 1000).
  • find: (Optional) Wait for a specific element to be present in the DOM. At least one element-finding field must be specified.
    • selector: (Optional) The CSS selector or XPath selector of the element to wait for.
    • elementText: (Optional) Display text of the element to wait for. Doc Detective matches this against the element’s full visible text with whitespace normalized, so text that a framework splits across several nodes still matches. To match a substring with a regular expression instead of the whole text, wrap the value in slashes (/pattern/). See How text matching works.
    • elementId: (Optional) ID attribute of the element. Supports exact match or a regex pattern using /pattern/ syntax.
    • elementTestId: (Optional) data-testid attribute of the element. Supports exact match or a regex pattern using /pattern/ syntax.
    • elementClass: (Optional) Class, or array of classes, the element must have. Each class supports exact match or a /pattern/ regex. The element must have all specified classes.
    • elementAttribute: (Optional) Object of attribute key-value pairs the element must have. Values can be strings (supporting /pattern/ regex), numbers, or booleans. Boolean true matches attribute presence, and false matches absence.
    • elementAria: (Optional) Computed accessible name of the element per the ARIA specification. Supports exact match or a /pattern/ regex.

Wait for network idle

Navigate to a page and wait for network activity to settle.

{
"tests": [
{
"steps": [
{
"description": "Navigate and wait for network idle.",
"goTo": {
"url": "https://www.example.com",
"waitUntil": {
"networkIdleTime": 500
}
}
}
]
}
]
}

Wait for a specific element

Navigate to a dashboard and wait for a specific element to appear.

{
"tests": [
{
"steps": [
{
"description": "Navigate to dashboard and wait for it to load.",
"goTo": {
"url": "https://www.example.com/dashboard",
"waitUntil": {
"find": {
"selector": "[data-testid='dashboard-loaded']"
}
}
}
}
]
}
]
}

Wait for element with text

Wait for an element with specific text to appear.

{
"tests": [
{
"steps": [
{
"description": "Navigate to status page and wait for operational message.",
"goTo": {
"url": "https://www.example.com/status",
"waitUntil": {
"find": {
"elementText": "System operational"
}
}
}
}
]
}
]
}

Combine multiple wait conditions

Use multiple wait conditions together with a custom timeout.

{
"tests": [
{
"steps": [
{
"description": "Navigate to app with comprehensive wait conditions.",
"goTo": {
"url": "https://www.example.com/app",
"timeout": 60000,
"waitUntil": {
"networkIdleTime": 500,
"domIdleTime": 1000,
"find": {
"selector": ".main-content",
"elementText": "Dashboard"
}
}
}
}
]
}
]
}

Wait for an element by ID, class, or attribute

waitUntil.find accepts the same element-finding fields as find: selector, elementText, elementId, elementTestId, elementClass, elementAttribute, and elementAria. Each matches an exact value or a /regex/ pattern. Set several fields to wait for an element that matches all of them.

{
"tests": [
{
"steps": [
{
"description": "Navigate and wait for a button identified by its test ID.",
"goTo": {
"url": "https://www.example.com/dashboard",
"waitUntil": {
"find": {
"elementTestId": "login-form-submit"
}
}
}
}
]
}
]
}

Treat the page as idle immediately

Set networkIdleTime or domIdleTime to 0 to treat the page as idle once the first check completes, rather than waiting for a quiet period. Both checks always run, and you can’t skip them.

{
"tests": [
{
"steps": [
{
"description": "Navigate without waiting for a network quiet period.",
"goTo": {
"url": "https://www.example.com",
"waitUntil": {
"networkIdleTime": 0
}
}
}
]
}
]
}