File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -1663,6 +1663,31 @@ public function iFocusOnTheElement(string $selector)
16631663 $ element ->focus ();
16641664 }
16651665
1666+ /**
1667+ * Checks if an element has focus.
1668+ *
1669+ * Example: Then the ".some-css-selector" element should have focus
1670+ * @Then /^the "([^"]*)" element should have focus$/
1671+ */
1672+ public function theFieldShouldHaveFocus (string $ selector )
1673+ {
1674+ $ page = $ this ->getSession ()->getPage ();
1675+ $ element = $ page ->find ('css ' , $ selector );
1676+ Assert::assertNotNull ($ element , sprintf ('Element %s not found ' , $ selector ));
1677+ $ sel = str_replace ('" ' , '\\" ' , $ selector );
1678+ $ script = <<<JS
1679+ return (function() {
1680+ var el = document.querySelector(" $ sel");
1681+ if (!el) {
1682+ return false;
1683+ }
1684+ return el == document.activeElement;
1685+ })();
1686+ JS ;
1687+ $ res = $ this ->getSession ()->evaluateScript ($ script );
1688+ Assert::assertTrue ($ res );
1689+ }
1690+
16661691 /**
16671692 * @Given /^I type "([^"]+)" in the field$/
16681693 *
You can’t perform that action at this time.
0 commit comments