Skip to content

Instantly share code, notes, and snippets.

@jennifer-shehane
Last active December 4, 2017 11:47
Show Gist options
  • Save jennifer-shehane/eaa017496b9b5cfc98e8f4ef31a437fc to your computer and use it in GitHub Desktop.
Save jennifer-shehane/eaa017496b9b5cfc98e8f4ef31a437fc to your computer and use it in GitHub Desktop.
Selenium versus Cypress.io
describe('Kitchen Sink', function(){
it('cy.should - assert that <title> is correct', function(){
cy
.visit('https://example.cypress.io/')
.title().should('include', 'Kitchen Sink')
})
context('Querying', function(){
beforeEach(function(){
cy.visit('https://example.cypress.io/commands/querying')
})
it('cy.get() - query DOM elements', function(){
cy
// We can get DOM elements by id
.get('#query-btn').should('contain', 'Button')
// We can get DOM elements by class
.get('.query-btn').should('contain', 'Button')
// we can CSS selectors just like jQuery
.get('#querying .well>button:first').should('contain', 'Button')
})
})
})
var selenium = require('selenium-webdriver')
var chai = require('chai')
var expect = chai.expect
chai.use(require('chai-as-promised'))
before(function() {
this.timeout(10000)
this.driver = new selenium.Builder().withCapabilities(selenium.Capabilities.chrome()).build()
this.driver.getWindowHandle()
});
after(function() {
this.driver.quit()
});
describe('Kitchen Sink', function() {
it('getTitle() - assert that <title> is correct', function() {
this.driver.get('https://example.cypress.io/')
expect(this.driver.getTitle()).to.eventually.contain('Cypress.io: Kitchen Sink')
});
describe('Querying', function() {
it('query DOM elements', function() {
this.driver.get('https://example.cypress.io/commands/querying')
// We can get DOM elements by id
var text = this.driver.findElement({id: 'query-btn'}).getText()
expect(text).to.eventually.equal('Button')
// We can get DOM elements by class
text = this.driver.findElement({css: '.query-btn'}).getText()
expect(text).to.eventually.equal('Button')
// we can CSS selectors just like jQuery
text = this.driver.findElement({css: '#querying .well>button:first'}).getText()
expect(text).to.eventually.equal('Button')
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment