Tuesday, October 25, 2016

How to use Jasmine for Protractor

Jasmine is essential for Protractor test. The testscripts of Protractor are in the style of Jasmine. Google has modified the speccial expect() function of Jasmine to work with promises. All functions of Protractor return only promises!

The expect() function is usually used to resolve the returned promises of Protractor for testing. When not using the expect() function, You have to resolve the returned promises first through the so-called then() function!

In summary, Protractor uses the same syntaxes and styles of Jasmine, like this:
describe('Angular App Test suite 1 -', function() {
  it('Testcase 1: should do xx job', function() {
    browser.get('');
    expect(element(by.xxx).getText()).toEqual(2);
    ...
    ...
  });
 
  it('Testcase 2: should do xxx job', function() {
    ...
    ...
  });
});
 
describe('Angular App Test suite 2 -', function() {
  it('Testcase 1: should do xx job', function() {
    browser.get('');
    expect(element(by.xxx).getText()).toEqual(2);
    ...
    ...
  });
 
  it('Testcase 2: should do xxx job', function() {
    ...
    ...
  });
});
I don't know "/some/some" comes from! (a bug in blogger self?)

No comments:

Post a Comment