【问题标题】:Protractor / Jasmine timing out on headless chromium - Error: Timeout - Async callback量角器/茉莉花在无头铬上超时 - 错误:超时 - 异步回调
【发布时间】:2020-06-11 19:38:12
【问题描述】:

大家好,所以我想用量角器和茉莉花来运行无头铬。我已经为 firefox 和 chrome 设置了一切,并且有头。当我无头运行 Firefox 时,它可以工作......当我尝试无头运行 chromium 时,它最终会超时。寻求一些帮助来解决这个问题。

我得到的错误是:

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

现在我已经在线阅读了一百万篇文章,并尝试增加超时时间并将完成添加到函数中......

这是我当前的代码:

Conf.js - 我在网上找到了一堆添加的参数和设置。我已经尝试了几乎所有的变化,但没有成功..

  exports.config = {
    framework: 'jasmine2',
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['spec.js'],
    allScriptsTimeout: 5000000,
    capabilities: {
        'directConnect': true,
        'browserName': 'chrome',
        "goog:chromeOptions": {
            args: ["--headless", "--remote-debugging-port=9222", "--verbose", "--disable-gpu", "--disable-web-security", "--window-size=800x600"],
            'binary': "/usr/bin/chromium-browser"
        }
    }
  };

Spec.js - 直接在他们的网站上使用 console.logs。所有的 console.logs 都按以下顺序 3、1、2 打印出来。这是我不确定是否正确的事情?描述是否应该等待它完成?它几乎感觉就像我的它永远不会回来......

    describe('angularjs homepage todo list', function() {
  it('should add a todo', function(done) {
    console.log("WOOO1");
    browser.get('https://angularjs.org');

    element(by.model('todoList.todoText')).sendKeys('write first protractor test');
    element(by.css('[value="add"]')).click();

    var todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(todoList.count()).toEqual(3);
    expect(todoList.get(2).getText()).toEqual('write first protractor test');

    // You wrote your first test, cross it off the list
    todoList.get(2).element(by.css('input')).click();
    var completedAmount = element.all(by.css('.done-true'));
    expect(completedAmount.count()).toEqual(2);
    console.log("WOO2");

  }, 15000);
  console.log("WOO3");
});

在此之后我发现了一些其他发现......当我转到 localhost:9222 时,我看到了

   Inspectable WebContents
data:text/html,<html></html>

data:text/html, 是一个链接,如果单击它会将我带到正在加载的远程 chrome 调试器 ... data:text/html,。这就是我认为问题所在。为什么这实际上从未加载 Angular 网站?

也许我不在基地,但有人知道如何理解这一点吗?

编辑: 额外的有用信息。 我在用 铬 79.0.3945.130 chromedriver 79.0.3945.36

茉莉花v3.5.0 jasmine-core v3.5.0

量角器 5.4.3

谢谢

【问题讨论】:

  • 您的控制台日志的顺序是正确的。规范文件中但在 It 块之外的任何代码都将在任何 It 块开始执行之前执行。我知道一开始可能会令人困惑,但只是意识到这是第一步。如果您认为无法在 headless chrome 中加载您的网站,您应该尝试添加一些屏幕截图,这些屏幕截图将被保存,您可以在之后查看
  • 我知道该站点是可访问的,因为它是一个公共 Angular 站点,并且在普通 chrome 中运行正常。提出的问题是量角器没有用正确的信息替换 data:text/html,。

标签: javascript selenium jasmine protractor selenium-chromedriver


【解决方案1】:

最终为我工作的配置

 exports.config = {
    framework: 'jasmine',
    allScriptsTimeout: 9000,
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['spec.js'],

    capabilities: {
    'directConnect': true,
    'browserName': 'chrome',
    "goog:chromeOptions": {
    args: ["--headless", "--remote-debugging-port=9222", "--verbose", "--disable-gpu", "--disable-web-security", "--window-size=800x600"],
    'binary': "path to chrome"
    }
    }
    };

【讨论】:

    【解决方案2】:

    在您的配置中添加 allScriptTimeOut,如下所示:

    exports.config = {
        capabilities: {
            'browserName': 'chrome'
        },
        framework: 'jasmine',
        specs: ['example_spec.js'],
        allScriptsTimeout: 9000
    };
    

    希望此链接对您有所帮助 https://www.protractortest.org/#/timeouts.

    【讨论】:

    • 嗨@Amato,我看到你是一个新用户,只是想让你知道只有链接的答案通常不被认为是很好的答案。有关更多信息,请参阅how to write good answers 上的常见问题解答中的此部分。虽然链接中的信息可能对 OP 有用,但它更适合作为评论(您现在确实有足够的代表可以添加,但希望很快就会:D)。
    • 感谢@DublinDev 的评论,我已经更新了我的答案
    • 我也试过这个配置,但没有解决。还有其他想法吗?对我来说,测试的运行时间不应超过几秒钟,因此将此值设置为 30-40 秒是荒谬的,而且还有另一个驱动因素......
    • @wdlax11 你试过用promise(然后是操作符)吗?
    • 不,但我让它以某种方式工作。一般来说,除了从 jasmine 2 到 jasmine 的 jasmine 之外,我没有更改原始配置中的任何内容
    猜你喜欢
    • 2017-06-10
    • 2015-11-26
    • 2016-09-05
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    • 2014-09-09
    • 2016-09-10
    • 2021-03-31
    相关资源
    最近更新 更多