Я пытаюсь изучить BDD в PHP с помощью Behat и Mink, и я использую драйвер Selenium2 для того же.
Мой вопрос: как после завершения тестов программно закрыть каждое окно/вкладку браузера, которые открывает Selenium2? Поскольку закрытие такого количества окон/вкладок браузера каждый раз после каждого теста занимает много времени.
Я вижу, что есть некоторые варианты, которые позволяют сделать то же самое на Java, родном языке Selenium2 (я также использую файл .jar), но в PHP я не смог найти эквивалент.
Примечание.
Для получения дополнительной информации я включил код, который я пытаюсь.
Я пытаюсь написать FeatureContext.php
вместо example.feature
на этой странице, что является:
# features/search.feature
Feature: Search
In order to see a word definition
As a website user
I need to be able to search for a word
Scenario: Searching for a page that does exist
Given I am on "/wiki/Main_Page"
When I fill in "search" with "Behavior Driven Development"
And I press "searchButton"
Then I should see "agile software development"
Scenario: Searching for a page that does NOT exist
Given I am on "/wiki/Main_Page"
When I fill in "search" with "Glory Driven Development"
And I press "searchButton"
Then I should see "Search results"
Мой FeatureContext.php
выглядит следующим образом:
<?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;
/**
* Defines application features from the specific context.
*/
class FeatureContext implements Context, SnippetAcceptingContext
{
/**
* 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()
{
$this->driver = new \Behat\Mink\Driver\Selenium2Driver('firefox');
$this->session = new \Behat\Mink\Session($this->driver);
$this->session->start();
}
/**
* @Given I am on :url
*/
public function iAmOn($url)
{
$this->session->visit('http://en.wikipedia.org'.$url);
}
/**
* @When I fill in :field with :text
*/
public function iFillInWith($field, $text)
{
$this
->session
->getPage()
->find('css', '[type=' . $field . ']')
->setValue($text);
}
/**
* @When I press :button
*/
public function iPress($button)
{
$this
->session
->getPage()
->find('css', '[id=' . $button . ']')
->press();
}
/**
* @Then I should see :text
*/
public function iShouldSee($text)
{
$title = $this
->session
->getPage()
->find('css', 'h1')
->getText();
if ($title !== $text) {
new Exception('Invalid page');
}
$this->driver->close();
}
}