Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT Keyboard test steps #263

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 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;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated refactoring. We don't use this class in the code any more.

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,71 @@ 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$/
*
* This method is used to type into the active element.
* It's used to type into fields that are input fields and currently active (has focus).
* Should be used together with the step "I focus on the "selector" element"
*
* Example:
* When I focus on the "selector" element
* And I type "text" 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 "([^"]+)"$/
*
* Example: And the active element should be "selector"
*/
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 "([^"]+)"$/
*
* This method is used to type into the active element.
*
* Example: And I type "text" in the active element "selector"
*/
public function iTypeInTheActiveElement(string $data, string $selector)
{
$this->theActiveElementShouldBe($selector);
$this->iTypeInTheField($data);
}

/**
* Globally press the key i.e. not type into an input and confirm dialog
*
* @When /^I press the "([^"]+)" key and confirm the dialog$/
*/
public function iPressTheKeyAndConfirmTheDialog(string $key)
{
$this->iPressTheKeyGlobally($key);
$this->iConfirmTheDialog();
}
}
Loading