PhantomJSをWebdriverとして使ってみる。プロジェクトはVagrantのホスト上で動かしている状態。
phantomJSのインストール
面倒だったので brew install phantomjs
でインストール
プロジェクトにインストール
基本全部のプロジェクトは Composer
を使ってるので、下記の一行を実行
> composer require "codeception/codeception" --dev
設定ファイルとか必要なので作成させる
> ./vendor/bin/codecept bootstrap
設定が作成されたら簡単な Acceptanceなテストを作ってみる。
> ./vendor/bin/codecept generate:cept acceptance Welcome
内容をこんな感じにしてみる。
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('perform actions and see result');
$I->amOnPage('/');
$I->see('Homepage'); /* replace this with your own text */
設定とか
一番やりたいのは、Acceptance なので、それの設定だけ少しいじる。
tests/acceptance.suite.yml
# Codeception Test Suite Configuration
# suite for acceptance tests.
# perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
class_name: AcceptanceTester
modules:
enabled: [WebDriver]
config:
WebDriver:
url: 'http://192.168.13.14:8054/'
browser: phantomjs
window_size: 1024x768
wait: 1
動かし方
二つのターミナルを開いて、一つをphantomjsを、一つをcodeceptに使ってみる。他の方法はよくわからんない。
> phantomjs --webdriver=4444
> ./vendor/bin/codecept run
Codeception PHP Testing Framework v2.0.14
Powered by PHPUnit 4.6.7 by Sebastian Bergmann and contributors.
Acceptance Tests (4) ----------------------------------------------------------------------------------------------------------------------
Perform actions and see result (WelcomeCept) Ok
エラーとか
エラーが出れば、 tests/_output
などに出力されるから、それを見ればいい感じ。スクリーンショットも撮っているので。
XPathとか
テストでDom指定もできるし、Xpathの指定もできる。ただ、XPathを書く気は無いので、XPathHelper を使ってみる。
XPathHelper の使い方
- Ctrl-Shift-X を押したら上にクエリーウィンドウが開く
- シフトを押しながらマウスを移動すれば、クエリーウィンドウにパスが出力されるから、それを利用する。
多分他にも。