Last active
March 21, 2020 09:46
-
-
Save s1n7ax/a893a0dea6a463c2ce6181a6f94f4b89 to your computer and use it in GitHub Desktop.
techminister.com cypress-first-impression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CommonJS default export | |
module.exports = () => { | |
// do something | |
} | |
// ES6 module default export | |
export default () => { | |
// do something | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CommonJS default import | |
const doSomthing = require('../doSomething') | |
// ES6 module default import | |
import doSomething from '../doSomething' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* express is an external node modules that is used to create http servers | |
* https://expressjs.com/ | |
*/ | |
import express from 'express'; | |
describe('Using modules with Cypress', () => { | |
it('will never make this method', () => { | |
console.log('') | |
}) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ES6 code automation engineer writes | |
export default class Cat { | |
static meaw() { | |
console.log('Meaw!!!'); | |
} | |
} | |
// Above ES6 class will be preprocessed in to following ES5 code before the run | |
// You got the source map to original ES6 code in case you want to debug | |
var Cat = /*#__PURE__*/ function() { | |
function Cat() { | |
(0, _classCallCheck2["default"])(this, Cat); | |
}(0, _createClass2["default"])(Cat, null, [{ | |
key: "meaw", | |
value: function meaw() { | |
console.log('Meaw!!!'); | |
} | |
}]); | |
return Cat; | |
}(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Google', () => { | |
it('should search value in Google', () => { | |
// navigate to google | |
cy.visit('https://www.google.com'); | |
// find element with title Search | |
// type hello world | |
// hit enter | |
cy.get('input[title="Search"]') | |
.type('Hello world') | |
.type('{enter}'); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* path is a native node js modules | |
* https://nodejs.org/api/path.html | |
*/ | |
import path from 'path'; | |
/* | |
* simple message router is a external node module written by an awesome guy XD | |
* https://www.npmjs.com/package/simple-message-router | |
*/ | |
import Router from 'simple-message-router'; | |
describe('Using modules with Cypress', () => { | |
it('using external modules', () => { | |
var root = new Router(); | |
let middleware = false; | |
root.registerMiddleware(function() { | |
middleware = true; | |
}); | |
root.dispatchRequest('/'); | |
assert.isTrue(middleware); | |
}); | |
it('using nodejs modules', () => { | |
assert.equal('/home/user', path.join('/', 'home', 'user')); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Google', () => { | |
it('should search value in Google', () => { | |
cy.visit('https://www.google.com'); | |
// Storing the Chainer object to use it in the future | |
const input = cy.get('div'); | |
// Find search 'input' within 'div' and type 'hello world' | |
input.find('input[title="Search"]').type('hello world'); | |
/* | |
Eventhough following statement looks like finding search 'input' within 'div' and hit { enter } key, it's not | |
This has nothing to do with promises but the weird way Cypress collects actions & executes them | |
So the following statement is going to search for an 'input' element in last statements 'subject', which is the 'input' element | |
There is no 'input' element within an 'input' element so it's failing (not what we wanted to do anyway) | |
*/ | |
input.find('input[title="Search"]').type('{enter}'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment