follow me icons

Thursday, January 27, 2011

Cucumber Parse Error, Expected one of \n \r

My cucumber tests usually have two sections, .manual and .feature, files. I use cucumber to write my automated test cases as well as the manual test cases. This way all of my test cases can be accessed from one project and you can easily differentiate which features are automable and which do not.

The good thing with cucumber is that it will only run the files that have .feature on it and ignoring the rest.

The way I run my test is usually by running the whole folder which is something like this:

cucumber features\regression


inside that folder I will have a mix of .manual and .feature files and folders.

Recently, I have been getting this error when I run my cucumber tests.

features/regression/postcode_details.feature:5:1: Parse error, expected one of "\n", "\r", "|", "\"\"\"", "#", "* ", "Given ", "When ", "Then ", "And ", "But ", "
@", "Scenario", "Scenario Outline". (Cucumber::Parser::SyntaxError


I check the feature file and everything looks ok. It actually took me a while to figure out that the mistake was just because I accidentally named a .manual file into a .feature file and thus the error as cucumber could not understand how to run a manual test. What an annoying mistake to make!

Monday, January 24, 2011

How to enable Ruby-debug in RubyMine

After finding out how to run my cucumber test through RubyMine, I try to enable the ruby-debug from RubyMine as well. It turns out that I need to install another ruby gem called Ruby-debug-ide which for some reason I could not download it straight from the RubyMine ide.

So here are the steps to install ruby-debug-ide gems into RubyMine:

1. Open your console, and type 'gem install ruby-debug-ide'
2. Open RubyMine and click File->Settings->Ruby SDK and Gems
3. Click Attach gems and attach 'ruby-debug-base'. You will need to instal 'ruby-debug' gems first.
4. Click Attach gems and attach 'ruby-debug-ide'
5. Click ok and put a breakpoint in your step definition

Thursday, January 20, 2011

error: Couldn't resolve host 'github.com' while accessing fatal: HTTP request failed

I am using Msygit 1.7.0.2 on my Windows machine. When I try to git clone a repository in github, I receive the following error


D:\>git clone
https://github.com/giozom/Cucumber-Test-Framework-for-Newbies.git
Initialized empty Git repository in
D:/Cucumber-Test-Framework-for-Newbies/.git/
error: Couldn't resolve host 'github.com' while accessing
https://github.com/giozom/
Cucumber-Test-Framework-for-Newbies.git/info/refs

fatal: HTTP request failed


It turns out I can get the clone to work by using http instead of https


D:\>git clone
http://github.com/giozom/Cucumber-Test-Framework-for-Newbies.git
Initialized empty Git repository in
D:/Cucumber-Test-Framework-for-Newbies/.git/
remote: Counting objects: 22, done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 22 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (22/22), done.


I am not really sure why git clone 'https://' does not work on my Windows machine but I am guessing it's because I don't have a github account.

Wednesday, January 19, 2011

Running cucumber test through RubyMine

I have been running my cucumber test using a command line console. I am so used to running it from the console that I did not bother to figure out how to run the cucumber test through the RubyMine ide. However, I was shown by my colleque on how to set it up:

From RubyMine you would need to do the following:
1. Click on File->Settings
2. Click on Ruby SDK and Gems
3. Click on Attach Gems
4. Locate your Cucumber gems and attach it.
5. Click Ok

Next is to configure your cucumber test environment variables.

1. Click on Run->Edit Configurations
2. Add the environment variables on the Environment Variables field

You can also specify which test you want to run on the "Feature file" field.

After that, all you need to do is to click the Run (Shift + F10) button to run your cucumber test from RubyMine.

Monday, January 10, 2011

Element is not currently visible and may not be manipulated

My web tests started to fail in Ubuntu when I upgraded my selenium-webdriver gem to the latest version 0.1.2.


Element is not currently visible and may not be manipulated (Selenium::WebDriver::Error::UnhandledError)
[remote server] :0:in `Error'
[remote server] file:///tmp/webdriver-profile20110110-17264-1osf9xy/extensions/fxdriver@googlecode.com/resource/modules/atoms.js:389:in `'
[remote server] file:///tmp/webdriver-profile20110110-17264-1osf9xy/extensions/fxdriver@googlecode.com/resource/modules/atoms.js:582:in `'
[remote server] file:///tmp/webdriver-profile20110110-17264-1osf9xy/extensions/fxdriver@googlecode.com/resource/modules/atoms.js:3968:in `'



The error does not explained alot but it seems that selenium-webdriver fails to locate the element. The code that I have is very simple which is to click the go button.


def click_go_button
find(:css, "#search_button").click
end


My test, however, works fine in a windows based environment. It only fails in the Linux environment.

So for now I have to gem uninstall selenium-webdriver 0.1.2 and gem install selenium-webdriver -v 0.0.29 to make my test work again in Ubuntu.

Friday, January 7, 2011

Cucumber Writing Standard

We found it useful to have a cucumber writing standard document where everyone can use it as a reference to write the scenarios. Without the standard we will have inconsistency in the features files.

1. The first cucumber writing standard that we have is to use a third person narrative when we write Given/When steps.


Given the user is on Google homepage
And the user clicks on the Google Search button


We find it more relevant to use "the user" instead of using the first person narrative "I"

2. We use "is/are" in the Given steps for assigning a variable.


Given price is "5" dollar
And quantity is "10"


And we use "should" in the Then steps for asserting result


Then the total price should be "50" dollar


This is so that we can differentiate quickly which one is the pre condition and which one is the assertion.

The above examples are the two things that are most argued in our team. Some people prefer to use "I" and some don't like to use the word 'should'. I guess there is no right or wrong answer. However, since we are working in a team, it is important that we come up with a cucumber writing standard so that we can have a consistent writing.

3. Condition statements (e.g if statements) are to be avoided in the scenario. This might sound obvious but for a tester who is new to cucumber might not find it that obvious.

Instead of

Given the user is on Yahoo.com

Then the user should see his name if the user has signed in


We separate the scenarios into two lines

Scenario: User has signed in
Given the user is on Yahoo.com

When the user signs in into his account as "bananta"
Then the user should see his name as "bananta"

Scenario: User has not signed in
Given the user is on Yahoo.com
Then the user should not see "bananta"



4. Another standard that we have is that testers own/maintain the cucumber scenarios and the developers maintains the steps defintions. In other words, testers should not modify the steps definition and developers should not modify the test scenarios. This might sound obvious but in our case, the devs are modifying the scenarios without the testers' knowledge which cause the test cases to behave
differently.

We have more cucumber writing standards that are specific to our projects but the above examples are the main one that we have.