Published on

Test a Client Address Book: Part 4

2 min read | 273 words
Authors
cypress tree

Photo by Yi Ma on Unsplash

Writing Our First Test

In part four of the series, we will create our first Cypress test to verify expected results for a search on Google.

The final test file will look like the following:

/*
 * Given: I am on google.com
 * When: I enter "Ironman Tony Stark" in the input
 * When: I press the "Enter" key
 * Then: I see Tony Stark (Marvel Cinematic Universe) in search results
 */

describe('Google Search', () => {
  it('should return search results for "Ironman"', () => {
    cy.visit('https://www.google.com/')
    // Get remaining code via Cypress selector tool while running
    //  the test
    cy.get('.gLFyf').type('Ironman Tony Stark').type('{enter}')
    cy.get(
      '[href="https://en.wikipedia.org/wiki/Tony_Stark_(Marvel_Cinematic_Universe)"] > .LC20lb'
    ).should('be.visible')
  })
})

The following video illustrates the entire process:

Part 5: Writing Better Tests with Cypress Testing Library

The final source code can be found here