{
  "doc": {
    "id": "api/commands/url",
    "title": "url | Cypress Documentation",
    "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": "a8fd16711bdda4c7b5645b9717e588ae99ec2470",
    "updated_at": "2026-05-18T17:21:32.047Z",
    "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-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "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-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/url#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/url#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about 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()cy.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 [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\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": 157
    },
    {
      "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 linkcy.get('#user-edit a').click()cy.url().should('include', '/users/1/edit') // => truecy.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.cy.url({ decode: true }).should('contain', '사랑')\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 81
    },
    {
      "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 linkcy.get('#user-edit a').click()cy.url().should('include', '/users/1/edit') // => truecy.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": 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 stringcy.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')cy.location().its('href').should('include', '/index.html')cy.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')cy.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": 265
    },
    {
      "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 stringcy.location('href') // these yield the same string\n```\n",
      "section": "api",
      "anchors": [
        "href-shorthand"
      ],
      "path": "/llm/json/chunked/api/commands/url.json",
      "token_estimate": 41
    },
    {
      "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')cy.location().its('href').should('include', '/index.html')cy.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')cy.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": 221
    },
    {
      "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')cy.location().its('href').should('include', '/index.html')cy.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": 109
    },
    {
      "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')cy.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": 95
    },
    {
      "id": "api/commands/url#rules",
      "doc_id": "api/commands/url",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)\n\n*   `cy.url()` requires being chained off of `cy`.\n\n### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#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 [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#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": 65
    }
  ]
}