Maintaining a session between scripts in one function file in runtime and mink mode

I have done a lot of R&D on this, but I cannot find a solution.

I need to maintain a login session between different scripts in a single function file. I made a function I am logged inand I wrote in the background. therefore, at the beginning of each script, a login occurs. but I want to maintain a single login session in scripts. Can anyone suggest.?

Example Code:

Feature: To test the output

Background:
  Given I am logged in 

@javascript
 Scenario: To test the positive input
   When I fill in "test" with "aab"
   And I press "add"
   Then I should see "welcome"

@javascript
  Scenario:To test the negative inputs
    When I fill in "test" with "@#$@!!111"
    And I press "add"
    Then I should see "Sorry,invalid input please try again"

, , . , , , 50 . . , , 15 . , , .

+4
2

. Behat . .

. .

, , , , . .

, , , Behat , . Mink, .

+4

! - AbstractWebDriver, webDriver.

FeatureContext

<?php
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;

/**
 * Defines application features from the specific context.
 */
class FeatureContext extends AbstractWebDriver
{
    /**
     * Initializes context.
     *
     * Every scenario gets its own context instance.
     * You can also pass arbitrary arguments to the
     * context constructor through behat.yml.
     */
    public function __construct()
    {
        $capabilities = DesiredCapabilities::safari();
        if(!AbstractWebDriver::$webDriver) {
            AbstractWebDriver::$webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities);
        }
        $this->baseUrl = "http://test.test.com";
    }
}

AbstractWebDriver

<?php

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;

/**
 * Defines application features from the specific context.
 */
abstract class AbstractWebDriver extends \PHPUnit\Framework\TestCase implements Context, SnippetAcceptingContext
{
    /**
     * @var \RemoteWebDriver
     */
    protected static $webDriver;
    protected $baseUrl;

protected function getDriver()
{
    if($this->webDriver==Null)
    echo "----------------- Instatiate New Driver -----------------";
    $capabilities = DesiredCapabilities::safari();
    self::$webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities);


    echo "----------------- Return Current Driver -----------------";
}



}

webDriver!

+1

All Articles