【问题标题】:Protractor tests in Docker - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVALDocker 中的量角器测试 - 在 jasmine.DEFAULT_TIMEOUT_INTERVAL 指定的超时内未调用异步回调
【发布时间】:2017-11-26 21:46:57
【问题描述】:

我已经为我的 Angular2 应用程序使用量角器编写了 6 个 e2e 测试。 测试在我的 windows 10 系统上运行良好。测试是一致的并且始终通过。

现在我尝试在 CentOS docker 容器中运行相同的测试。 测试不一致。他们一直在失败。

我收到一个错误提示

错误:超时 - 在 jasmine.DEFAULT_TIMEOUT_INTERVAL 指定的超时内未调用异步回调。

我增加了超时时间,我在需要的地方给出了 browser.wait(直到存在),我增加了分配给 docker 的计算资源(CPU-3,Memory-3328MB)。似乎没有任何效果。

 // Protractor configuration file, see link for more information  

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome',
    'chromeOptions': {
      'args': [ '--no-sandbox']
    }

  },
  directConnect: false,
  baseUrl: 'http://localhost:3200/',
  framework: 'jasmine2',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {
      // NOOP
    }
  },
  beforeLaunch: function() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
  },
  onPrepare() {
    browser.driver.manage().window().maximize();
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  }
};

其中一项测试

// create a user and he should be able to login after creation
  it('should add a new user and log him in successfully', () => {
    browser.wait(until.presenceOf(userCreate.forename, 5000, 'Timed out'));
    const forename = 'newUserFore' + generateRandom.generateRandom();
    const surename = 'newUserSur' + generateRandom.generateRandom();
    const username = 'newUserUser2' + generateRandom.generateRandom();
    const password = 'Pass@123' + generateRandom.generateRandom();

    userCreate.addUserWithPassword(forename, surename, username, password);
    // select language
    userCreate.selectDropdownByNumber(userCreate.mylang, 1);
    // select role
    userCreate.selectDropdownByNumber(userCreate.myrole, 1);
    // click add
    userCreate.addUserButton.click();
    browser.wait(until.presenceOf(userCreate.successMessage, 5000, 'Timed out'));
    expect(userCreate.successMessage.getText()).toContain('User saved successfully!');
    // cancelbutton
    userCreate.cancelbutton.click();
    browser.wait(until.presenceOf(userOverview.addUserButton, 5000, 'Timed out'));
    // logout
    indexPage = homePage.menu.navigateTo(MenuOption.LOGOUT, until);
    // click on login button on first page
    loginPage = indexPage.loginButtonClickedOnBasePage();
    // login with the credentials
    browser.wait(until.presenceOf(loginPage.loginTitle, 5000, 'Timed out'));
    loginPage.login(username, password);
    browser.wait(until.presenceOf(menu, 5000, 'Timed out'));
    expect(menu.isDisplayed()).toBe(true);
  });

功能测试文件,我首先启动服务器然后运行 ​​ui

     #!/usr/bin/env bash
    echo  "API: Ensuring the port $API_SERVER_PORT is freed."
    fuser -k -n tcp $API_SERVER_PORT


    echo " Starting the server in detached mode. This will take about 5 minutes the first time  "
    cd ../api && mvn spring-boot:run  -D server.port=$API_SERVER_PORT >> api-start.log 2>&1 &

    # Wait for the server to come up..
    while ! (ncat -w 1 127.0.0.1 $API_SERVER_PORT </dev/null >/dev/null 2>&1); do sleep 1; done
    echo "Server started on port $API_SERVER_PORT"


    echo "UI: Ensuring the port $UI_SERVER_PORT is freed."
    fuser -k -n tcp $UI_SERVER_PORT

    npm start >> ui-start.log 2>&1 &

    while ! (ncat -w 1 127.0.0.1 $UI_SERVER_PORT </dev/null >/dev/null 2>&1); do sleep 1; done
    echo "Angular app is running on port $UI_SERVER_PORT , startup logs is in start.log".

    protractor container.protractor.conf.js

【问题讨论】:

  • 似乎是服务延迟......当有异步服务调用时,这可能会发生
  • 我正在处理同样的事情,我们现在有 57 个规格。相同的基于 docker 的测试容器在我们的开发笔记本电脑上可以正常通过,但是当它们在 Jenkins docker 节点上运行时,每次出现超时问题都会在同一个地方失败。上周我更新了我们正在使用的 selenium 和 chromedriver 的版本,测试仍然失败,但后来他们失败了,原因相同。 (最初失败的规范没有问题。)
  • @anjunatl,如果对您有帮助,可以尝试这种处理异步规范的方式。 jasmine.github.io/2.4/…。我试过这个。在 Docker 容器中通过测试的概率增加了。但同样,它也不是完全证明的。 35 次测试中有 2 次失败。
  • @DebanjanaMaitra 你找到解决方案了吗?我面临着完全相同的问题。

标签: angular docker protractor


【解决方案1】:

您是否尝试将主机的 /dev/shm 卷挂载到容器中?

https://github.com/SeleniumHQ/docker-selenium#running-the-images

这显然是一种已知的解决方法,可以阻止 selenium 在 Docker 中与 Chrome 或 Firefox 一起崩溃。 selenium 崩溃并没有立即显现出来,它只是通过 Jasmine 超时来表达。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-10
    • 2021-03-31
    • 2016-04-21
    • 2017-10-23
    • 1970-01-01
    • 2018-07-30
    • 2016-05-30
    • 1970-01-01
    相关资源
    最近更新 更多