-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Add extra trait to control the Neos Backend
- Loading branch information
1 parent
d7706c2
commit fd6b887
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace Sandstorm\E2ETestTools\Tests\Behavior\Bootstrap; | ||
|
||
use Neos\Flow\ObjectManagement\ObjectManagerInterface; | ||
use Neos\Flow\Persistence\PersistenceManagerInterface; | ||
use Neos\Neos\Domain\Service\UserService; | ||
use PHPUnit\Framework\Assert; | ||
|
||
trait NeosBackendControlTrait | ||
{ | ||
abstract public function getObjectManager(): ObjectManagerInterface; | ||
|
||
/** | ||
* @Given I have a Neos backend user :username with password :password and role :role | ||
*/ | ||
public function iHaveANeosBackendUserWithPasswordAndRole(string $username, string $password, string $role) | ||
{ | ||
$this->getObjectManager()->get(UserService::class)->createUser($username, $password, 'Test', 'Test', [$role]); | ||
$this->getObjectManager()->get(PersistenceManagerInterface::class)->persistAll(); | ||
} | ||
|
||
/** | ||
* @When I log into the backend using credentials :username :password | ||
*/ | ||
public function iLogIntoTheBackendUsingCredentials(string $username, string $password) | ||
{ | ||
$this->playwrightConnector->execute($this->playwrightContext, sprintf(' | ||
vars.page = await context.newPage(); | ||
await vars.page.goto("BASEURL/neos/"); | ||
await vars.page.fill("[placeholder=\"Username\"]", "%s"); | ||
await vars.page.fill("[placeholder=\"Password\"]", "%s"); | ||
await vars.page.click("button:has-text(\"Login\")"); | ||
await vars.page.waitForNavigation(); | ||
', $username, $password)); | ||
} | ||
|
||
/** | ||
* @When I click the main menu item :menuItem | ||
*/ | ||
public function iClickTheMainMenuItem($menuItem) | ||
{ | ||
$this->playwrightConnector->execute($this->playwrightContext, sprintf(' | ||
// open the main menu | ||
await vars.page.click(`[aria-label="Menu"]`); | ||
await vars.page.click(`button[role="button"]:has-text("%s")`); | ||
', $menuItem)); | ||
} | ||
|
||
/** | ||
* @When I click the overview dashboard tile :tileTitle | ||
*/ | ||
public function iClickTheDashboardOverviewTile($tileTitle) | ||
{ | ||
$this->playwrightConnector->execute($this->playwrightContext, sprintf(' | ||
await vars.page.click(`text=%s`); | ||
', $tileTitle)); | ||
} | ||
|
||
/** | ||
* @Then the URI path should be :uriPath | ||
*/ | ||
public function theUriPathShouldBe($uriPath) | ||
{ | ||
$actual = $this->playwrightConnector->execute($this->playwrightContext,' | ||
return vars.page.evaluate(() => window.location.pathname); | ||
'); | ||
Assert::assertEquals(rtrim($uriPath, '/'), rtrim($actual, '/')); | ||
} | ||
|
||
/** | ||
* @Then there should be the text :expected on the page | ||
*/ | ||
public function thereShouldBeTheTextOnThePage($expected) | ||
{ | ||
$this->playwrightConnector->execute($this->playwrightContext, sprintf(' | ||
await vars.page.textContent(`text=%s`); | ||
', $expected)); | ||
} | ||
|
||
/** | ||
* @When I access the URI path :uriPath | ||
*/ | ||
public function iAccess($uriPath) | ||
{ | ||
$this->playwrightConnector->execute($this->playwrightContext, sprintf(' | ||
vars.page = await context.newPage(); | ||
await vars.page.goto("BASEURL%s"); | ||
', $uriPath)); | ||
} | ||
} |