【问题标题】:Selenium get(url) issue on FirefoxFirefox 上的 Selenium get(url) 问题
【发布时间】:2017-03-30 22:40:59
【问题描述】:

我在使用 Selenium + mocha 打开 URL 时遇到了一些问题。这是我正在使用的代码行。

return driver.get('http://localhost/ClickSuscribe/#/MisProductos')

我发现 angular url 存在一些问题,但我还没有找到解决方案。

错误是Error: timeout of 40000ms exceeded. Ensure the done() callback is being called in this test.

这是测试用例:

it("Is visible", function() {
        if(viable)
        {
            return driver.findElements(webdriver.By.id('activarMiSitio')).then(function(misProductos){
                misProductos[0].getAttribute("class").then(function(webElement){
                    if(webElement==='ng-hide')
                    {
                        console.log('Element not found');
                    }
                    else{
                        console.log('Element exists');
                    }
                }).then(function(){
                    driver.sleep(500);
                    //return driver.get('http://localhost/ClickSuscribe/#').catch(r => console.log(r));
                    return driver.get('http://localhost/ClickSuscribe/#/MisProductos').catch(r => console.log(r));
                });/*.then(function(){
                    driver.sleep(2000);
                    return driver.getCurrentUrl();
                }).then(function(currentUrl){
                    driver.sleep(1000);
                    console.log(currentUrl);
                });*/
            });
        }
        return console.log("No está loggeado");
    });

PS:这确实适用于 Chrome 和 IE。似乎 selenium 在处理带有锚点或井号“#”的 URL 时存在问题。

【问题讨论】:

  • 是get方法还是脚本执行的问题?
  • @MohamedELAYADI 我不太确定,但似乎最有可能与 get 方法有关,因为当它卡在那里大约一分钟时,会继续下一个测试。跨度>

标签: node.js selenium testing mocha.js selenium-firefoxdriver


【解决方案1】:

错误提示

确保在此测试中调用了 done() 回调。

您可以按如下方式注入done 回调:

it("Is visible", function(done) {
  //...
});

并设置每次测试完成的超时时间:

describe('...', function(){
  this.timeout(15000);

  it('...', function(done){
    this.timeout(15000);
    setTimeout(done, 15000);
  });
});

更多信息可以找到in the docs

还有一些known issues,所以我建议升级你的依赖项。

【讨论】:

  • 这个答案的前半部分是错误的。错误消息具有误导性。 OP 正在使用 Promise,返回 Promise 是 Mocha 等待异步测试所需的全部内容。特别是,在driver.get(...) 之后调用done() 将导致测试在get 操作完成之前完成。
  • 谢谢,我改变了答案,但现在可能不再有帮助了。
  • 正确,正如我对摩卡的理解,你只需要回报承诺。我也在使用after(function(done) { driver.quit().then(done); });
猜你喜欢
  • 1970-01-01
  • 2012-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-26
  • 1970-01-01
  • 1970-01-01
  • 2017-05-14
相关资源
最近更新 更多