首页 > 解决方案 > 量角器AngularJs,改变位置

问题描述

当我告诉量角器单击更改 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");
  }); 

标签: angularjsprotractor

解决方案


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

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

推荐阅读