Sha256: cca742cfe80e0b1a5a33bcf8fd1cc1b15c80ede0c68d3137f8ee8963faa98f31

Contents?: true

Size: 1.87 KB

Versions: 20

Compression:

Stored size: 1.87 KB

Contents

/// <reference types="Cypress" />

context('Querying', () => {
  beforeEach(() => {
    cy.visit('https://example.cypress.io/commands/querying')
  })

  // The most commonly used query is 'cy.get()', you can
  // think of this like the '$' in jQuery

  it('cy.get() - query DOM elements', () => {
    // https://on.cypress.io/get

    cy.get('#query-btn').should('contain', 'Button')

    cy.get('.query-btn').should('contain', 'Button')

    cy.get('#querying .well>button:first').should('contain', 'Button')
    //              ↲
    // Use CSS selectors just like jQuery
  })

  it('cy.contains() - query DOM elements with matching content', () => {
    // https://on.cypress.io/contains
    cy.get('.query-list')
      .contains('bananas').should('have.class', 'third')

    // we can pass a regexp to `.contains()`
    cy.get('.query-list')
      .contains(/^b\w+/).should('have.class', 'third')

    cy.get('.query-list')
      .contains('apples').should('have.class', 'first')

    // passing a selector to contains will
    // yield the selector containing the text
    cy.get('#querying')
      .contains('ul', 'oranges')
      .should('have.class', 'query-list')

    cy.get('.query-button')
      .contains('Save Form')
      .should('have.class', 'btn')
  })

  it('.within() - query DOM elements within a specific element', () => {
    // https://on.cypress.io/within
    cy.get('.query-form').within(() => {
      cy.get('input:first').should('have.attr', 'placeholder', 'Email')
      cy.get('input:last').should('have.attr', 'placeholder', 'Password')
    })
  })

  it('cy.root() - query the root DOM element', () => {
    // https://on.cypress.io/root

    // By default, root is the document
    cy.root().should('match', 'html')

    cy.get('.query-ul').within(() => {
      // In this within, the root is now the ul DOM element
      cy.root().should('have.class', 'query-ul')
    })
  })
})

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
cypress-on-rails-1.12.1 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.12.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.11.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.10.1 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.9.1 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.9.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.8.1 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.8.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.7.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.6.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.5.1 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.5.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.4.2 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.4.1 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.4.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.3.0 lib/generators/cypress_dev/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.2.1 lib/generators/cypress_dev/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.2.0 lib/generators/cypress_dev/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.1.1 lib/generators/cypress_dev/templates/spec/cypress/integration/examples/querying.spec.js
cypress-on-rails-1.1.0 lib/generators/cypress_dev/templates/spec/cypress/integration/examples/querying.spec.js