Protractor: catch AssertionError

I use Protractor with Chai as Promised to create a javascript based testing tool and I get an error

AssertionError: expected 'http://localhost:8888/test/homepage.php' to equal 'http://localhost:8888/test/my_homepage.php'

while I check the URL with this step definition:

this.Then(/^The url of the page should be "([^"]*)"$/, function(myUrl, callback){
    expect(browser.getCurrentUrl()).to.eventually.equal(myUrl);

    callback();
  });

I would like to catch this error in order to use another callback function, how can I do this? I tried using a try-catch block, but it does not seem to work. I can’t even understand if the AssertionErrorsTransporter is generating , could you give me an explanation about this?

Thank you in advance

+4
source share
1 answer

, - . @alecxe , ,

browser.getCurrentUrl().then(function(url) {
    if(url === myUrl) {
       callback();
    } else {
       callback('something went wrong'); 
    }
});

?

try {
  expect(browser.getCurrentUrl()).to.eventually.equal(myUrl);
  callback();
} catch(e) {
  callback('something went wrong ')); 
}
+2

Source: https://habr.com/ru/post/1624159/


All Articles