18

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.

Aristona
  • 8,611
  • 9
  • 54
  • 80

3 Answers3

9

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.

J.D.
  • 1,786
  • 2
  • 22
  • 34
2

I'd think that it can be done, but gluing everything tohether is not going to be for the faint of heart. Reason why I think it can be done is that codeception, itself, is ci-ed on Travis. See https://travis-ci.org/Codeception/Codeception. I'd contact the people at codeception and ask for their thoughts.

Or you can take a peek at how they do it in the build logs, such as: https://travis-ci.org/Codeception/Codeception/jobs/14432638 Looks like they're running headless with a downloaded standalone selenium server.

Travis-ci have some information on how to run GUI tests. In particular, they allow you to use a sauce labs account and run distributed selenium tests from there.

flup
  • 26,937
  • 7
  • 52
  • 74
0

I ran into this problem today and I solved it by adding Codeception to my composer.json:

"require-dev": {
    "codeception/codeception": "^2.1"
},

and referring to it on my .travis.yml:

install:
    - composer self-update
    - composer install

before_script:
    - #Code that creates and seeds my database and so on

script: php vendor/codeception/codeception/codecept run
FBidu
  • 972
  • 9
  • 21