{
  "doc": {
    "id": "api/commands/url",
    "title": "cy.url()",
    "description": "Get the current URL of the page that is currently active in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/url.md",
    "version": "efcbe8c28d49ff52285a47072f279cb65f20c0fc",
    "updated_at": "2026-09-09T13:41:20.773Z",
    "headings": [
      {
        "id": "api/commands/url#url",
        "text": "url",
        "level": 1
      },
      {
        "id": "api/commands/url#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/url#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/url#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/url#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/url#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/url#no-args",
        "text": "No Args",
        "level": 3
      },
      {
        "id": "api/commands/url#assert-the-url-is-http-localhost-8000-users-1-edit",
        "text": "Assert the URL is http://localhost:8000/users/1/edit",
        "level": 4
      },
      {
        "id": "api/commands/url#decode-option",
        "text": "decode option",
        "level": 3
      },
      {
        "id": "api/commands/url#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/url#href-shorthand",
        "text": "Href Shorthand",
        "level": 3
      },
      {
        "id": "api/commands/url#url-is-an-alias-for-cy-location-href",
        "text": "URL is an alias for cy.location('href')",
        "level": 4
      },
      {
        "id": "api/commands/url#differences",
        "text": "Differences",
        "level": 3
      },
      {
        "id": "api/commands/url#url-versus-href",
        "text": "URL versus href",
        "level": 4
      },
      {
        "id": "api/commands/url#hardcoded-versus-using-the-configuration-object",
        "text": "Hardcoded versus using the configuration object",
        "level": 4
      },
      {
        "id": "api/commands/url#assert-that-the-url-contains-users-new",
        "text": "Assert that the url contains \"#users/new\"",
        "level": 4
      },
      {
        "id": "api/commands/url#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/url#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/url#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/url#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/url#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/url#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/url#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/url#syntax",
      "doc_id": "api/commands/url",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\ncy.url()\ncy.url(options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.url() // Yields the current URL as a string\n```\n\n### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.url()`.\n\n**cy.url( _options_ )**\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `decode` | `false` | Decode URL |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.url()` to resolve before [timing out](#Timeouts) |\n\n### Yields\n\n*   `cy.url()` yields the current URL as a string.\n*   `cy.url()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 153
    },
    {
      "id": "api/commands/url#arguments",
      "doc_id": "api/commands/url",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `cy.url()`.\n\n**cy.url( _options_ )**\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `decode` | `false` | Decode URL |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.url()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 93
    },
    {
      "id": "api/commands/url#examples",
      "doc_id": "api/commands/url",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### No Args\n\n#### Assert the URL is `http://localhost:8000/users/1/edit`\n\n```\n// clicking the anchor causes the browser to follow the link\ncy.get('#user-edit a').click()\ncy.url().should('include', '/users/1/edit') // => true\ncy.url().should('eq', 'http://localhost:8000/users/1/edit') // => true\n```\n\n### `decode` option\n\nWhen the URL contains non-ASCII characters, use the `decode` option.\n\n```\n// For the curious, '사랑' means 'love' in Korean.\ncy.url({ decode: true }).should('contain', '사랑')\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 87
    },
    {
      "id": "api/commands/url#no-args",
      "doc_id": "api/commands/url",
      "heading": "No Args",
      "heading_level": 3,
      "content_markdown": "### No Args\n\n#### Assert the URL is `http://localhost:8000/users/1/edit`\n\n```\n// clicking the anchor causes the browser to follow the link\ncy.get('#user-edit a').click()\ncy.url().should('include', '/users/1/edit') // => true\ncy.url().should('eq', 'http://localhost:8000/users/1/edit') // => true\n```\n",
      "section": "api",
      "anchors": [
        "no-args"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 45
    },
    {
      "id": "api/commands/url#assert-the-url-is-http-localhost-8000-users-1-edit",
      "doc_id": "api/commands/url",
      "heading": "Assert the URL is http://localhost:8000/users/1/edit",
      "heading_level": 4,
      "content_markdown": "#### Assert the URL is `http://localhost:8000/users/1/edit`\n\n```\n// clicking the anchor causes the browser to follow the link\ncy.get('#user-edit a').click()\ncy.url().should('include', '/users/1/edit') // => true\ncy.url().should('eq', 'http://localhost:8000/users/1/edit') // => true\n```\n",
      "section": "api",
      "anchors": [
        "assert-the-url-is-http-localhost-8000-users-1-edit"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 41
    },
    {
      "id": "api/commands/url#notes",
      "doc_id": "api/commands/url",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### Href Shorthand\n\n#### URL is an alias for `cy.location('href')`\n\n`cy.url()` uses `href` under the hood.\n\n```\ncy.url() // these yield the same string\ncy.location('href') // these yield the same string\n```\n\n### Differences\n\n#### URL versus href\n\nGiven the remote URL, `http://localhost:8000/index.html`, all 3 of these assertions are the same.\n\n```\ncy.location('href').should('include', '/index.html')\n\ncy.location().its('href').should('include', '/index.html')\n\ncy.url().should('include', '/index.html')\n```\n\n`href` and `toString` come from the `window.location` spec.\n\nBut you may be wondering where the URL property comes from. Per the `window.location` spec, there actually isn't a URL property on the `location` object.\n\n`cy.url()` exists because it's what most developers naturally assume would return them the full current URL. We almost never refer to the URL as an `href`.\n\n#### Hardcoded versus using the configuration object\n\nInstead of hard-coding the URL used in the assertion, we recommend you define a `baseUrl` in your [Cypress configuration](/llm/markdown/app/references/configuration.md). For more details on why, see our Best Practices guide on [setting a global `baseUrl`](/llm/markdown/app/core-concepts/best-practices.md#Setting-a-Global-baseUrl).\n\nGiven the remote URL, `http://localhost:8000/index.html`, and the baseUrl, `http://localhost:8000`, these assertions are the same.\n\n```\ncy.url().should('eq', 'http://localhost:8000/index.html')\ncy.url().should('eq', Cypress.config().baseUrl + '/index.html') // tests won't fail in case the port changes\n```\n\n#### Assert that the url contains \"#users/new\"\n\n```\ncy.url().should('contain', '#users/new')\n```\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 271
    },
    {
      "id": "api/commands/url#href-shorthand",
      "doc_id": "api/commands/url",
      "heading": "Href Shorthand",
      "heading_level": 3,
      "content_markdown": "### Href Shorthand\n\n#### URL is an alias for `cy.location('href')`\n\n`cy.url()` uses `href` under the hood.\n\n```\ncy.url() // these yield the same string\ncy.location('href') // these yield the same string\n```\n",
      "section": "api",
      "anchors": [
        "href-shorthand"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 43
    },
    {
      "id": "api/commands/url#differences",
      "doc_id": "api/commands/url",
      "heading": "Differences",
      "heading_level": 3,
      "content_markdown": "### Differences\n\n#### URL versus href\n\nGiven the remote URL, `http://localhost:8000/index.html`, all 3 of these assertions are the same.\n\n```\ncy.location('href').should('include', '/index.html')\n\ncy.location().its('href').should('include', '/index.html')\n\ncy.url().should('include', '/index.html')\n```\n\n`href` and `toString` come from the `window.location` spec.\n\nBut you may be wondering where the URL property comes from. Per the `window.location` spec, there actually isn't a URL property on the `location` object.\n\n`cy.url()` exists because it's what most developers naturally assume would return them the full current URL. We almost never refer to the URL as an `href`.\n\n#### Hardcoded versus using the configuration object\n\nInstead of hard-coding the URL used in the assertion, we recommend you define a `baseUrl` in your [Cypress configuration](/llm/markdown/app/references/configuration.md). For more details on why, see our Best Practices guide on [setting a global `baseUrl`](/llm/markdown/app/core-concepts/best-practices.md#Setting-a-Global-baseUrl).\n\nGiven the remote URL, `http://localhost:8000/index.html`, and the baseUrl, `http://localhost:8000`, these assertions are the same.\n\n```\ncy.url().should('eq', 'http://localhost:8000/index.html')\ncy.url().should('eq', Cypress.config().baseUrl + '/index.html') // tests won't fail in case the port changes\n```\n\n#### Assert that the url contains \"#users/new\"\n\n```\ncy.url().should('contain', '#users/new')\n```\n",
      "section": "api",
      "anchors": [
        "differences"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 225
    },
    {
      "id": "api/commands/url#url-versus-href",
      "doc_id": "api/commands/url",
      "heading": "URL versus href",
      "heading_level": 4,
      "content_markdown": "#### URL versus href\n\nGiven the remote URL, `http://localhost:8000/index.html`, all 3 of these assertions are the same.\n\n```\ncy.location('href').should('include', '/index.html')\n\ncy.location().its('href').should('include', '/index.html')\n\ncy.url().should('include', '/index.html')\n```\n\n`href` and `toString` come from the `window.location` spec.\n\nBut you may be wondering where the URL property comes from. Per the `window.location` spec, there actually isn't a URL property on the `location` object.\n\n`cy.url()` exists because it's what most developers naturally assume would return them the full current URL. We almost never refer to the URL as an `href`.\n",
      "section": "api",
      "anchors": [
        "url-versus-href"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 112
    },
    {
      "id": "api/commands/url#hardcoded-versus-using-the-configuration-object",
      "doc_id": "api/commands/url",
      "heading": "Hardcoded versus using the configuration object",
      "heading_level": 4,
      "content_markdown": "#### Hardcoded versus using the configuration object\n\nInstead of hard-coding the URL used in the assertion, we recommend you define a `baseUrl` in your [Cypress configuration](/llm/markdown/app/references/configuration.md). For more details on why, see our Best Practices guide on [setting a global `baseUrl`](/llm/markdown/app/core-concepts/best-practices.md#Setting-a-Global-baseUrl).\n\nGiven the remote URL, `http://localhost:8000/index.html`, and the baseUrl, `http://localhost:8000`, these assertions are the same.\n\n```\ncy.url().should('eq', 'http://localhost:8000/index.html')\ncy.url().should('eq', Cypress.config().baseUrl + '/index.html') // tests won't fail in case the port changes\n```\n",
      "section": "api",
      "anchors": [
        "hardcoded-versus-using-the-configuration-object"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 96
    },
    {
      "id": "api/commands/url#rules",
      "doc_id": "api/commands/url",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements\n\n*   `cy.url()` requires being chained off of `cy`.\n\n### Assertions\n\n*   `cy.url()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed\n\n### Timeouts\n\n*   `cy.url()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 52
    }
  ]
}