Jinu
Jinu

Reputation: 65

How to load a page without reloading it in protractor

While doing e2e testing using protractor ,a requirement comes to load a page.I tried browser.get,But that reloads the page resulting in cache clear.Getting ERROR as

Failed: Element not found in the cache - perhaps the page has changed since it was looked up

How to load a page without reloading it in protractor?

Upvotes: 2

Views: 3352

Answers (2)

Linh Pham
Linh Pham

Reputation: 3025

If you question is about routing in an angular app, then you can try with browser.setLocation().

browser.get('http://angular.github.io/protractor/#/tutorial');
browser.setLocation('api');
// You now will be in http://angular.github.io/protractor/#/api without any page reload

Reference: Protractor API browser.setLocation

Upvotes: 10

martin770
martin770

Reputation: 1288

Protractor's browser.get will always navigate to a RESET_URL=data:text/html, <html></html> before navigating to the page you requested. There are a couple options to get around this:

browser.driver.get(url) will use the webdriver native command, and bypass protractor's reset url. If you go this route on an angular page, you will want to add in a waitForAngular() before the command so that you wait for the original page to settle before navigating to the new page.

browser.ignoreSynchronization = true in your test will essentially turn browser.get into browser.driver.get and bypass the reset url. The downside here is that your entire test would now be ignoring angular synchronization.

Source: protractor/lib/protractor.js

Upvotes: 2

Related Questions