昨天,我运行了我的 Laravel Dusk 测试,它们运行良好,今天我运行它们,13 次测试中有 8 次失败,其中大多数带有“陈旧的元素参考”。我对应用程序进行了一些修改,但没有任何东西需要我修改测试。
我已经使用(感谢staudenmeir/dusk-updater
)更新了 chrome 驱动程序:
php artisan dusk:update 81
但这让我犯了更多错误。在此之前,我只有 3 个测试失败,现在我有 8 个。
我试过用谷歌搜索这个问题,但似乎没有什么是解决方案。
这是我得到的前 3 个错误:
1) Tests\Browser\ApartmentsTest::testApartments
Facebook\WebDriver\Exception\StaleElementReferenceException: stale element reference: element is not attached to the page document
(Session info: headless chrome=81.0.4044.122)
(Driver info: chromedriver=81.0.4044.69 (6813546031a4bc83f717a2ef7cd4ac6ec1199132-refs/branch-heads/4044@{#776}),platform=Linux 4.15.0-96-generic x86_64)
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:108
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:331
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:565
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Remote/RemoteExecuteMethod.php:40
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Remote/RemoteWebElement.php:332
/var/www/domovakniga.local/vendor/laravel/dusk/src/Concerns/InteractsWithElements.php:142
/var/www/domovakniga.local/tests/Browser/ApartmentsTest.php:25
/var/www/domovakniga.local/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:67
/var/www/domovakniga.local/tests/Browser/ApartmentsTest.php:67
2) Tests\Browser\BoardMembersTest::testExample
Facebook\WebDriver\Exception\StaleElementReferenceException: stale element reference: element is not attached to the page document
(Session info: headless chrome=81.0.4044.122)
(Driver info: chromedriver=81.0.4044.69 (6813546031a4bc83f717a2ef7cd4ac6ec1199132-refs/branch-heads/4044@{#776}),platform=Linux 4.15.0-96-generic x86_64)
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:108
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:331
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:565
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Remote/RemoteExecuteMethod.php:40
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Remote/RemoteWebElement.php:332
/var/www/domovakniga.local/vendor/laravel/dusk/src/Concerns/InteractsWithElements.php:142
/var/www/domovakniga.local/tests/Browser/BoardMembersTest.php:25
/var/www/domovakniga.local/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:67
/var/www/domovakniga.local/tests/Browser/BoardMembersTest.php:54
3) Tests\Browser\CashbookSettingsTest::testExample
Facebook\WebDriver\Exception\UnrecognizedExceptionException: element not interactable
(Session info: headless chrome=81.0.4044.122)
(Driver info: chromedriver=81.0.4044.69 (6813546031a4bc83f717a2ef7cd4ac6ec1199132-refs/branch-heads/4044@{#776}),platform=Linux 4.15.0-96-generic x86_64)
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:158
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:331
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:565
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Remote/RemoteExecuteMethod.php:40
/var/www/domovakniga.local/vendor/facebook/webdriver/lib/Remote/RemoteWebElement.php:332
/var/www/domovakniga.local/vendor/laravel/dusk/src/Concerns/InteractsWithElements.php:142
/var/www/domovakniga.local/tests/Browser/CashbookSettingsTest.php:25
/var/www/domovakniga.local/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:67
/var/www/domovakniga.local/tests/Browser/CashbookSettingsTest.php:32
其他错误与“stale element reference”属于同一类型。
这也是我的ApartmentsTest
:
<?php
namespace Tests\Browser;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ApartmentsTest extends DuskTestCase
{
/**
* Test if user can create and edit apartments
*
* @return void
*/
public function testApartments()
{
$this->browse(function (Browser $browser) {
$browser->visit('/login');
sleep(1);
$browser->click('#ok')
->waitForLocation('/login')
->type('email', 'peter@gmail.com')
->type('password', 'password')
->press('Вход')
->visit('/apartments/create')
->waitForLocation('/apartments/create')
->assertSee('Нов апартамент')
// select obekt
->click('.form-group:nth-child(2) .selectize-input')
->click('.form-group:nth-child(2) .selectize-dropdown .option:nth-child(2)')
->click('.panel-heading');
sleep(1.5);
// select entrance
$browser->click('.form-group:nth-child(3) .selectize-input')
->click('.form-group:nth-child(3) .selectize-dropdown .option:nth-child(1)')
->click('.panel-heading')
->select('type', 1)
->type('floor', 10)
->type('apt_number', 1)
->type('percent_ideal_parts', 10.00)
->type('taksa_fro', 2.50)
->type('taksa_domoupravitel', 5.00)
->type('starting_balance', 14.00)
->press('Запиши')
->assertSee('Апартамента беше запазен успешно.')
->assertPathIs('/entrances/2/apartments')
->visit('/apartments/21/edit')
->type('percent_ideal_parts', 12.50)
->press('Запиши')
->assertSee('Успешно актуализирахте апартамента.')
->visit('/apartments')
->type('.form-control-sm', '#2020221101');
sleep(1);
$browser->press('Изтрий')
->acceptDialog()
->waitForLocation('/apartments')
->assertSee('Апартамента бе успешно изтрит.');
});
}
}
任何想法表示赞赏。