3

I am writing a test to automate a scenario, using PROTRACTOR:

I am getting "Undefined is not a function" at .toBe below is my code: trying to get offset position of an element :

this.Then(/^I should have ONLY LOGO available on main page$/, function () { 
    element(by.id('mainPage')).getLocation().then(function (navDivLocation) { 
        var currTop = navDivLocation.y; 
        var currLeft = navDivLocation.x; 

        expect(currLeft).toBe(0); 
        expect(currTop).toBe(0); 
     }); 
});
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
msbyuva
  • 3,467
  • 13
  • 63
  • 87

1 Answers1

3

Cucumber and Jasmine are mutually exclusive.

If you are not already, you should use Chai assertion library:

expect(currLeft).to.equal(0); 
expect(currTop).to.equal(0); 

To assert promises returned by different Protractor functions, use Chai-as-promised library - you would be able to pass promises inside the expect(). Example:

expect(elm.getText()).should.eventually.equal("my text");
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • thanks for your response.. well I am trying to get x, y position of id "mainPag" -- style="position: absolute; left:0px; top:0px;" ? tried using above snippet but its not getting... – msbyuva Dec 16 '15 at 01:33
  • @msbyuva okay, what error are you getting now - after using `chain` assertions? Thanks. – alecxe Dec 16 '15 at 01:50
  • expect(currLeft).to.equal(0); expect(currTop).to.equal(0); expected answer should be 0 and 0 but I am getting 467, 187--- as per HTML style="position: absolute; left:0px; top:0px;" – msbyuva Dec 16 '15 at 02:01
  • @msbyuva yeah, that's cause `getLocation()` gives you an absolute location of an element on a page. – alecxe Dec 16 '15 at 02:04