Skip to content

Commit

Permalink
Fixed action sequence to include multiple actions of same name. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
DavertMik committed Mar 20, 2017
1 parent b3856b9 commit 2bfcd4e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Codeception/Module/WebDriver.php
Expand Up @@ -2942,7 +2942,9 @@ public function performOn($element, $actions, $timeout = 10)
if (!is_array($actions)) {
throw new \InvalidArgumentException("2nd parameter, actions should be a valid callable or array");
}
foreach ($actions as $action => $value) {
foreach ($actions as $actionDefinition => $value) {
$actionDefinition = explode('.', $actionDefinition);
$action = end($actionDefinition);
if (!is_array($value)) {
$value = [$value];
}
Expand Down
6 changes: 5 additions & 1 deletion src/Codeception/Util/ActionSequence.php
Expand Up @@ -43,6 +43,8 @@ class ActionSequence
{
protected $actions = [];

private $counter = 1;

/**
* Creates an instance
* @return ActionSequence
Expand All @@ -54,7 +56,9 @@ public static function build()

public function __call($action, $arguments)
{
$this->actions[$action] = $arguments;
$key = "{$this->counter}.$action";
$this->actions[$key] = $arguments;
$this->counter++;
return $this;
}

Expand Down
14 changes: 13 additions & 1 deletion tests/web/WebDriverTest.php
Expand Up @@ -946,7 +946,6 @@ public function testPerformOnWithCallback()
$this->module->see('Login');
}


public function testPerformOnWithBuiltArray()
{
$asserts = \PHPUnit\Framework\Assert::getCount();
Expand All @@ -960,6 +959,19 @@ public function testPerformOnWithBuiltArray()
$this->module->see('Login');
}

public function testPerformOnWithArrayAndSimilarActions()
{
$asserts = \PHPUnit\Framework\Assert::getCount();
$this->module->amOnPage('/form/example1');
$this->module->performOn('.rememberMe', \Codeception\Util\ActionSequence::build()
->see('Remember me')
->see('next time')
->dontSee('Login')
);
$this->assertEquals(3, \PHPUnit\Framework\Assert::getCount() - $asserts);
$this->module->see('Login');
}

public function testPerformOnFail()
{
$this->shouldFail();
Expand Down

0 comments on commit 2bfcd4e

Please sign in to comment.