Search code examples
javascripttestingprotractorend-to-end

How to change URL in protractor


I'm wondering how do you change the current URL upon pressing some button or link.

browser.waitForAngular();
expect(browser.driver.getCurrentUrl()).to.eventually.match(/document/).and.notify(callback);

I know this code will get the url and match it with document, I would like to set the URL upon a click.

e.g. I'm on Facebook and I want to go to profile, I click Profile button but want to update the URL by parsing a string value to it rather than a class/function

As I have a piece of code that doesn't have any classes to point to, the only thing I have is a href which contains the path location to the page.


Solution

  • Why don't actually let the browser navigate to the new URL on click, get it via browser.getCurrentUrl(), modify it and navigate to the modified URL, e.g.

    button.click();
    
    browser.getCurrentUrl().then(function (url) {
        browser.get(url + "?a=b");
    });