I want to log in to a remote address with DUSK and verify with 2FA at the same time.
$this->browse(function (Browser $browser) {
$browser->visit('https://www.domain.tld');
$browser->pause(300);
$browser->typeSlowly('input[type="text"]', '[email protected]');
$browser->pause(300);
$browser->typeSlowly('input[type="password"]', 'hereispassword');
$browser->pause(300);
$browser->click('button.button');
$browser->pause(300);
$browser->waitFor('input[type="number"]',2000);
$browser->typeSlowly('input[type="number"]', '268313');
$browser->pause(1000);
$browser->script('document.querySelector('[type="checkbox"]').checked = true;');
$browser->pause(1000);
$browser->click('button.button');
$browser->pause(1000);
$browser->visit('https://backoffice.domain.tld');
$browser->pause(2000);
#$this->saveCookies($browser);
});
I log in successfully, but after 2FA verification, I want it to remember that browser when I run the test again and not ask for 2FA again.
I wanted to write cookies to the cookie.txt file for this, but;
invalid cookie domain
hatası alıyorum.
private function saveCookies(Browser $browser) {
$cookies = $browser->driver->manage()->getCookies();
file_put_contents($this->cookie_file, serialize($cookies));
}
private function loadCookies(Browser $browser) {
if (file_exists($this->cookie_file)) {
//Get cookies from storage
$cookies = unserialize(file_get_contents($this->cookie_file));
//Add each cookie to this session
foreach ($cookies as $key => $cookie) {
$browser->driver->manage()->addCookie($cookie);
}
}
}
This is the part where I store the cookies and try to reload them? Where could I be making a mistake?
Thanks.