Thursday, August 28, 2014

An example of Cucumber - Ruby - Capybara

In this post, we won't talk too much about theory: What is cucumber? since you can research this information from internet. With this post, we just want to give you an example of Cucumber test with Selenium Ruby using Capybara (a library written in Ruby which makes it easy to simulate how a user interacts with your application)

1. Install Ruby, ruby devkit and some rubygem for your test, such as: selenium-client, selenium-webdriver, rspec, capybara, cucumber.

2. Using JetBrain RubyMine editor to write test script. User can use evaluation version of RubyMine for 30 days.

3. Open RubyMine, go to menu File > Settings > Ruby SDK and Gems, click (+) button on the right hand side to browse to ruby.exe (the location you had installed Ruby), press OK to complete the setting.

Now, write the first project with Cucumber and Ruby - Capybara.

 A cucumber project have structure like this:

 Create a new project named "FirstProject" with structure as above.

1. Create env.rb in feature\support:

2.Create Common_Lib.rb in feature\support:

3. Create first.feature in feature with below scenario:

Right-click on this scenario and select "Run..."
Because this is the first run, so that editor will generate step definition inside for this scenario

4. Next, we create step definition first_steps.rb in \step_definitions\

Tester copy the generated steps from section 3 from above and correct them as below code:

5. Run the first.feature again, you will get the report like this:

Hope this help.

1 comment:

  1. That was spot on! Thank you so much. Could you please provide code for chromedriver as well.

    Cheers, D