Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 1.09 KB

File metadata and controls

28 lines (20 loc) · 1.09 KB

Url Query

Url query parameters are the base of the dynamic web and they are used by all the main search engines to implment their search funcionalities.

Examples

How does it work?

For example if we can to test that a Url has a q= parameter, we can use the following code:

cy.url().should("include", "q=");

The previous code is just a simple check but to make sure that this value was actually parsable and present in the Url we can use this code:

cy.location().then((location) => {
  // here we can access the location searchParams directly with the URL constructor
  const searchQuery = new URL(location.href).searchParams.get("q");
  // we then check that the searched text is in the query in the URL
  expect(searchQuery).to.equal("searched text");
});