できる!解決策を見つけたところです。webDriver の静的インスタンスを維持する AbstractWebDriver クラスを作成する必要があります。
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 -----------------";
}
}
1 つの機能ファイルに対して、webDriver の 1 つのインスタンスで複数のシナリオを実行できるようになりました!