繁体   English   中英

获得网页标题的承诺永远不会与Protractor和Jasmine一起解决

[英]Promise for getting the title of a web page never resolves with Protractor and Jasmine

以下量角器/茉莉花测试代码仅打印出1和2,然后挂起并超时。

对于按钮元素的click()操作或浏览器对象上的getTitle方法的promise,或两者都是一个问题。

有没有人有解决方案,或者更好的方式做我正在做的事情?

码:

it('should allow successful login', function() {   
    browser.get('http://192.168.0.100/src/');
    browser.waitForAngular();

    var titlePromise = browser.getTitle();
    titlePromise.then(function(text){
      console.log("1**************", text);
    });

    var titlePromise = browser.getTitle();
    titlePromise.then(function(text){
      console.log("2**************", text);
    });

    element.all(by.model('credentials.username')).first().sendKeys('foo');
    element.all(by.model('credentials.password')).first().sendKeys('bar');
    var loginBtn = element.all(by.cssContainingText('.btn', 'Login')).first();
    loginBtn.click();
    browser.sleep(5000);

    var titlePromise = browser.getTitle();
    titlePromise.then(function(text){
      console.log("3**************", text);
    });    
  });
}); 

错误:

错误:等待Protractor在11秒后与页面同步超时。 请参阅https://github.com/angular/protractor/blob/master/docs/faq.md

我可能没有足够的信息,但有些事情要尝试:

  1. 很明显,您是否已阅读每个案例,这将导致链接文档中的超时https://github.com/angular/protractor/blob/master/docs/faq.md 如果你在Angular应用程序中使用$ timeout,Protractor永远不会加载。

  2. 你确定你正确选择了loginBtn吗? 您可能希望以交互方式测试量角器: https//github.com/angular/protractor/blob/master/docs/debugging.md 从量角器目录/ node_modules /量角器:

    $ node ./bin/elementexplorer.js http://192.168.0.100/src/

  3. 如果您正在登录并转到另一个页面,而不是等待下一页加载,请等待它更改:

    browser.driver.wait(function() { return browser.driver.getCurrentUrl().then(function(url) { return /logged-in-url/.test(url); }); });

您忘记了与文档的所有交互都是通过Promises完成的。 您的代码应该看起来像下面未经测试的块。

另请注意, 不需要 browser.waitForAngular ,“Protractor会在每个WebDriver操作之前自动应用此命令。”

不知道为什么你这么经常调用getTitle ,但我把它留在了,以防它使重构更清晰。

it('should allow successful login', function() {   
    browser.get('http://192.168.0.100/src/')
    .then(function(){
        return browser.getTitle()
    })
    .then(function(text){
        console.log("1**************", text);
        return browser.getTitle();
    })
    .then(function(text) {
        console.log("2**************", text);
        return browser.getTitle()
    })
    .then(function (text) {
        console.log("3**************", text);
        element.all(by.model('credentials.username')).first().sendKeys('foo');
    })
    .then(function () {
        element.all(by.model('credentials.password')).first().sendKeys('bar');
    })
    .then(function () {
        element.all(by.cssContainingText('.btn', 'Login')).first().click();
    })
    .then(function () {
        browser.sleep(5000); // Better to use ExpectedConditions to wait something
    })
    .then(function () {
        var titlePromise = browser.getTitle();
        return browser.getTitle()
    })
    .then(function (text) {
        console.log("3**************", text);
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM