In my previous post, I discussed how I began using the ask method in cucumber to incorporate manual testing as part of my test suite.
As a reminder, here is the step definition to “Given I am on the Nouvola Homepage” Given(/^I am on the Nouvola Homepage$/) do question = "Does the following home page open in the browser, http://www.nouvola.com?" answer = ask(question).chomp expect(answer).to eq "yes" end Any tester will soon realize that there are issues with the way that I wrote this step definition (outside of the technical obvious). First and foremost nothing in the prompt tells me how to answer the question. The most common command line response would be to simply enter ‘y’. Unfortunately, based on the expectation that the answer is yes, this scenario would be marked as failed. Second, even though the question is self explanatory, more detail may become necessary to help the tester run the test scenario. Nothing in the question helps the tester validate that page that opened up is in fact Nouvola’s home page. It can easily have been a GoDaddy Parking page. Many would say that the answer for the first problem is to simply add a ‘yes/no’ at the end of question. It gets the job done, but it can be rather redundant work for the manual tester to constantly add this to the end of every question created. Since cucumber is a framework that allows code to be written, we can actually make that part easy be wrapping most of the step definition inside a method called generate_test_step. def generate_test_step(query) question = query+” [yes/no] “ answer = ask(question).chomp expect(answer).to eq “yes” end Now, our step definitions can simply written as follows: Given(/^I am on the Nouvola Homepage$/) do generate_test_step(”Does the following home page open in the browser, http://www.nouvola.com?”) end Now with the generate_test_step method, I can improve on my actual test case. Although the scenario is relatively easy a tester could make a mistake. For example, in our given step, how does our tester know that the Nouvola home page was the correct one when the url open was open in the browser. Let's add another parameter to my method called info. Then in my method, add the string to my ask method like so: generate_test_step( info, query ) details = info+"\n" question = query+” [yes/no] “ answer = ask(info+question).chomp expect(answer).to eq “yes” end Now I can update my step definition like this: Given(/^I am on the Nouvola Homepage$/) do info = "The Nouvola Home Page should contain the phrase 'Real-World Ready'." question = ”Does the home page open in the browser, http://www.nouvola.com?” generate_test_step( info, question) end Now when I run the scenario, I get the following: The Nouvola Home Page should contain the phrase 'Real-World Ready'. Does the home page open in the browser, http://www.nouvola.com? [yes/no] Manual testing in cucumber has now greatly improved. In the next post, I'll show how I still keep my 3 step rule in my scenarios when I need to provide more detail in my test. It's been a while since my last post. I was actually working on a project where I had to do manual testing. The cost of automating functional tests for the project did not provide any real advantage considering the tight schedule. It did allow me to revisit a method in cucumber that I never thought I would ever use.
The ask method will pause the cucumber runtime and prompt the user for an input. So, if I had the following step: Given I am on the Nouvola Homepage The ask method could be added to the step definition like this: Given(/^I am on the Nouvola Homepage$/) do question = "Does the following home page open in the browser, http://www.nouvola.com?" answer = ask(question).chomp expect(answer).to eq "yes" end If you just tried to run the above code, you will most like have received an error. Given I am on the Nouvola Homepage # features/step_definitions/steps.rb:1 Does the following home page open in the browser, http://www.nouvola.com? yes expected: "yes" got: "yes\n" (compared using ==) (RSpec::Expectations::ExpectationNotMetError) ./features/step_definitions/steps.rb:4:in `/^I am on the Nouvola Homepage$/' features/nouvola.feature:4:in `Given I am on the Nouvola Homepage' This can be easily fixed by adding a chomp to the end of code. Given(/^I am on the Nouvola Homepage$/) do question = "Does the following home page open in the browser, http://www.nouvola.com?" answer = ask(question).chomp expect(answer).to eq "yes" end Now with the ask method, I can “fully” document my scenario. Feature: As A User, I would like to view my Nouvola Dashboard Scenario: I should see my dashboard when I log in Given I am on the Nouvola Homepage When I log into my account Then I see my dashboard And my code looks like this: Given(/^I am on the Nouvola Homepage$/) do question = "Does the following home page open in the browser, http://www.nouvola.com?" answer = ask(question).chomp expect(answer).to eq "yes" end When(/^I log into my account$/) do question1 = "When you click 'Login' from the top menu, are you taken to the login page?" question2 = "Are you able to enter your log in credentials and click on 'LOG IN' button?" answer = ask(question1).chomp expect(answer).to eq "yes" answer = ask(question2).chomp expect(answer).to eq "yes" end Then(/^I see my dashboard$/) do question = "Do you see your dashboard?" answer = ask(question).chomp expect(answer).to eq "yes" end Of course, this approach can easily get out of hand. In the next post, I'll demonstrate how I currently manage my manual steps. |