Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99410

PHP webdriver + selenium + chromedriver not loading cookies from profile

$
0
0

I have

openjdk version "1.8.0_181"
ChromeDriver 2.42.591071
Google Chrome 69.0.3497.100
Selenium build info: version: '3.14.0'

And I am running a test with the current code snippet:

<?php

namespace Facebook\WebDriver;

use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Chrome\ChromeOptions;
ini_set("display_errors", "on");
error_reporting(E_ALL);
require_once('vendor/autoload.php');

// start Chrome with 5 second timeout
$host = 'http://localhost:4444/wd/hub';
$capabilities = DesiredCapabilities::chrome();
$options = new ChromeOptions();
$options->addArguments(array(
      '--headless',
      '--no-sandbox',
      '--window-size=1920,1080',
      'user-data-dir=/usr/share/nginx/html/browser/tmp/profile',
    ));
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = RemoteWebDriver::create($host, $capabilities, 5000);

$driver->get('http://example.com/browser/cookies.php');

$driver->takeScreenshot('/usr/share/nginx/html/browser/tmp/screen.png');

// close the browser
$driver->quit();
echo "<img src='tmp/screen.png' />";

The code in cookies.php is:

<?php
if(isset($_COOKIE['test'])){
    echo "It is set";
}else{
    setcookie("test", "testCookie");
    echo "Setting it ...";
}

I am expecting the cookie to be re-used on the second visit and so I will get "It is set", instead I am getting "setting it ..." regardless of how many time I request the page.

I checked the path for the profile, it was created successfully.

I also tried the page in my browser and it is working properly, so what am I missing here?

Thanks


Viewing all articles
Browse latest Browse all 99410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>