Previously, I’ve written up something on how to implement logic around cucumber’s tags. Well, here’s an improvement… instead of using a formatter, it turns out that you can get to a scenario’s tags as an array of strings, eg:
The place to do is in the Before or After blocks in your env.rb file, eg:
That’s a fair bit easier than using a formatter!
Before hook just doesn’t cut it. Here’s a nice hack that allows you to perform some logic during execution of cucumber scenarios when a tag is first come across:
It’s a cucumber formatter that detects when a tag is first come across. When a new tag is found, the
perform_logic_for method is called, passing the tag to it. Once you’re in the
perform_logic_for method, you can do what you like. I’m doing stuff like checking to see if a directory matches the tag name; if I find one, I load the data into an environment (a great example of when the
Before tag isn’t enough). You have free reign in here to do what you like with the tag.
To use it, save the file to
features/support/tag_logic.rb, add your own tag logic, and then execute it with:
#cucumber -f pretty -f TestManagement::TagLogic -o /dev/null
I hope that helps!
Before hook instead of this if you possibly can.
The change I asked for made it into rspec so you can now call
example.exception out of the box!
RSpec allows you to run a block of code at the end of each test using the
after(:each) method. A change is going to be included in a future (hopefully near future!) version of RSpec that allows you to know what exception the test failed with so that you can decide what to do based on the exception. You’ll be able to do that by asking the
example for its
I’ve been using a monkeypatch for a little while that allows me to know if a test passed or failed – I’ve wanted to write out a variable on test failure but until now rspec hasn’t exposed the test result. Here’s the patch:
If you place the above code in your project somewhere, you’ll be able to use it as shown in the following example of its use:
When the next version of RSpec exposes the exception that caused the test to fail, this patch will still work, so it’s fairly well future proof…
My new NetGear NV+ has just arrived. It’s great. Apart from the fact that none of the paperwork mentions the username or password you need to log in to the admin console. If you’re looking for the same info, the details you need are:
- Username: admin
- Password: netgear1
Hope that helps!
The css selector stuff is done by injecting jQuery into the page that’s being tested (if it’s not already there). This is pretty cool because it means you don’t need to worry about browser specific ways to select stuff (useful, since watir and selenium are/are going to be sat on top of webdriver so browser agnosticism is important). It also means that you don’t need to know xpath – cool if you’re a webdev since you don’t want to learn something new, and you probably already know css!
Check out the rQuery wiki for how to get started.
Overall, RQuery looks like a cool project. I’ll be following it for sure…