Codeception Acceptance tests with Javascript

I had an issue on this old legacy site in work where I was writing a basic acceptance test where it clicks all the links in the top section of the home page. The problem was that one of the links opened another window using JavaScript. So I had to reconfigure Codeception to get it running.

There are various different drivers that codeception uses, PhpBrowser which doesn’t do JS, Selenium WebDriver does, and you have several options; you could install Selenium, chrome headless browser, or phantomjs. I chose phantomjs, as it was easiest (for me) to get up and running on a non X Server.

First up, you’ll need phantomjs. Go download it, unpack the zip, move the folder somewhere, and then symlink the bin/phantomjs to /usr/bin/phantomjs.

Next, launch phantomjs like so:

phantomjs --webdriver=4444 --ignore-ssl-errors=true --ssl-protocol=any

Now, in your YAML:

# Codeception Test Suite Configuration

# suite for acceptance tests.
# Run the following command FIRST:
# phantomjs --webdriver=4444 --ignore-ssl-errors=true --ssl-protocol=any

# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.

class_name: WebGuy
modules:
     enabled:
         - WebDriver
         - WebHelper
     config:
         WebDriver:
             url: 'https://USER:PASS@YOUR_URL_HERE'
             browser: phantomjs
             capabilities:
                 acceptSslCerts: true

If you have a site using HTTP Basic Auth, put USER:PASSWORD@ in yopur URL, if not, remove it.

Now in your acceptance test, you can write:

$i->click('Nouvel abonnement');
$i->switchToWindow('webformswin');

Note that, in your Javascript, when you run the open window function, you specify a name. This is the name you use, and not the title from the HTML <head> section!

And there you have it! We can now test with javascript functionality!

Advertisements

Slouch on the CouchDB

No doubt you will know about the new generation of document oriented databases designed to work using the HTTP protocol, such as Mongo and CouchDB. They come pretty much with a built in API! So it’s time to mess around with it!

I downloaded Couchbase Server community edition (which is pretty nifty I’ll admit). Once you get that installed you can access localhost on port 8091 and it will take you into a cool looking admin panel:

One of the admin screens on couchbase server
One of the admin screens on couchbase server

It comes with a sample database, and you can access the API on port 8092. The full range of ports is as follows:

Port Description Node to Node Node to Client Cluster Administration XDCR
8091 Web Administration Port Yes Yes Yes Yes
8092 Couchbase API Port Yes Yes No Yes
11209 Internal Cluster Port Yes No No No
11210 Internal Cluster Port Yes Yes No No
11211 Client interface (proxy) Yes Yes No No
4369 Erlang Port Mapper (epmd) Yes No No No
21100 to 21199 (inclusive) Node data exchange Yes No No No

There are some great videos at http://www.relaxed.tv that show you how couch works. This is the introductory video:

The curl syntax should be something like:

curl  localhost:8092/
{"couchdb":"Welcome","version":"1.2.0a-be4fa61-git","couchbase":"2.0.0-1976-rel-community"}

As you can know, being able to query a database and perform CRUD over HTTP would be incredibly useful, so this is very promising!

It’s stupid O’clock and I’ve been up all night but this looks great! I will update this post when I return to have a play with my new toy! 🙂