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
Add loginUser()
helper method to Panther client
#574
base: main
Are you sure you want to change the base?
Conversation
@plotbox-io Also wondering if this PR is even being considered? |
loginUser()
helper method to Panther client
The sheer number of assumptions baked into this is truly staggering. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not fond of the general approach. This will break in many cases (Panther on the host, the Symfony app in a Docker container). Also, this creates a hard coupling between Panther (the library) and the full-stack Symfony framework.
Couldn't we try an alternative approach like trying to log the user using HTTP Basic or some other kind of standard approach instead?
"symfony/http-kernel": "^5.3 || ^6.0", | ||
"symfony/process": "^5.3 || ^6.0" | ||
"symfony/process": "^5.3 || ^6.0", | ||
"symfony/security-core": "^5.3 || ^6.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package must be moved to require-dev
as it's already an optional dependency (an exception is thrown if the package isn't installed).
|
||
// Make a single request to avoid 'Invalid cookie domain' error when attempting to | ||
// set a cookie to the uninitialised web driver. The path does not matter for this | ||
$this->request('GET', '/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to be able to prevent this, at least if WebDriver is already initialized.
$this->request('GET', '/'); | ||
|
||
if (null === $sessionStorage) { | ||
$sessionStorage = new MockFileSessionStorage('/app/var/cache/panther/sessions'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should something like tempnam(sys_get_temp_dir(), 'panther-sessions');
instead. This hardcoded directory may not be writable.
I'm interested in other approaches if people have clever ideas. Auth is an extremely common use case, so some sort of panther support for it would be cool and would likely boost panther usage across the board |
HTTP Basic? |
We use form login, accross all of our apps, so I don't think HTTP Basic would be of much use to us, unfortunately. I'm open to ideas on how to reduce the number of assumptions and how to decouple it from the Symfony framework. If you look at the discussion in #283 you'll see that the code was directly taken from the symfony testing framework, with a little modification, because, the perfect situation for me would be to have to only change Maybe the |
You could enable HTTP Basic only for the |
I'm also not keen on basic auth. My actual site doesn't use it, and I want my tests to behave as closely to my live site as possible, including running through my real auth mechanism. I think allowing basic auth is fine, letting the implementer decide. But forcing it doesn't seem appealing. |
@arderyp that's the plan. You can already plug your custom auth logic if needed. |
Please see here for discussion context
When doing E2E testing, it is common to need to login a user to perform certain actions. We often don't care about the login process for 99% of our tests, but we must still perform the steps each time. This can add unneccesary time and complexity onto the tests that could be avoided if only we had a way to simulate logins.
It would be nice to have a helper function named loginUser() similar to the Application Test client. However, as we are doing E2E testing, we know that there is an added complexity of the environment settings of the alternate webserver (specifically how it handles session data). So, to solve this, we can pass SessionStorageInterface and firewallContext as arguments (but with sensisble defaults so they could be omitted in most cases).
Example of calling code would be:
Or simple (for most cases)
Have tested this approach (in userland code) and is working well for me. Was suggested in the discussion that I raise a PR for integration to Panther library code so here it is for your consideration. Please let me know if you need anything more from me.
Richard.