Comments (16)
Can you provide the reproducing case (your usage of Mink that was working before and does not work anymore) ?
from mink.
<?php
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\MinkExtension\Context\RawMinkContext;
class MyAppContext extends RawMinkContext ...
{
/**
* @BeforeScenario
*/
public function setUpBeforeScenario(BeforeScenarioScope $scope)
{
// Workaround for https://github.com/minkphp/Mink/issues/798:
$this->getSession()->start();
// $this->getSession()->setCookie() fails as of minkphp/Mink ^1.8
if (\function_exists('xdebug_is_debugger_active') && xdebug_is_debugger_active()) {
$this->getSession()->setCookie('XDEBUG_SESSION', 'behat');
}
}
....
from mink.
For additional context, see https://travis-ci.com/github/lpeabody/Metis/builds/153721427#L1377 for an example of where this breaks. $this->page
evaluates to null
here https://gitlab.com/DMore/chrome-mink-driver/-/blob/2.7.0/src/ChromeDriver.php#L1058.
It's broken out more verbosely here https://gitlab.com/DMore/chrome-mink-driver/-/issues/94.
from mink.
@mpdude , actually I see no issue here.
In Selenium (which emulates user actions) you can't set a cookie on a page prior to that page being visited. Same goes for dmore/chrome-mink-driver
driver, which does the same as Selenium, but without Selenium in Google Chrome.
Setting headers (e.g. basic authentication, cookies, etc.) prior to page visiting is only possible in headless drivers, like MinkBrowserKitDriver
and MinkZombieDriver
.
The solution you came up with is correct way to do this. I'm not sure why it even worked, because you've set cookie right after browser window was opened, but prior to page being visited. In that case there is no way to determine at which URL cookie should apply.
from mink.
But I should be able to set a request header before requesting a page, right?
from mink.
But I should be able to set a request header before requesting a page, right?
@mpdude , I guess no. If you can't do this with Selenium you can't do it in dmore/chrome-mink-driver
driver, that controls actual web browser.
from mink.
I am not sure if we're talking about the same thing: The driver needs the start()
method to be called so it connects to the browser. But once that's done, you can add the cookies and/or headers, even before visiting the page.
Am I missing something?
from mink.
If that is how it works for that driver then it's good thing. It doesn't work that way with other drivers.
Maybe driver code needs to be updated to that it auto-starts session, when it's missing and somebody is attempting to set cookies.
from mink.
@aik099 I cross-posted this as an issue here and over at the driver's repo at https://gitlab.com/DMore/chrome-mink-driver/-/issues/94 because I know too little about the contracts between Mink and the drivers and I was unsure if this needs to be fixed in the driver or here.
Mink/src/Driver/DriverInterface.php
Lines 32 to 51 in 07c6a9f
Calling any action before visiting a page is an undefined behavior.
The only supported method calls on a fresh driver are [...]
- setRequestHeader()
If "fresh" means "not started", then probably the driver should not rely on start()
being called until the very last moment before visitPage()
?
from mink.
@mpdude , I guess no. If you can't do this with Selenium you can't do it in dmore/chrome-mink-driver driver, that controls actual web browser.
Selenium needs the browser to navigate to the cookie domain before being able to set a cookie. The chrome driver can technically set the cookie to base_url before visiting it, as long as ->start() is called before setCookie.
But since calling setCookie() before visit() is undefined behaviour, that doesn't have much practical value.
Maybe driver code needs to be updated to that it auto-starts session, when it's missing and somebody is attempting to set cookies.
It's possible, but is it a good idea? What if mink called stop() specifically and then we just overrule that with autostart. We'd essentially be taking control over start/stop/reset.
from mink.
Closing as @DorianCMore agreed to fix it on driver side in https://gitlab.com/DMore/chrome-mink-driver/-/issues/94.
from mink.
I'm failing to see where he has explicitly agreed to fix this in chrome-mink-driver?
from mink.
@lpeabody , here is a screenshot with relevant text selected from GitLab:
from mink.
There's an MR for this at https://gitlab.com/DMore/chrome-mink-driver/-/merge_requests/93 now.
Input / feedback welcome - @aik099 I'd especially welcome your thoughts on the solution, I'm pretty fresh to this!
from mink.
https://gitlab.com/DMore/chrome-mink-driver/-/merge_requests/93 does not fix the issue:
It fixes that you can set HTTP Basic Auth and/or request headers before calling visit()
, but it does not fix calls to setCookie()
.
You still can call the start()
method on the driver yourself and afterwards call setCookie()
, even before calling visit()
.
I find it hard to understand why setCookie()
should not be possible when setRequestHeader()
is. But that might be because setCookie()
is expected to have additional semantics (setting the cookie in the context of a page limits it to... the URL? Domain?) over just a "plain" request header.
from mink.
@xurizaemon , I've commented on that PR on GitLab website.
from mink.
Related Issues (20)
- Feature: set basic auth after session start and reset HOT 3
- PHP 8.1 compatible release HOT 10
- Element attribute not exists HOT 1
- symfony/css-selector 6.0 compatibility with behat/mink HOT 1
- Symfony 6 compatible release
- Mink's use of stripos leads to some empty string behaviors in PHP 8 HOT 3
- Element not interactable even though it is in view (scrolled to) and visible HOT 1
- Add case-sensitive comparison option to function WebAssert::elementContains HOT 5
- Empty read; connection dead HOT 1
- Support Browserless HOT 2
- GET Request HOT 2
- Allow custom processing of WebAssert::assert through callback HOT 9
- Is this project active? HOT 2
- Strictly typed methods HOT 3
- Class "Behat\Mink\Mink" not found HOT 5
- Release with Symfony 7
- responseHeaderEquals() can no longer be used to check for existence HOT 3
- submit form and get resulting page?! HOT 1
- Unable to switch to frame on Selenium 3.x HOT 7
- Switching windows by name or handle? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mink.