Francois Girard
Francois Girard

Reputation: 348

Protractor AngularJs, changing location

When I tell protractor to click on a button that change currentLocation, the html protractor is looking in is not updated.

I know, there is the 'browser.setLocation()' method and it works well for it's purpose. But if the button create an invoice in the database for example, and then change the location.. I cannot just use browser.setLocation, I have to click on the button and wait for the new page content, but I'm not able with protractor..

edit: I also tried this:

var EC = protractor.ExpectedConditions;
return browser.wait(EC.urlContains('invoice'), 2000, "error");

this is not working

Is there a solution ?

edit: Here is my test code:

var EC = protractor.ExpectedConditions;
browser.wait(EC.elementToBeClickable($('#menu-newClient')), 2000, "error waiting menu-newClient")
  .then(function () {
    // Click on 'new client' button, that create a client and change location to client form
    return element(by.id('menu-newClient')).click();
  })
  .then(function(){
    // The textbox 'test1' is in the header and works correctly
    element(by.model('test1')).sendKeys("test1"); 
    // The textbox 'test2' is in the Client form and protractor don't find it
    var el = element(by.className('test2'));         
    return browser.wait(EC.presenceOf(el), 2000, "error waiting test2") 
  })
  .then(function () {
    element(by.model('test2')).sendKeys("test2");
  });

Second test:

var EC = protractor.ExpectedConditions;
browser.wait(EC.elementToBeClickable($('#menu-newClient')), 2000, "error waiting menu-newClient")
  .then(function () {
    return element(by.id('menu-newClient')).click();
  })
  .then(function(){
    // Set new location and load the new html
    browser.setLocation("client");
  })
  .then(function(){
    // Now protractor find the textbox 'test2'
    var el = element(by.className('test2'));
    return browser.wait(EC.presenceOf(el), 2000, "error3")
  })
  .then(function () {
    element(by.model('test2')).sendKeys("test2");
  }); 

Upvotes: 0

Views: 127

Answers (1)

Yash Jagdale
Yash Jagdale

Reputation: 1508

In same situation below code worked for me:-

browser.wait(function() {
    return browser.getCurrentUrl().then(function (url) {
         return url.includes("invoice");
    });
}, 2000, "Error").then(function() {
//next code will go here
})

Upvotes: 0

Related Questions