mercredi 28 mars 2018

Cucumber-Protractor tests skipping over assertions, falsely passing

So I am brand new at Javascript, my only language before this was Ruby. I have written API tests with Cucumber and Ruby for years, but now I am trying to figure out UI tests for an angular app using Protractor and Cucumber.js. I have the framework set up and the test steps run are passing, but falsely so.

Here is a snippet of my step definitions, with a few edits to change data in assertions and the string for the assertion is intentionally wrong to trigger a failure. They run and are passing, but only because it ignores the assertion. I don't see it actually doing anything in the browser, but if I put in console.log messages I do see them in the console. However, if I comment out the last callback, then I can see it run in the browser and it actually checks the assertions and fails as it should.

Cucumber doesn't require callbacks, and removing them results in it running in exactly the same way... only I can't comment out a callback of course and watch it run like I mentioned above.

And if I don't put that timeout in the first step, then the whole thing errors out at the first step with "Error: function timed out after 5000 milliseconds"

Why?!? Thanks!!

Protractor 5.3.0 with Cucumber 4.0.0 and protractor-cucumber-framework 4.2.0

Given('I am on the home page', {timeout: 30000}, (callback) => {
    browser.waitForAngularEnabled(false);
    browser.get(browser.params.env.int).then(callback);
});

Then('the log in form is displayed', callback => {
    expect(element(by.id('email')).isPresent()).to.eventually.be.true;
    expect(element(by.id('password')).isPresent()).to.eventually.be.true;
    callback();
});

When('I enter my user name', callback => {
    element(by.name('email')).sendKeys('my_addy@example.com');
    expect(element(by.id('email')).getAttribute('value')).to.eventually.equal('something that does match');
    callback();
});

When('I enter my password', callback => {
    element(by.name('password')).sendKeys('blah');
    callback();
});

When('I click the log in button', callback => {
    element(by.buttonText('Log In')).click();
    callback();
});

Then('I am on the X page', callback => {
    expect(browser.getCurrentUrl()).to.eventually.contains('Y');
    // callback();
});

Aucun commentaire:

Enregistrer un commentaire