Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loginAs() method doesn't hit the internal Dusk endpoint #210

Closed
pavoltanuska opened this issue Apr 3, 2017 · 7 comments
Closed

loginAs() method doesn't hit the internal Dusk endpoint #210

pavoltanuska opened this issue Apr 3, 2017 · 7 comments

Comments

@pavoltanuska
Copy link

pavoltanuska commented Apr 3, 2017

When I try to log the user in via $browser->loginAs(1) method, the request isn't received by Dusk's UserController.

However, if I hit the endpoint manually in my test via $browser->visit('/_dusk/login/1') everything works correctly.

I can confirm, that Dusk emits the request via Browser->visit($url) in both cases, but the request sent by the loginAs() method never reaches the UserController.

I'm willing to help and provide more info, but I'm not sure how to debug this one further.

Edit: It seems that both of these requests need to be made, to make the test work. See the next comment for details

@pavoltanuska
Copy link
Author

The issue seems to be a little bit deeper than I previously thought.

I'll give you the full scenario here:

  • I have a test called LoginWorkflowTest
  • 1st method I run - testBaseUrlRedirectsToLogin()
    • go to /admin URL
    • see if I'm being redirected to /admin/login correctly - this step is ok
  • 2nd method - testSuccessfulLogin()
    • create the Admin user
    • go directly to /admin/login
    • punch in the credentials and press submit
    • I should be redirected to /admin/dashboard - and I am (this is correct)
  • 3rd method (the problematic one) - testSuccessfulLogout()
    • create the Admin user
    • log in as Admin user
    • go to /admin/dashboard - I should not be redirected elsewhere
    • click Logout
    • should be redirected to /admin/login

And now my observations:

  • If I run the tests like specified, the last test fails (I'm not correctly logged in, so I'm redirected from dashboard to login)
  • If I skip the second test, everything runs ok
  • If I precede the loginAs() method in the third test method with whatever link (e.g. visit('/admin/login') and I run the loginAs() after that, everything runs correctly again
  • If I run the third test in second browser instance, it works correctly

It seems like some issue with sessions, but I'm not sure what could be the problem here.
Is there something more I should do/test?

@deleugpn
Copy link
Contributor

deleugpn commented Apr 3, 2017

Take a look at discussion on #100

@axyr
Copy link

axyr commented Apr 13, 2017

I'm having the same problem.

Everything after the click method will error.

public function test_it_logs_a_user_in_and_out()
{
    $user = factory(user_model())->create();

    $this->browse(function (Browser $browser) use ($user) {
        $browser
            ->visit(route('admin.login'))
            ->type('email', $user->email)
            ->type('password', 'secret')
            ->click('.loginscreen form button')
            ->assertRouteIs('admin.index')
            ->assertSee($user->name)
            ->click('#wrapper a.logout')
            // everything after the click will error
            //->assertDontSee($user->name)
            //->assertPathIs('admin/login')
        ;
    });
}
There was 1 error:

1) Tests\Browser\AuthenticationTest::test_it_logs_a_user_in_and_out
Facebook\WebDriver\Exception\NoSuchDriverException: no such session
(Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.1 x86_64)

/path/to/project/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:100
/path/to/project/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:320
/path/to/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:535
/path/to/project/vendor/facebook/webdriver/lib/Remote/RemoteExecuteMethod.php:40
/path/to/project/vendor/facebook/webdriver/lib/WebDriverOptions.php:157
/path/to/project/vendor/laravel/dusk/src/Browser.php:232
/path/to/project/vendor/laravel/dusk/src/TestCase.php:171
/path/to/project/vendor/laravel/framework/src/Illuminate/Support/Collection.php:260
/path/to/project/vendor/laravel/dusk/src/TestCase.php:172
/path/to/project/vendor/laravel/dusk/src/TestCase.php:100
/path/to/project/tests/Browser/AuthenticationTest.php:37

Caused by
Facebook\WebDriver\Exception\UnknownServerException: unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed
(Session info: chrome=57.0.2987.133)
  (Driver info: chromedriver=2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f),platform=Mac OS X 10.12.1 x86_64)

/path/to/project/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:114
/path/to/project/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:320
/path/to/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:535
/path/to/project/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:333
/path/to/project/vendor/laravel/dusk/src/Browser.php:219
/path/to/project/vendor/laravel/dusk/src/TestCase.php:158
/path/to/project/vendor/laravel/framework/src/Illuminate/Support/Collection.php:260
/path/to/project/vendor/laravel/dusk/src/TestCase.php:159
/path/to/project/vendor/laravel/dusk/src/TestCase.php:92
/path/to/project/tests/Browser/AuthenticationTest.php:37

@deleugpn
Copy link
Contributor

@axyr That's not the same problem. Your Google Chrome is crashing. Check if there's any screenshot of the crash in the folder.

@axyr
Copy link

axyr commented Apr 13, 2017

Ok. hm sry. I thought it was related because the issue both occurs when testing authentication. but yes I read it wrong.

@deleugpn
Copy link
Contributor

@pavoltanuska you still need support? Can this be closed?

@pavoltanuska
Copy link
Author

Well, I don't need further support, since there are workarounds in the thread you've linked here (thanks for that).

And as #100 probably covers this issue better, I agree that this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants