mercredi 29 avril 2020

Laravel Dusk getting: "stale element reference: element is not attached to the page document"

Yesterday, I run my Laravel Dusk tests and they worked fine, today I run them and 8 out of the 13 fail, most of them with "stale element reference". I've made some modifications to the app but nothing that should require me to modify the tests.

I've updated the chrome driver using (thanks to staudenmeir/dusk-updater):

php artisan dusk:update 81

but that got me even more errors. Before doing that I got only 3 of my tests to fail now I've got 8.

I've tried googling the issue but nothing seems like a solution.

here are the first 3 errors I get:

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 

the other errors are of the same type as "stale element reference".

Here is also my 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.v.vasilev@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('Апартамента бе успешно изтрит.');
        });
    }
}

Any ideas appreciated.

Aucun commentaire:

Enregistrer un commentaire