Skip to content

Instantly share code, notes, and snippets.

@mashiox
Created May 14, 2018 21:08
Show Gist options
  • Save mashiox/2678857249eef68126fd92e150702305 to your computer and use it in GitHub Desktop.
Save mashiox/2678857249eef68126fd92e150702305 to your computer and use it in GitHub Desktop.
Example Mink code
#Note: this is only a snippet of what you need to add to behat.yml
default:
suite:
# Below is config that is required in behat.yml
ExampleTestsForLearning:
paths: [%paths.base%/feature/ExampleTestsForLearning]
contexts:
- ExampleTestsForLearningContext
Feature: EXamples
@work
Scenario: This is my example title
Given I am a "moderator"
When I load the page
Then I see "Account Login"
Given I am a "panelist"
When I load the page
Then I see "Account Login"
<?php
require_once(dirname(dirname(__FILE__)) . "/bootstrap/Utility/DIOIMAP.php");
use \Behat\MinkExtension\Context\MinkContext;
class ExampleTestsForLearningContext extends MinkContext
{
private $baseUrl;
private $userModel;
private $selectedUser;
private $role;
/**
* @BeforeScenario
*/
public function beforeScenario()
{
$this->baseUrl = getenv("TEST_TARGET_HOSTNAME", true); // qa.qual.life
$modPfx = "testerAgent" . mt_rand();
$panPfx = "testerAgent" . mt_rand();
$this->userModel = [
'moderator' => [
'key' => $modPfx, //testerAgent007
'password' => mt_rand() . "x0$#!",
'browser' => $this->getSession("session1"),
'email' => DIOIMAP::init($modPfx)
],
'panelist' => [
'key' => $panPfx, //"testerAgent0124578",
'password' => mt_rand() . "x0$#!",
'browser' => $this->getSession("session2"),
'email' => null
]
];
}
/**
* @Given I am a :role
*/
public function iAmA($role)
{
$role = strtolower($role);
switch ($role)
{
case "moderator":
case "panelist":
// $this->selectedUser = &$this->userModel[$role];
$this->role = $role;
break;
default:
throw new Exception("user error");
}
}
/**
* @When I load the page
*/
public function loadPage()
{
$emailBody = $this->userModel[$this->role]['email']->findEmail("Test Subject");
$this->userModel[$this->role]['browser']->visit($this->baseUrl);
}
/**
* @Then I see :text
*/
public function seeText($text)
{
$onPage = $this->userModel[$this->role]['browser']->getPage();
$value = $onPage->find(
'xpath',
sprintf('//*[contains(text(), "%s")]', $text)
);
PHPUnit_Framework_Assert::assertNotEmpty($value, 'The Value Exists!');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment