6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

codeception を使ってみたメモ

Last updated at Posted at 2015-06-01

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 の使い方

  1. Ctrl-Shift-X を押したら上にクエリーウィンドウが開く
  2. シフトを押しながらマウスを移動すれば、クエリーウィンドウにパスが出力されるから、それを利用する。

多分他にも。

6
7
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?