Skip to content

Commit

Permalink
Merge pull request #248 from nanasess/use-webdriver
Browse files Browse the repository at this point in the history
会員登録と管理画面ログインのテスト追加
  • Loading branch information
Chihiro Adachi authored Apr 5, 2019
2 parents 7f7d192 + 4af4916 commit 11f541a
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 29 deletions.
18 changes: 16 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ php:
- 7.2
- 7.3

addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable

env:
global:
- DBNAME=myapp_test HTTP_URL=http://localhost:8085/ HTTPS_URL=https://localhost:8085/
- DBNAME=myapp_test HTTP_URL=http://localhost:8085/ HTTPS_URL=http://localhost:8085/
matrix:
- DB=mysql USER=root DBPASS=' ' DBUSER=root
- DB=pgsql USER=postgres DBPASS=password DBUSER=postgres
Expand Down Expand Up @@ -52,13 +59,20 @@ before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- php -S localhost:8085 -t html/ &
- wget -c -nc --retry-connrefused --tries=0 http://chromedriver.storage.googleapis.com/2.43/chromedriver_linux64.zip
- unzip -o -q chromedriver_linux64.zip
- sudo mv -f ./chromedriver /usr/local/bin/
- sudo chmod +x /usr/local/bin/chromedriver
- gem install mailcatcher -v "0.6.5"
- mailcatcher
- chromedriver --url-base=/wd/hub &
- php data/vendor/bin/codecept build

script:
- mkdir -p reports/coverage
- if [ ! $COVERAGE ] ; then php data/vendor/bin/phpunit -c phpunit.xml.dist ; fi
- if [ $COVERAGE ] ; then phpdbg -qrr data/vendor/bin/phpunit -c phpunit.xml.dist ; fi
- if [ ! $COVERAGE ] ; then php data/vendor/bin/codecept run --env travis --steps ; fi
- if [ ! $COVERAGE ] ; then php data/vendor/bin/codecept run --env chrome --steps ; fi

after_script:
- if [ $COVERAGE ] ; then php data/vendor/bin/coveralls -v ; fi
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"sort-packages": true
},
"require-dev": {
"satooshi/php-coveralls": "1.0",
"codeception/codeception": "*"
"captbaritone/mailcatcher-codeception-module": "1.2.1",
"codeception/codeception": "*",
"fzaninotto/faker": "^1.8",
"satooshi/php-coveralls": "1.0"
},
"require": {
"php": ">=5.3.9",
Expand Down
118 changes: 101 additions & 17 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions ctests/_support/MailCatcherGuzzle5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace Codeception\Module;

use Codeception\Module;

class MailCatcherGuzzle5 extends MailCatcher
{
public function _initialize()
{
$base_uri = trim($this->config['url'], '/') . ':' . $this->config['port'];
// XXX FIX base_uri to base_url
// see https://github.com/captbaritone/codeception-mailcatcher-module/issues/28

$this->mailcatcher = new \GuzzleHttp\Client(['base_url' => $base_uri]);

if (isset($this->config['guzzleRequestOptions'])) {
foreach ($this->config['guzzleRequestOptions'] as $option => $value) {
$this->mailcatcher->setDefaultOption($option, $value);
}
}
}

protected function emailFromId($id)
{
$response = $this->mailcatcher->get("/messages/{$id}.json");
$message = json_decode($response->getBody(), true);

$message['source'] = quoted_printable_decode($message['source']);
$message['source'] = mb_convert_encoding($message['source'], 'UTF-8', 'JIS');
return $message;
}
}
28 changes: 26 additions & 2 deletions ctests/acceptance.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,38 @@
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser
- AcceptanceHelper
- WebDriver
- MailCatcherGuzzle5
config:
PhpBrowser:
url: 'http://localhost:8085/'
WebDriver:
browser: chrome
url: 'http://localhost:8085/'
host: 'localhost'
port: 9515
window_size: 1680x3000
wait: 10
capabilities:
unexpectedAlertBehaviour: 'accept'
elementScrollBehavior: 1
MailCatcherGuzzle5:
url: 'http://127.0.0.1'
port: '1080'

env:
travis:
modules:
config:
PhpBrowser:
PhpBrowser:
url: 'http://localhost:8085/'
chrome:
modules:
config:
WebDriver:
browser: chrome
capabilities:
chromeOptions:
prefs:
download.default_directory: '%PWD%/codeception/_support/_downloads'
10 changes: 10 additions & 0 deletions ctests/acceptance/AdminHomeCept.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('管理画面に正常にログインできるかを確認する');
$I->amOnPage('/admin');

$I->fillField('input[name=login_id]', 'admin');
$I->fillField('input[name=password]', 'password');
$I->click(['css' => '.btn-tool-format']);

$I->see('ログイン : 管理者 様');
Loading

0 comments on commit 11f541a

Please sign in to comment.