2

Is it because browser.setLocation is not supported in angular v6 (like by.model and by.binding)?

I have tried await browser.waitForAngular(), but it doesn't seem to change anything.

I do wish to keep synchronization between angular/protractor (e.g. browser.ignoreSynchronization = true and browser.waitForAngularEnabled(true))

Maxime Dupré
  • 5,319
  • 7
  • 38
  • 72

1 Answers1

1

It does appear that browser.setLocation is for angular v1 only, and I couldn't find an alternative for angular 2+.

I got it to work by executing a script to change the URL, and the angular router will do it without reloading the page (this is using useHash for the RouterModule):

const setLocation = url =>
  browser.executeScript(pUrl => window.location.href = `/#/${pUrl}`, url);

Then it works similarly to browser.setLocation:

 browser.get('http://angular.github.io/protractor/#/tutorial');
 setLocation('api');
 expect(browser.getCurrentUrl())
   .toBe('http://angular.github.io/protractor/#/api');
sorohan
  • 786
  • 6
  • 12