user11664054
user11664054

Reputation: 13

Accessing PHP $_SESSION in FeatureContext file

I have a PHP file that generates a dynamic payment URL and saves it in $_SESSION['userDetails']. Now, I want to read/access that $_SESSION['userDetails'] value in my FeatureContext.php file under Behat. Can anyone please guide me on how to work on it?

I tried the following code, but it gives me Null for $cururl and some array for the $session...

use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Session;

class FeatureContext extends Context implements BehatContext, SnippetAcceptingContext
{
    protected $session;

    public function __construct()
    {
        if (defined('APP_MODE') && APP_MODE === 'DEV') {
            $baseUrl = 'http://localhost';
        } else {
            $baseUrl = 'http://MAINSITEurl';
        }

        parent::__construct($baseUrl);

        // ensure request factory is available
        $this->jsonUtility = JsonUtility::getInstance();
        $this->requestFactory = RequestFactory::getInstance();
        $this->arrayUtility = ArrayUtility::getInstance();
    }

    public function iAmRedirectedToPaymentPage()
    {
        $driver = new \Behat\Mink\Driver\Selenium2Driver('firefox');

        $session = new \Behat\Mink\Session($driver);

        // start the session
        $session->start();
        $cururl = $session->getCurrentUrl();
        var_dump($cururl);
        var_dump($session);
        die();
    }
}

Getting this as output for var_dump($session)

class Behat\Mink\Session#946 (3) {
  private $driver =>
  class Behat\Mink\Driver\Selenium2Driver#967 (8) {
    private $started =>
    bool(true)
    private $webDriver =>
    class WebDriver\WebDriver#944 (1) {
      protected $url =>
      string(28) "http://localhost:4444/wd/hub"
    }
    private $browserName =>
    string(7) "firefox"
    private $desiredCapabilities =>
    array(9) {
      'browserName' =>
      string(7) "firefox"
      'version' =>
      string(1) "9"

How to get $_SESSION['userDetails'] value in Behat??

Upvotes: 0

Views: 96

Answers (0)

Related Questions