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.
Amol
8/11/2017 08:51:04 am
Wow ! Very easy and simple explanation with examples. Really helpful while writing automation test scenarios... Comments are closed.
|