如何从Spectron-Mocha-webdiverio中的Alertbox获取文本



我正在使用Spectron测试我的电子应用。我正在尝试从Alertbox获取文本,但会出现错误。我想从警报中获取文本,如果可以接受,请接受。

测试:

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()函数。他们建议实现我自己的警报()类似功能。因此,使用https://github.com/limonte/sweetalert2我实现了自己的警报,并且测试正常。

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

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

最新更新