lundi 25 janvier 2016

Protractor element caching

I started to learn testing in Angular and have a little problem doing a serie of test in the same view.

I have a form with some inputs for customer data. I use it both for add new customer and edit an existing one.

So, firstly I test adding a new customer, then I click back, and click the first customer in a list (not the recently added). The data shows correctly in the view, but the test fails saying Expected 'new customer' to be 'customer 1'. Somehow element.name is caching the previous value.

Here is the test:

describe('Showing Customer data', function(){
    var customersMenu, homeMenu, firstListItem;

beforeEach(function() {
    customersMenu = element(by.css('.ion-person-stalker'));
    homeMenu = element(by.css('.ion-home'));
    firstListItem = element(by.css('.firstListItem'));
});

it('should create a new customer', function() {
    customersMenu.click();
    var newButton = element(by.css('.button-fab'));
    newButton.click();

    element(by.name('name')).sendKeys('new customer');
    [...] // The other fields...

    homeMenu.click();
});

it('should display correct customer data', function() {
    customersMenu.click();
    firstListItem.click();

    expect(element(by.name('name')).getAttribute('value')).toBe('customer 1');

    homeMenu.click();
});

});

Aucun commentaire:

Enregistrer un commentaire