Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Travis-CI run Codeception tests?

I'm creating my tests (though I'm a beginner, learning) using Codeception. This includes acceptance and unit tests for now.

I want to add my repo to Travis CI so I can automate testing process after each commit and put build-status tag.

I would like to ask;

  1. Can Travis-CI run codeception tests?
  2. Can Travis-CI run codeception acceptance tests emulating browser?
  3. If both answers are no, is there any other CI tool which can?

Thank you.

like image 545
Aristona Avatar asked Sep 01 '13 12:09

Aristona


1 Answers

Yes, it is possible to run Codeception tests, including acceptance tests that run using WebDriver, on Travis CI.

It is possible to run your tests with a real browser on Travis, but it is easiest to use a headless browser, since Travis is running on a headless machine. PhantomJS is perfect for this, and it comes pre-installed with Travis CI's build bootstrap.

To run the tests with PhantomJS, you'll need to configure the WebDriver module like this in your .yml Codeception configuration file:

modules:
    config:
        WPWebDriver:
            url: 'http://127.0.0.1:8888'
            browser: phantomjs

The URL is important. I have found that attempting to use localhost instead of 127.0.0.1 will not work. Also, if you accidentally leave out the http://, that won't work either. You can use most any 8*** port, since most of them are open, but of course you'll need to have a web server running on that port to serve your static files or run your PHP application. The easiest way to do this, I find, is to use PHP's built-in webserver.

Your .travis.yml file might look something like this:

# Travis CI configuration file.

language: php

php:
    - 5.6
    - 7.0

before_script:
    # Start up a web server.
    - php -S 127.0.0.1:8888 -t /path/to/web/root >/dev/null 2>&1 &
    # Start up the webdriver.
    - phantomjs --webdriver=4444 >/dev/null 2>&1 &
    # Install Codeception.
    # Doing this last gives the webdriver and server time to start up.
    - composer install --prefer-source

script:
    - vendor/bin/codecept run

You will of course need to add Codeception to your project's composer.json file:

composer require --dev codeception/codeception

You'll also need to change path/to/web/root above to the path to the directory where you want the server's document root to be.

If you'd like to see a working demo running WebDriver tests against WordPress, you can check out this GitHub repo.

like image 188
J.D. Avatar answered Oct 24 '22 17:10

J.D.