Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing the <head> content - possible? #624

Closed
tivnet opened this issue May 27, 2018 · 4 comments
Closed

Testing the <head> content - possible? #624

tivnet opened this issue May 27, 2018 · 4 comments

Comments

@tivnet
Copy link

tivnet commented May 27, 2018

Dear Cypress,

I am having trouble finding any mentioning of testing the HEAD content, besides the title. Specifically, check the META DESCRIPTION?

Highly appreciate if you point me to a doc page.

Thank you!

@kuceb
Copy link
Contributor

kuceb commented May 28, 2018

You should be able to access anything on the document as described here https://docs.cypress.io/api/commands/document.html#Examples

@kuceb kuceb closed this as completed May 28, 2018
@tivnet
Copy link
Author

tivnet commented May 28, 2018

@bkucera Thank you, Ben, it wasn't clear to me from reading the docs. Now, after your explanation, I've got this working example:

it("works!", () => {
    cy.visit("/");
    cy.document().get('head meta[name="description"]')
      .should("have.attr", "content", "Here goes the description...");
});

As correctly noticed by @bkucera below, this should be simplified as follows:

it("works!", () => {
    cy.visit("/");
    cy.get('meta[name="description"]')
      .should("have.attr", "content", "Here goes the description...");
});

@kuceb
Copy link
Contributor

kuceb commented May 29, 2018

@tivnet the cy.document() is not actually doing anything in this case, since a cy.get will always act as if it is a new chain off of cy. You can just change your code to

cy.get('head meta[name="description"]')
    .should("have.attr", "content", "Here goes the description...");

@tivnet
Copy link
Author

tivnet commented May 30, 2018

Indeed. Do not know why it did not work for me. Do not even need the "head" part.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants