Search code examples
electronwebdriver-iospectron

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


I am testing my electron app using spectron. I am trying to get text from alertbox but getting an error. I want to get the text from alert and if that is expected then accept it.

Test :

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
    });

I am getting the following error

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

But I can see the alert.


Solution

  • As discussed with the WebDriverio community it is difficult to handle the default alert() function. They suggested to implement my own alert() like function. So using https://github.com/limonte/sweetalert2 I implemented my own alert and the test is working fine.

    Community discussion : https://gitter.im/webdriverio/webdriverio/archives/2017/10/04

    Spectron issue : https://github.com/electron/spectron/issues/23