Skip to content

Commit

Permalink
MNT Keyboard test steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Feb 15, 2024
1 parent 99fd1ac commit 71bf4d6
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/Context/BasicContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use InvalidArgumentException;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
use Behat\Behat\Definition\Call;
use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
Expand All @@ -19,6 +18,7 @@
use Facebook\WebDriver\Exception\WebDriverException;
use Facebook\WebDriver\WebDriver;
use Facebook\WebDriver\WebDriverAlert;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverExpectedCondition;
use Facebook\WebDriver\WebDriverKeys;
use PHPUnit\Framework\Assert;
Expand Down Expand Up @@ -1583,4 +1583,46 @@ public function iFollowWithJavascript($locator)
}
$this->getSession()->executeScript("document.location.href = '{$href}';");
}

/**
* @Given /^I focus on the "([^"]+)" element$/
*/
public function iFocusOnTheElement(string $selector)
{
$page = $this->getSession()->getPage();
$element = $page->find('css', $selector);
Assert::assertNotNull($element, sprintf('Element %s not found', $selector));
$element->focus();
}

/**
* @Given /^I type "([^"]+)" in the field$/
*/
public function iTypeInTheField(string $data)
{
$driver = $this->getSession()->getDriver()->getWebDriver();
$driver->switchTo()->activeElement();
$keyboard = $driver->getKeyboard();
$keyboard->sendKeys([$data]);
}

/**
* @Given /^the active element should be "([^"]+)"$/
*/
public function theActiveElementShouldBe(string $selector)
{
$driver = $this->getSession()->getDriver()->getWebDriver();
$element = $driver->findElement(WebDriverBy::cssSelector($selector));
Assert::assertNotNull($element, sprintf('Element %s not found', $selector));
Assert::assertTrue($element->equals($driver->switchTo()->activeElement()));
}

/**
* @Given /^I type "([^"]+)" in the active element "([^"]+)"$/
*/
public function iTypeInTheActiveElement(string $data, string $selector)
{
$this->theActiveElementShouldBe($selector);
$this->iTypeInTheField($data);
}
}

0 comments on commit 71bf4d6

Please sign in to comment.