量角器AngularJs,更改位置

时间:2018-12-11 20:49:38

标签: angularjs protractor

当我告诉量角器单击更改currentLocation的按钮时,正在查找的html量角器不会更新。

我知道,有一个“ browser.setLocation()”方法,因此很有效。但是,如果该按钮例如在数据库中创建了一个发票,然后更改了位置。.我不能只使用browser.setLocation,我必须单击该按钮并等待新页面的内容,但是我无法使用量角器..

编辑: 我也尝试过:

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

这不起作用

有解决方案吗?

编辑: 这是我的测试代码:

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");
  });

第二项测试:

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");
  }); 

1 个答案:

答案 0 :(得分:0)

在相同情况下,以下代码对我有用:-

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