2

I've started to work with protractor + Jasmine for E2E testing.

The idea is to do an invalid operation and catch the exception:

expect(function () { return documentsPanel.clickUploadButtonError(); }).toThrow();

The documentsPanel is just a page object with multiple page actions. This is how I'm defining the method:

this.clickUploadButtonError = function () {
    return uploadButton.click().thenCatch(function (err) {
        throw('Cannot click upload button.');
    });
};

The idea is for expect to pass by catching the error but my test still fails as uploadButton.click() throws a Selenium error:

Failed: unknown error: Element ... is not clickable at point (263, 131).

Any ideas on how can Jasmine catch the Selenium error?

Mohsin Awan
  • 1,176
  • 2
  • 12
  • 29
mleitao
  • 23
  • 5

1 Answers1

1

You can provide an error callback explicitly:

return uploadButton.click().then(function success() {
    console.log("Click was successful");
}, function failure(error) {
    console.log("Click was unsuccessful");
    console.log(error);
});

As a side note, if you are interested in tackling the "Element is not clickable" errors, please see this summary of the things to try.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195