如何从spectron-mocha-webdiverio中的alertbox获取文本

时间:2017-10-03 18:21:01

标签: electron webdriver-io spectron

我正在使用光谱测试我的电子应用程序。 我试图从alertbox获取文本,但收到错误。 我希望从警报中获取文本,如果需要,则接受它。

测试:

$var1 = Get-ChildItem -Path "W:\Blabla" -Recurse | Where-Object { $_.CreationTime -gt (Get-Date).AddHours(-24) } | Select-Object Fullname,CreationTime
Out-File test-24.txt -InputObject $var1

$var2 = Select-String -Path test-24.txt -Pattern "pass|Angie" | select line
Out-File test-out.txt -InputObject $var2



$params = @{
    Uri = "https://hipchat.blabla.com/v2/room/456/notification?auth_token=????"
    Method = "POST"
    Body = @{
        color = 'red'
        message = "$var2"
        notify = $false
        message_format = "text"
    } | ConvertTo-Json
    ContentType = 'application/json'
}

Invoke-RestMethod @params

我收到以下错误

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

但我能看到警报。

1 个答案:

答案 0 :(得分:3)

正如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