Good application logging is invaluable. If offers insight into what your application is doing under normal conditions as well as somewhere to log information about errors. Combined with tools such as Graphite or Splunk, you can create real-time dashboards showing how your application is performing. Not only does this aid developers, but also operational teams to indentify abnormal patterns quickly.
These benefits also apply to automated test suites. They start off small and easy to understand. As they grow, testing more components and requiring more fixtures, they can become difficult to understand. Take an online shop for example, fixturing and testing the product catalogue is probably significantly more straightforward compared to completing a purchase.
To help those creating Behat test suties, I’ve create a Monolog extension for it. It works by injecting a log channel into each Behat Context, including Sub-Contexts. The name of the logger object is configurable, as are the handlers, although only the Stream hanlder (for writing to files) is supported for now. To get you up ‘n running quickly, there’s also an example project demostrating howto use it.
Below is the output when the stream hanlder is figured to write to php://stdout,
Any feedback, comments or suggestions are welcome.
On every fresh OS X install, I always end-up googling how-to setup Git completion on the command line. Almost every article I read suggests cloning the Git source code to acquire the necessary bash script. That’s not necessary if you have the offical Git package installed as you’ll already have the file under /usr/local/git/.
I run my Raspberry Pi as a headless server using ArchLinux. This post runs through how-to setup a wireless network interface using the Edimax EW-7811UN (£9.20 from Amazon) and have it connect automatically on boot, all without leaving the command line.
This post is just as much for my benefit as it is for others. It probably won’t be long before I break something and have to install the OS!
Lets get started,
Ensure you have a recent release of Archlinux – I installed archlinux-hf-2012-09-18 which includes Linux 3.2 and the Edimax driver.
Install the wireless management tools
sudo pacman -S wireless_tools iwconfig
Create /etc/wpa_supplicant.conf and add your wifi settings,
Then run /sbin/ipconfig wlan0 to check whether it’s connected, if is says ‘not associated’ it failed to connect. Once your connected, you and request an IP address from your router with,
sudo dhcpd wlan0
Run ipconfig again and you should see your IP address.
Now we can move onto configuring your RPi to automatically connect on bootup. To do this, we’ll create a network profile using netcfg and configure systemd to start it during bootup.
sudo pacman -S netcfg
Define a network profile, create /etc/network.d/wlan and enter the following details
WPA_CONF='/etc/wpa_supplicant.conf' ; this is the file we created earlier
Now register your network profile with netcfg by adding the above filename to the NETWORKS list /etc/conf.d/netcfg,
Finally configure systemd to start netcfg during bootup,
Providing the night sky is clear, the International Space Station is visible from as early as 21:30 for the next couple of weeks. It only takes a couple of minutes to across the sky, so you need to be ready for it! For exact times, see the Heaven Above website.
If your astronavigation skills are anything like mine, I highly recommend Stellarium to help find your way around the night sky. It is available for Mac OS X, Linux and Windows.
At work, we have a few scenarios where acceptance tests require two or more users to interact with each other on a website. An example of this is multiple users joining a poker table and playing against each other.
Scenario: Simple 1-way chat Given "User1" enters the chat roomAnd "User2" enters the chat roomWhen "User1" posts a messageThen "User2" should see that message
And now for some code. There’s a lot going on below, first we retrieve the default Mink session (as configured in behat.yml) and clone it. At this point we have two session objects linked to the same Selenium2 session. To correct this and provide session isolation, we instantiate and set a fresh WebDriver object before finally registering the new session with Mink and restarting. Okay, this is a bit hacky, but stay with me.
Now we have multiple sessions registered with Mink and subsequent steps will be passed the appropriate session name as defined in the Gherkin. These steps can simply reference the required session with $this->getSession($user).
I mentioned some gotchas previously. They are,
This code is Selenium2/Web Driver specific, however, broadly speaking the same approach should work with other drivers too.
Mink auto-starts the default session when you first call getSession(). This means a total of 3 browser instances are used for this test.
I’ve duplicated some Selenium2 config in behat.yml for ease. I couldn’t figure how-to ‘ask’ Mink for another Selenium2 driver instance
The standard MinkContext steps can’t be used as they only work with the default Mink session.UPDATE: Switching the default session name within a step with $this->getMink()–>setDefaultSessionName($name) means the MinkContext continue to work. I’ve updated the code on GitHub to reflect this.
Clearly this isn’t the cleanest implementation of multiple sessions, however it does prove the concept works while retaining the focus on describing behaviour in the Gherkin. I suspect the limitations of MinkContext and custom sessions can be resolved with a simple patch which I hope to raise over the next few days.
The full source code is available on GitHub. Any ideas/suggestions/improvements are welcome!