15
14

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のAcceptanceテスト実行時にちょっと楽する方法

Last updated at Posted at 2016-05-31

PhantomJSでもSeleniumサーバーでもphpビルトインサーバーでも動作テストが出来るCodeception。
ただその度に各サーバーを起動させるのが面倒でした。
なのでcodeception実行時に自動で各サーバーを立ち上げて、自動で落としてくれるextensionをメモ。
phantomjsはvagrantやテスト環境へのテストで超ベンリです。

phantomjs・codeceptionの基本設定等は
http://qiita.com/a_yasui/items/6bd4826980c80197a95f
こちらを閲覧下さい。

※ selenium-serverも自動で立ち上げてくれるextension超募集中!

動作確認環境

  • php 5.6
  • composer
  • codeception 2.1.9
  • phantomjs 1.9.8

phpビルトインサーバーの場合

まずはcomposerでインストール

$ composer require codeception/phpbuiltinserver --dev

次はcodeception.ymlのextensionsに以下を追加

codeception.yml
extensions:
    enabled:
        - Codeception\Extension\PhpBuiltinServer
    config:
        Codeception\Extension\PhpBuiltinServer:
            hostname: localhost
            port: 8080
            documentRoot: ./
            phpIni: tests/.test.php.ini #ここでphp.iniも切り替えられます
            startDelay: 0

tests/acceptance.suite.ymlも忘れずに

tests/acceptance.suite.yml
enabled:
        - \Helper\Acceptance
        - PhpBrowser:
            url: http://localhost:8080

そのままおもむろにcodeception実行。

$ ./vendor/bin/codecept run acceptance tests/acceptance

PhantomJSの場合

まずはcomposerでインストール

$ composer require site5/phantoman --dev

次はcodeception.ymlのextensionsに以下を追加

codeception.yml
enabled:
        - Codeception\Extension\Phantoman
    config:
        Codeception\Extension\Phantoman:
            path: '/usr/local/bin/phantomjs' # which phantomjsで調べたパスを入れる
            port: 4445 # 空いてるポートを指定。selenium-serverが4444
            suites: ['acceptance']

tests/acceptance.suite.ymlも忘れずに

tests/acceptance.suite.yml
enabled:
        - \Helper\Acceptance
        - WebDriver:
            url: テストしたいURLへ
            browser: phantomjs
            port: 4445 # codeception.ymlで指定したポートを指定
            window_size: 1024x768 #windowサイズも指定出来る!

そしておもむろにcodeception実行。

$ ./vendor/bin/codecept run acceptance tests/acceptance
15
14
0

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
15
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?