Skip to content

Commit

Permalink
[feature] allow Browser::click() to work with css selectors (#60)
Browse files Browse the repository at this point in the history
* Add Browser::clockOnElement()

* Allow CSS selectors

* Added a small test

* Merge into click()
  • Loading branch information
Nyholm authored Oct 2, 2021
1 parent db95a42 commit d555ce8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ final public function attachFile(string $selector, $filename): self
}

/**
* Click on a button, link or any DOM element.
*
* @return static
*/
final public function click(string $selector): self
Expand All @@ -268,7 +270,11 @@ final public function click(string $selector): self
$this->documentElement()->pressButton($selector);
} catch (ElementNotFoundException $e) {
// try link
$this->documentElement()->clickLink($selector);
try {
$this->documentElement()->clickLink($selector);
} catch (ElementNotFoundException $e) {
$this->documentElement()->find('css', $selector)->click();
}
}

return $this;
Expand Down
12 changes: 12 additions & 0 deletions tests/BrowserTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,18 @@ public function link_action(): void
;
}

/**
* @test
*/
public function click_on_element(): void
{
$this->browser()
->visit('/page1')
->click('#link a')
->assertOn('/page2')
;
}

/**
* @test
*/
Expand Down

0 comments on commit d555ce8

Please sign in to comment.