由于UnexpectedAlertOpenException,黄昏无法关闭对话框

时间:2019-04-23 08:50:15

标签: phpunit laravel-5.7 laravel-dusk

我正在使用Laravel Dusk为Laravel 5.7应用程序编写浏览器测试。在测试中,我导航到该页面并单击一个触发确认对话框的按钮。我正在尝试测试关闭该对话框不会更改页面网址。

我已经在运行测试之前尝试添加$this-expectException(UnexpectedAlertOpenException::class),以使代码理解应该显示一个对话框

    {
        $this->expectException(UnexpectedAlertOpenException::class);

        $this->browse(function (Browser $browser) {
            $browser->loginToWave()
                ->goToSystemsEdit();

            $browser->waitFor('@delete-systems-button')
                ->click('@delete-systems-button')
                ->assertDialogOpened('This will delete the system. Please seek advice before doing this. Continue?')
                ->dismissDialog()
                ->assertPathBeginsWith('systems/edit');
        });
    }

我希望测试能够关闭对话框并检查路径断言。

实际上发生的是抛出了UnexpectedAlertOpenException

1) Tests\Browser\Systems\DeleteSystemTest::testSystemNotDeletedIfConfirmIsDismissed
Facebook\WebDriver\Exception\UnexpectedAlertOpenException: unexpected alert open: {Alert text : This will delete the system. Please seek advice before doing this. Continue?}
  (Session info: chrome=71.0.3578.98)
  (Driver info: chromedriver=2.45.615279 (12b89733300bd268cff3b78fc76cb8f3a7cc44e5),platform=Linux 4.9.125-linuxkit x86_64)

/var/www/html/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:140
/var/www/html/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:326
/var/www/html/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:547
/var/www/html/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:345
/var/www/html/vendor/laravel/dusk/src/Browser.php:261
/var/www/html/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:139
/var/www/html/vendor/laravel/framework/src/Illuminate/Support/Collection.php:418
/var/www/html/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:140
/var/www/html/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:69
/var/www/html/tests/DuskTestCase.php:68

0 个答案:

没有答案