thejci's avatar

Test error in Dusk

This is the code for my tests both of the first tests are passing, but the last one for the password will not and keeps erroring. I will post the error in the comments.


namespace Tests\Browser\Auth;

use Illuminate\Foundation\Testing\DatabaseTruncation;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use Tests\Browser\Pages\Auth\Profile;
use Tests\Browser\Pages\Auth\Login;

class ProfileTest extends DuskTestCase
{
    use DatabaseTruncation;

    private $defaultUser = null;

    /**
     * Setup for profile tests.
     */
    public function setUp(): void
    {
        parent::setUp();
        $this->defaultUser = $this->createUser();
    }

    /**
     * Test unauthenticated users are redirected to login.
     */
    public function testUnauthenticatedUsersRedirectedToLogin(): void
    {
        $this->browse(function (Browser $browser) {
            $browser->visit((new Profile)->url())
                    ->assertPathIs((new Login)->url());
        });
    }

    /**
     * Test authenticated users can access the profile information form
     * and that if functions correctly.
     */
    public function testProfileFormAccessibleToAuthenticatedUsers(): void
    {
        $this->browse(function (Browser $browser) {
            $browser->loginAs($this->defaultUser);
            $browser->visit(new Profile);
            $browser->assertDisabled("@email");
            $browser->assertDisabled("@username");
            $browser->type("@firstName", "")
                    ->type("@middleName", "middle")
                    ->type("@lastName", "last")
                    ->press("@saveProfileButton")
                    ->refresh()
                    ->assertInputValueIsNot("@firstName", "");
            $browser->type("@firstName", "first")
                    ->type("@middleName", "middle")
                    ->type("@lastName", "last")
                    ->press("@saveProfileButton")
                    ->refresh()
                    ->assertInputValue("@middleName", "middle");
            $browser->type("@firstName", "first")
                    ->type("@middleName", "middle")
                    ->type("@lastName", "")
                    ->press("@saveProfileButton")
                    ->refresh()
                    ->assertInputValueIsNot("@lastName", "");
            $browser->type("@firstName", "first")
                    ->type("@middleName", "middle")
                    ->type("@lastName", "last")
                    ->pressAndWaitFor("@saveProfileButton")
                    ->assertSee("Saved.");
            });
    }

    public function testPasswordFormAccessibleToAuthenticatedUsers(): void
    {
        $this->browse(function (Browser $browser) {
            $browser->loginAs($this->defaultUser);
            $browser->visit(new Profile);
            $browser->type("@currentPassword", "")
                    ->type("@password", "Password")
                    ->type("@passwordConfirmation", "Password")
                    ->press("@savePasswordButton")
                    ->refresh()
                    ->assertInputValueIsNot("@currentPassword", "");
            $browser->type("@currentPassword", "currentPassword")
                    ->type("@password", "")
                    ->type("@passwordConfirmation", "Password")
                    ->press("@savePasswordButton")
                    ->refresh()
                    ->assertInputValueIsNot("@password", "");
            $browser->type("@currentPassword", "currentPassword")
                    ->type("@password", "Password")
                    ->type("@passwordConfirmation", "")
                    ->press("@savePasswordButton")
                    ->refresh()
                    ->assertInputValueIsNot("@passwordConfirmation", "");
            $browser->type("@currentPassword", "currentPassword")
                    ->type("@password", "Password")
                    ->type("@passwordConfirmation", "Password")
                    ->pressAndWaitFor("@savePasswordButton")
                    ->assertSee("Saved.");
            });

    }
}
0 likes
2 replies
thejci's avatar

This is the error. There was 1 error:

  1. Tests\Browser\Auth\ProfileTest::testPasswordFormAccessibleToAuthenticatedUsers Facebook\WebDriver\Exception\UnexpectedAlertOpenException: unexpected alert open: {Alert text : This page has expired. Would you like to refresh the page?} (Session info: chrome=110.0.5481.77)

/var/www/html/vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:142 /var/www/html/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:359 /var/www/html/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:605 /var/www/html/vendor/php-webdriver/webdriver/lib/Remote/RemoteExecuteMethod.php:23 /var/www/html/vendor/php-webdriver/webdriver/lib/WebDriverNavigation.php:41 /var/www/html/vendor/laravel/dusk/src/Browser.php:185 /var/www/html/tests/Browser/Auth/ProfileTest.php:78 /var/www/html/vendor/laravel/dusk/src/Concerns/ProvidesBrowser.php:70 /var/www/html/tests/Browser/Auth/ProfileTest.php:76

thejci's avatar

I can see the $browser->visit(new Profile); line is causing the issue, I am just not sure why when the same style of tests pass with similar conditions above.

Please or to participate in this conversation.