【问题标题】:Protractor asynchronous parallel testing on docker containersDocker 容器上的 Protractor 异步并行测试
【发布时间】:2019-02-12 23:00:01
【问题描述】:

几天来,我一直在努力使用 selenium docker 并行执行测试。

以下场景:

  • 使用规范在 multiCapabilities 中定义浏览器。
  • 使用 selenium-hub、2 个 firefox、2 个 chrome 节点部署容器。
  • 运行测试

当 chrome 和 firefox 并行运行相同的规范时,就会出现问题。 根据执行速度,假设 Firefox 是第一个,chrome 是第二个。 (spec1 同时在两个浏览器上运行)。

由于依赖 spec1 在 firefox 上成功(如预期的那样),而在 chrome 上它应该失败并出现异常(如预期的那样)。这是有趣的部分:

firefox 测试结束,但 chrome 挂起(它抛出异常的部分)并且在配置的 jasmine/test 超时后测试失败,假设 3 分钟 “未解决的承诺”.... 由于我已经在方法上等待,并且我已经将它包装在 try catch 中,所以异常应该进行测试,在那里我也将测试方法包装在 try catch 中,如果有异常 done.fail() 应该停止测试。

但它永远不会去那里......经过长时间的调试,我唯一能看到它的异常被抛出并且它永远不会进入我应该捕获它并且测试失败的测试。

多功能配置

{
    browserName: 'chrome',
    shardTestFiles: true,
    maxInstances: 2,
    specs: [
        '../spec/**/spec1.js'
    ]
},
    {
    browserName: 'firefox',
    maxInstances: 2,
    shardTestFiles: true,
    marionette: true,
    specs: [
        '../spec/**/spec1.js'
    ]
},

量角器专用:

    SELENIUM_PROMISE_MANAGER: false,
    seleniumAddress: 'ip of the selenium hub'
    maxSessions: 4
    framework: 'jasmine'
    ... and other custom not related props as loggers, reporters etc.

测试示例:

describe('test 1', () => {

    it('can done something', async (done) => {
        try {
            await doSomething();
        } catch (e) {
            done.fail(e);
        }

        done();
    }, 1000 * 60 * 5);
}

如果 doSomething() 发生异常,测试应该被强制失败,但它会在并行执行中挂起。

在不同的浏览器上执行相同的测试时,我是否遗漏了什么和/或你能建议它为什么挂起?

如果您需要更多信息,请告诉我。

【问题讨论】:

    标签: selenium selenium-webdriver jasmine protractor


    【解决方案1】:

    此类回调不适用于异步。如果您想通过测试,您可以更轻松:

    describe('test 1', () => {
    
        it('can done something', async () => {
            try {
                await doSomething();
            } catch (e) {
                throw new Error(e);
            }
        }
    }
    

    附:我强烈建议使用 Selenoid 在容器中运行 e2e 测试。

    【讨论】:

    • 您好,感谢您的回复,但您不正确他们工作得很好,因为如果调用了 done.fail(),茉莉花会停止任务并将测试标记为失败。问题是测试堆栈没有达到这一点。它只是从茉莉花默认超时配置超时。
    • 你能尝试在没有done 的情况下重写吗? ;) 我只是想知道它如何与throw new Error(e) 一起使用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多