18. featureの
Feature: facebook login
facebook login
@javascript
Scenario: facebook login
Given on facebook login page.
When input email and password.
And press login button
Then facebook logged in.
19. Contextの
<?php
use Behat¥Behat¥Context¥ClosuredContextInterface,
Behat¥Behat¥Context¥TranslatedContextInterface,
Behat¥Behat¥Context¥BehatContext,
Behat¥Behat¥Exception¥PendingException;
use Behat¥Gherkin¥Node¥PyStringNode,
Behat¥Gherkin¥Node¥TableNode;
class FacebookloginContext extends BehatContext
{
public $mink;
public function __construct($mink)
{
$this->mink = $mink;
}
(続く)
20. Contextの
/**
* @Given /^on facebook login page¥.$/
*/
public function onFacebookLoginPage()
{
$this->mink->getSession()-
>visit('http://www.facebook.com/login.php');
}
/**
* @When /^input email and password¥.$/
*/
public function inputEmailAndPassword()
{
$this->mink->getSession()->getPage()->fillField('email',
MAIN_EMAIL);
$this->mink->getSession()->getPage()->fillField('pass',
PASSWORD);
}
(続く)
21. Contextの
/**
* @Given /^press login button$/
*/
public function pressLoginButton()
{
$this->mink->getSession()->getPage()->pressButton('Log In');
}
/**
* @Then /^facebook logged in¥.$/
*/
public function facebookLoggedIn()
{
assertEquals('https://www.facebook.com/', $this->mink-
>getSession()->getCurrentUrl());
}
}
(終わり)
22. FeatureContextの
<?php
use Behat¥Behat¥Context¥ClosuredContextInterface,
Behat¥Behat¥Context¥TranslatedContextInterface,
Behat¥Behat¥Context¥BehatContext,
Behat¥Behat¥Exception¥PendingException;
use Behat¥Gherkin¥Node¥PyStringNode,
Behat¥Gherkin¥Node¥TableNode;
use Behat¥MinkExtension¥Context¥MinkContext;
/**
* Features context.
*/
class FeatureContext extends MinkContext
{
public $base_url;
public $mink;
23. FeatureContextの
public function __construct(array $parameters)
{
// Initialize your context here
$driver = new ¥Behat¥Mink¥Driver¥Selenium2Driver(
SELENIUM2_BROWSER, null, SELENIUM2_URL
);
$session = new ¥Behat¥Mink¥Session($driver);
$this->base_url = OKKRU_BASE_URL;
$mink = new ¥Behat¥Mink¥Mink();
$mink->registerSession('okkru', $session);
$mink->setDefaultSessionName('okkru');
$this->mink = $mink;
// use other context
$this->useContext('fbconnect', new FbconnectContext($mink));
$this->useContext('facebooklogin', new FacebookloginContext($mink));
$this->useContext('sendme', new SendmeContext($mink));
$this->useContext('inputme', new InputmeContext($mink));
$this->useContext('ticketsend', new TicketsendContext($mink));
$this->useContext('ticketrecipient', new TicketrecipientContext($mink));
}
}
24. り な :feature
Feature: sendme
商品を自分で受け取ることが出来る。
@javascript
Scenario: 商品を自分贈りで購入する。
Given テスト用商品ページにアクセスする。
When 購入ボタンを押下する。
Then ログイン画面に遷移する。
When ログインボタンを押下する。
Then facebookログインページに遷移する。
When facebookログインする。
Then 友人選択画面に遷移する。
When 友人選択画面で自分贈りを選択する。
Then 自分の住所情報が入 出来る。
And FBから引いた情報が補完されている。
When 自分の住所情報を入 する。
And 確認ボタンを押下する。
Then 確認画面に入 卣が勖単される。
When 確定ボタンを押下する。
Then 決済画面に遷移する。
25. り な :Context
<?php
use Behat¥Behat¥Context¥ClosuredContextInterface,
Behat¥Behat¥Context¥TranslatedContextInterface,
Behat¥Behat¥Context¥BehatContext,
Behat¥Behat¥Exception¥PendingException;
use Behat¥Gherkin¥Node¥PyStringNode,
Behat¥Gherkin¥Node¥TableNode;
class SendmeContext extends BehatContext
{
public $base_url;
public $mink;
public function __construct($mink)
{
$this->base_url = OKKRU_BASE_URL;
$this->mink = $mink;
}
(続く)
26. り な :Context
/**
* @Given /^テスト用商品ページにアクセスする。$/
*/
public function accessDetail()
{
$this->mink->getSession()->visit($this->base_url .
'/fbec_front/gift/detail/shop_id/' . SHOP_ID . '/product_id/' .
PRODUCT_ID);
}
/**
* @When /^購入ボタンを押下する。$/
*/
public function pressProductButton()
{
$this->mink->getSession()->getPage()->clickLink('product-
button');
}
27. り な :Context
/**
* @Then /^ログイン画面に遷移する。$/
*/
public function assertDetail2FBlogin()
{
$this->mink->assertSession()-
>addressMatches("/fbec_front¥/gift¥/login¥/url/");
}
/**
* @When /^ログインボタンを押下する。$/
*/
public function pressConnectButton()
{
$this->mink->getSession()->wait(3000, "$('#login_btn').length
> 0");
$this->mink->getSession()->getPage()->clickLink('login_btn');
}
28. り な :Context
/**
* @Then /^facebookログインページに遷移する。$/
*/
public function assertFBConnect2FBLogin()
{
$expected_url = 'https://www.facebook.com';
$this->mink->getSession()->wait(3000);
$actual_url = $this->mink->getSession()->getCurrentUrl();
$this->getMainContext()->getSubContext('fbconnect')->assertContainUrl($expected_url,
$actual_url);
}
/**
* @When /^facebookログインする。$/
*/
public function facebookLogin()
{
$this->getMainContext()->getSubContext('facebooklogin')->inputEmailAndPassword();
$this->getMainContext()->getSubContext('facebooklogin')->pressLoginButton();
}
29. り な :Context
/**
* @Then /^友人選択画面に遷移する。$/
*/
public function displayFriendsSelect()
{
$this->mink->assertSession()-
>addressMatches("/fbec_front¥/gift¥/friends¥/shop_id¥/" .
SHOP_ID . "/");
}
/**
* @When /^友人選択画面で自分贈りを選択する。$/
*/
public function selectBuymyself()
{
$this->mink->getSession()->getPage()->clickLink('buymyself-
button');
}