{
  "doc": {
    "id": "api/commands/location",
    "title": "cy.location()",
    "description": "Get the URL of the page that is currently active in Cypress as a location object, or one part of it, such as the pathname.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/location.md",
    "version": "5a232a3cf094b8f928b1179ce5af6a5046296fac",
    "updated_at": "2026-11-13T01:14:31.437Z",
    "headings": [
      {
        "id": "api/commands/location#location",
        "text": "location",
        "level": 1
      },
      {
        "id": "api/commands/location#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/location#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/location#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/location#yields",
        "text": "Yields",
        "level": 3
      },
      {
        "id": "api/commands/location#when-not-given-a-key-argument",
        "text": "When not given a key argument",
        "level": 4
      },
      {
        "id": "api/commands/location#when-given-a-key-argument",
        "text": "When given a key argument",
        "level": 4
      },
      {
        "id": "api/commands/location#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/location#key-argument",
        "text": "Key argument",
        "level": 3
      },
      {
        "id": "api/commands/location#assert-that-a-redirect-works",
        "text": "Assert that a redirect works",
        "level": 4
      },
      {
        "id": "api/commands/location#wait-longer-for-a-slow-redirect",
        "text": "Wait longer for a slow redirect",
        "level": 4
      },
      {
        "id": "api/commands/location#match-a-pathname-that-contains-a-generated-id",
        "text": "Match a pathname that contains a generated ID",
        "level": 4
      },
      {
        "id": "api/commands/location#save-part-of-the-url-for-later-in-the-test",
        "text": "Save part of the URL for later in the test",
        "level": 4
      },
      {
        "id": "api/commands/location#no-arguments",
        "text": "No arguments",
        "level": 3
      },
      {
        "id": "api/commands/location#make-assertions-about-every-location-property",
        "text": "Make assertions about every location property",
        "level": 4
      },
      {
        "id": "api/commands/location#check-location-for-query-params-and-pathname",
        "text": "Check location for query params and pathname",
        "level": 4
      },
      {
        "id": "api/commands/location#query-parameters",
        "text": "Query parameters",
        "level": 3
      },
      {
        "id": "api/commands/location#read-a-query-parameter",
        "text": "Read a query parameter",
        "level": 4
      },
      {
        "id": "api/commands/location#assert-on-query-parameters-in-any-order",
        "text": "Assert on query parameters in any order",
        "level": 4
      },
      {
        "id": "api/commands/location#cross-origin-redirects",
        "text": "Cross-origin redirects",
        "level": 3
      },
      {
        "id": "api/commands/location#assert-that-sign-in-redirects-to-an-identity-provider",
        "text": "Assert that sign-in redirects to an identity provider",
        "level": 4
      },
      {
        "id": "api/commands/location#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/location#cy-location-yields-a-plain-object-not-window-location",
        "text": "cy.location() yields a plain object, not window.location",
        "level": 3
      },
      {
        "id": "api/commands/location#cross-origin-pages-and-cy-location",
        "text": "Cross-origin pages and cy.location()",
        "level": 3
      },
      {
        "id": "api/commands/location#choosing-between-cy-location-cy-url-and-cy-hash",
        "text": "Choosing between cy.location(), cy.url(), and cy.hash()",
        "level": 3
      },
      {
        "id": "api/commands/location#pass-a-key-instead-of-chaining-its",
        "text": "Pass a key instead of chaining .its()",
        "level": 3
      },
      {
        "id": "api/commands/location#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/location#requirements",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/location#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/location#timeouts",
        "text": "Timeouts",
        "level": 3
      },
      {
        "id": "api/commands/location#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/location#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/location#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "location"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Get the URL of the page that is currently active as a location object, or one part of that URL."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.location()\ncy.location(key)\ncy.location(options)\ncy.location(key, options)"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Usage"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Correct Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.location() // Get location object\ncy.location('host') // Get the host of the location object\ncy.location('port') // Get the port of the location object"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Incorrect Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('a').location() // Ignores the link, yields the page's location\ncy.location('assign') // Errors, the location object has no assign key"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.location()` reads the page's URL, not an element's `href`. To check where a link points, assert on the link's own properties instead:"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('a').should('have.prop', 'pathname', '/users')"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Arguments"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "key (String)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "One of the properties listed under "
          },
          {
            "type": "link",
            "title": null,
            "url": "#Yields",
            "children": [
              {
                "type": "text",
                "value": "Yields"
              }
            ]
          },
          {
            "type": "text",
            "value": ", such as `'pathname'`. `cy.location()` yields that property's value instead of the full location object, and fails when the location object has no property named `key`."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "options (Object)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Pass in an options object to change the default behavior of `cy.location()`."
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Option"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Default"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Description"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`log`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`true`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Displays the command in the "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/open-mode.md#Command-Log",
                    "children": [
                      {
                        "type": "text",
                        "value": "Command Log"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`timeout`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/configuration.md#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "`defaultCommandTimeout`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Time to wait for `cy.location()` to resolve before "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "#Timeouts",
                    "children": [
                      {
                        "type": "text",
                        "value": "timing out"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Yields"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.location()` is a query, and it is safe to chain further commands."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "When not given a `key` argument"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.location()` yields a plain object with these properties. The example values are for the URL `https://example.com:8080/app/users?tab=1#section`."
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Property"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Type"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Example value"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`hash`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "string"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`'#section'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`host`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "string"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`'example.com:8080'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`hostname`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "string"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`'example.com'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`href`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "string"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`'https://example.com:8080/app/users?tab=1#section'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`origin`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "string"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`'https://example.com:8080'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`pathname`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "string"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`'/app/users'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`port`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "string"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`'8080'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`protocol`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "string"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`'https:'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`search`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "string"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`'?tab=1'`"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`searchParams`"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams",
                    "children": [
                      {
                        "type": "text",
                        "value": "`URLSearchParams`"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "`searchParams.get('tab')` returns `'1'`"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "When given a `key` argument"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.location()` yields the value of that property: a string, or a `URLSearchParams` object for `searchParams`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.location()` fails when the location object has no property named `key`"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "These diagrams show where each key sits in a URL:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "In a hash-based route, a query string after the `#` is part of the hash:"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Key argument"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Assert that a redirect works"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Grab only the `pathname` and add an assertion."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.visit('http://localhost:3000/admin')\ncy.location('pathname').should('eq', '/login')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Wait longer for a slow redirect"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Pass a `timeout` when a redirect takes longer than "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/references/configuration.md#Timeouts",
            "children": [
              {
                "type": "text",
                "value": "`defaultCommandTimeout`"
              }
            ]
          },
          {
            "type": "text",
            "value": ", such as after a login request. Cypress retries the assertion until the pathname matches or the timeout passes."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('[data-cy=\"login\"]').click()\ncy.location('pathname', { timeout: 10000 }).should('eq', '/dashboard')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Match a pathname that contains a generated ID"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When your application creates a record and navigates to it, the ID in the URL isn't known ahead of time. Match the pathname against a regular expression instead."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.get('[data-cy=\"create-user\"]').click()\ncy.location('pathname').should('match', /^\\/users\\/\\d+$/)"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Save part of the URL for later in the test"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Transform the value in "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/then.md",
            "children": [
              {
                "type": "text",
                "value": "`.then()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " and save it with "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/as.md",
            "children": [
              {
                "type": "text",
                "value": "`.as()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " to use it in a later command."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.location('pathname')\n  .then((pathname) => pathname.split('/').pop())\n  .as('userId')\n\ncy.get('@userId').then((userId) => {\n  cy.request(`/api/users/${userId}`).its('status').should('eq', 200)\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "No arguments"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Make assertions about every location property"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.visit('http://localhost:8000/app/index.html?q=dan#/users/123/edit')\n\ncy.location().should((loc) => {\n  expect(loc.hash).to.eq('#/users/123/edit')\n  expect(loc.host).to.eq('localhost:8000')\n  expect(loc.hostname).to.eq('localhost')\n  expect(loc.href).to.eq(\n    'http://localhost:8000/app/index.html?q=dan#/users/123/edit'\n  )\n  expect(loc.origin).to.eq('http://localhost:8000')\n  expect(loc.pathname).to.eq('/app/index.html')\n  expect(loc.port).to.eq('8000')\n  expect(loc.protocol).to.eq('http:')\n  expect(loc.search).to.eq('?q=dan')\n  expect(loc.searchParams.get('q')).to.eq('dan')\n})"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Check location for query params and pathname"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Pass a callback to "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/should.md",
            "children": [
              {
                "type": "text",
                "value": "`.should()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " to work with the location object directly. Cypress retries the callback until every assertion in it passes."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "index.html"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "<form action=\"/users\">\n  <input id=\"search\" name=\"search\" />\n</form>"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "spec.cy.js"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.visit('http://localhost:3000/')\ncy.get('#search').type('niklas{enter}')\ncy.location().should((loc) => {\n  expect(loc.search).to.eq('?search=niklas')\n  expect(loc.pathname).to.eq('/users')\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Query parameters"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Read a query parameter"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`searchParams` yields a `URLSearchParams` object, so you can call its methods with "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/invoke.md",
            "children": [
              {
                "type": "text",
                "value": "`.invoke()`"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.visit('http://localhost:3000/users?page=2&sort=name')\ncy.location('searchParams').invoke('get', 'sort').should('eq', 'name')"
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Assert on query parameters in any order"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Comparing `search` to a string fails when your application writes the same parameters in a different order. Asserting on `searchParams` checks each parameter by name, and `getAll()` reads a parameter that appears more than once."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.visit('http://localhost:3000/posts?sort=name&tag=cypress&page=2&tag=testing')\ncy.location('searchParams').should((params) => {\n  expect(params.get('page')).to.eq('2')\n  expect(params.get('sort')).to.eq('name')\n  expect(params.getAll('tag')).to.deep.eq(['cypress', 'testing'])\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Cross-origin redirects"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 4,
        "children": [
          {
            "type": "text",
            "value": "Assert that sign-in redirects to an identity provider"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.location()` reads the URL after your application navigates to another origin, so you can confirm where a sign-in flow landed before you interact with that page inside "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/origin.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.origin()`"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.visit('http://localhost:3000/')\ncy.contains('a', 'Sign in').click()\n\ncy.location('origin').should('eq', 'http://auth.example.com')\ncy.location('searchParams')\n  .invoke('get', 'redirect_uri')\n  .should('eq', 'http://localhost:3000/callback')\n\ncy.origin('http://auth.example.com', () => {\n  cy.get('input[name=\"email\"]').type('user@example.com')\n})"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Notes"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "`cy.location()` yields a plain object, not `window.location`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.location()` reads the current URL of the application under test from the browser and yields a plain object with the properties listed under "
          },
          {
            "type": "link",
            "title": null,
            "url": "#Yields",
            "children": [
              {
                "type": "text",
                "value": "Yields"
              }
            ]
          },
          {
            "type": "text",
            "value": ". It has none of the `window.location` methods, such as `assign()` or `reload()`. Read `href` when you need the full URL as a string."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Changing a property on the real `window.location` object navigates the browser away. Changing a property on the object `cy.location()` yields has no effect on navigation."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Logging the yielded object shows only its URL properties:"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.location().then((loc) => {\n  console.log(loc)\n})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Cross-origin pages and `cy.location()`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Cypress reads the URL through the browser's automation protocol instead of the application's `window`, so `cy.location()` works after your application navigates to another origin, without wrapping it in "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/origin.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.origin()`"
              }
            ]
          },
          {
            "type": "text",
            "value": ". See "
          },
          {
            "type": "link",
            "title": null,
            "url": "#Assert-that-sign-in-redirects-to-an-identity-provider",
            "children": [
              {
                "type": "text",
                "value": "Assert that sign-in redirects to an identity provider"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Choosing between `cy.location()`, `cy.url()`, and `cy.hash()`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "All three commands read the same URL from the browser. Use the one that yields what you're asserting on:"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/url.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.url()`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " yields the full URL as a string, the same value as `cy.location('href')`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/hash.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.hash()`"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " yields the fragment, the same value as `cy.location('hash')`"
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.location()` yields any other part of the URL, such as `pathname`, `host`, or `searchParams`, or the whole location object"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "In a hash-based route, a query string after the `#` belongs to the hash, so `search` and `searchParams` don't include it. See "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/hash.md#Query-strings-inside-a-hash-route",
            "children": [
              {
                "type": "text",
                "value": "Query strings inside a hash route"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Pass a key instead of chaining `.its()`"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "`cy.location('pathname')` and `cy.location().its('pathname')` both retry until the assertion that follows passes. Passing the key reads more clearly and shows the key next to `location` in the Command Log."
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.location('pathname').should('eq', '/users')"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Rules"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Requirements"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.location()` requires being chained off of `cy`."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Assertions"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.location()` automatically "
                  },
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/core-concepts/retry-ability.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "retries"
                      }
                    ]
                  },
                  {
                    "type": "text",
                    "value": " until all chained assertions have passed"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Timeouts"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.location()` can time out waiting for the browser to report the page's URL."
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "text",
                    "value": "`cy.location()` can time out waiting for assertions you've added to pass."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Command Log"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Assert on the location's href"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.location().should((loc) => {\n  expect(loc.href).to.include('commands/querying')\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The commands above display in the Command Log as:"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When clicking on `location` within the Command Log, the console outputs the following:"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "History"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Version"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Changes"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#15-18-1",
                    "children": [
                      {
                        "type": "text",
                        "value": "15.18.1"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Experimental WebKit yields the same location object as other browsers"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md#15-0-0",
                    "children": [
                      {
                        "type": "text",
                        "value": "15.0.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "In Chromium-based browsers and Firefox, reads the URL through the browser's automation protocol. The yielded object includes `searchParams` and no longer includes `toString`"
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/hash.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.hash()`"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/commands/url.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "`cy.url()`"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 1580
}