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

add clickAll #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions src/Extensions/Selenium.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,46 @@ public function click($name)

return $this;
}

/**
* Click all elements in a Collection using a variable as the variable
* eg. ->clickAll(Confirmations::all(), 'label[for={$1}]', 'slug')
* the Confirmation Model would have a slug field which populates
* the <label for="{{ $confirmation->slug }}"> field
*
* @param Collection $elements
* @param string $selector
* @param string $variable
* @return static
*/
public function clickAll($elements, $selector, $variable)
{
$page = $this->currentPage();

foreach($elements as $element)
{
$name = str_replace('{$1}', $element->{$variable}, $selector);
try {
$link = $this->findByBody($name)->click();
} catch (InvalidArgumentException $e) {
try {
$link = $this->findByCss($name)->click();
} catch (InvalidArgumentException $e) {
$link = $this->findByNameOrId($name)->click();
}
}
}

$this->updateCurrentUrl();

$this->assertPageLoaded(
$page,
"Successfully clicked on a link with a body, name, or class of '{$name}', " .
"but its destination, {$page}, did not produce a 200 status code."
);

return $this;
}

/**
* Find an element by its text content.
Expand Down