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

Use better technique to determine whether user is logged in #131 #237

Merged
merged 4 commits into from
Dec 14, 2015

Conversation

LionsAd
Copy link
Contributor

@LionsAd LionsAd commented Dec 13, 2015

Based heavily on #131

This makes Drupal 7 work for themes without logout link on front-page and also makes Drupal 8 minimal profile, which uses stark work.

For most cases it can also avoid the visit to an additional page, which is great.

Original report

Not all websites have the logout link on the front page, in my case, Chrome with Selenium was simply to fast, admin-menu showed up after the check for the link happened.

Since there is no real 100% reliable method in D7, I've implemented two more methods to determine if a user is logged in. (D8 has the user information in the global Drupal Javascript object)

First test: Check for a "logged-in" class on the body element, most themes support this. (Mothership for example doesn't)
Second test: Visit "/user/login", if there is no login form, the user should be logged in.

I also had the Idea to simple check "/user/login" for a 403 status code, but this is not supported by Selenium because it is out of scope. (https://code.google.com/p/selenium/issues/detail?id=141)

@jhedstrom jhedstrom added this to the 3.2.0 release milestone Dec 14, 2015
@jhedstrom
Copy link
Owner

Since there is no real 100% reliable method in D7, I've implemented two more methods to determine if a user is logged in. (D8 has the user information in the global Drupal Javascript object)

Any idea how much work it would be to add the D8-logic to the Drupal Drivers, and use that here (I assume it would not require making the redundant page load)?

jhedstrom added a commit that referenced this pull request Dec 14, 2015
Use better technique to determine whether user is logged in #131
@jhedstrom jhedstrom merged commit 9dc38c5 into jhedstrom:master Dec 14, 2015
@jhedstrom
Copy link
Owner

Thanks for this!

@dman-coders
Copy link

Thanks for this.
Took me an hour to trace and eventually deduce the same fix (admin-menu in use on D7 meant I was better to look for the logged-in class on the body)
before I had enough background to trace the issue back to the issue queue to find myself here.

Now it seems I just have to use yesterdays git release. :-} Goody, I guess.

(++ works for me BTW!)

@austinmcorso
Copy link

++ thank you for this

@generalconsensus
Copy link

++ thank you for this! phantomjs was breaking because of the loggedIn() function

generalconsensus added a commit to forumone/drupalextension that referenced this pull request Jan 20, 2016
@generalconsensus
Copy link

@jhedstrom @LionsAd Due to the inherent complexity of upgrading Behat to the latest dev release to be able to benefit from this functionality, would it be possible to patch earlier versions with this? Like say 1.0?

@jhedstrom
Copy link
Owner

@generalconsensus I'd certainly review a PR for this fix against 1.x.

@generalconsensus
Copy link

@jhedstrom Thanks! Here is the P.R. #247

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

Successfully merging this pull request may close these issues.

5 participants