如何从 spectron-mocha-webdriverio 中的警告框中获取文本

How to get text from alertbox in spectron-mocha-webdiverio

我正在使用 spectron 测试我的电子应用程序。 我正在尝试从警报框获取文本,但出现错误。 我想从警报中获取文本,如果可以,则接受它。

测试:

it('Check alert message', function() {
        return this.app.client
            .waitForExist('#associates', 20000).should.eventually.equal(true)
            .click('#pq-associates')
            .click('#submit-selection')
            .alertText().should.eventually.equal("You have to select any one")
            .should.eventually.exist
    });

我收到以下错误

no alert open
Error: An attempt was made to operate on a modal dialog when one was not open.

但是我可以看到警报。

正如与 WebDriverio 社区讨论的那样,很难处理默认的 alert() 函数。他们建议实现我自己的类似 alert() 的函数。所以使用 https://github.com/limonte/sweetalert2 我实现了自己的警报并且测试工作正常。

社区讨论:https://gitter.im/webdriverio/webdriverio/archives/2017/10/04

Spectron 问题:https://github.com/electron/spectron/issues/23