I have been working with nightmare.js to run tests using mocha. This is my first time working with these framework/libraries. I am currently creating a test that loads a login page on a web app im working on and attempts to sign in. This is the code I am using as a reference Source: http://ift.tt/2lFjwAH
describe('Login Page', function () {
describe('given bad data', () => {
it('should fail', done => {
nightmare
.goto('http://ift.tt/2p9v42e')
.on('page', (type, message) => {
if (type == 'alert') done()
})
.type('.login-email-input', 'notgonnawork')
.type('.login-password-input', 'invalid password')
.click('.login-submit')
.wait(2000)
.end()
.then()
.catch(done)
})
})
The main question I have about tis code is the .type and .click functions. Reading the nightmare api both of these functions work like so
.type(selector[, text])
Enters the text provided into the selector element. Empty or falsey values provided for text will clear the selector's value..type(selector[, text])
I have tried to implement this functionality using the code below
describe('/ (authentication)', () => {
it('should pass by logging into the system', done => {
// testing urls will be `http://localhost:port/path`
nightmare.goto('http://localhost:4000/login')
.on('page', (type, message) => {
if (type === 'alert') done()
})
.type('input[id="username"]', 'admin')
.type('input[id="password"]', 'toetagging')
.click('button[data-reactid=".0.0.1.3.0"]')
.wait(2000)
.end()
.then()
.catch(done)
})
})
My main question is, what exactly is the selector and how do I get it?
Aucun commentaire:
Enregistrer un commentaire