I have started writing the following feature within an app designed to manage a cleaning business:
Feature: Creating a new cleaner
In order to allow Franchisees to allocate cleaners to jobs they need to be uploaded to the system
Background:
Given I am currently logged in to my account
And I have navigated to the "Cleaners" page
And I want to add a new cleaner to the database
Scenario: Add a new cleaner to the system
Given I have brought up the "Add Cleaner" form
Then I will need to complete the fields within the following form:
| first_name |
| last_name |
| email |
| date_of_birth |
| postcode |
| mobile |
| other_phone |
| address_1 |
| address_2 |
| work_radius |
| **days_available** |
| notes |
When I have entered valid data
Then I can save to the database
And I will have added a new cleaner to the system
In addition to welcoming comments on the way I have written the scenarios etc, my main problem is that I can't work out how to simulate selecting from a pre-populated field:
Populating the days_available should allow the franchisee to choose which days of the week, and which hours within those days, that a cleaner will be available for work. This obviously makes it possible to return queries which only show available cleaners for any given day/time of day.
Really hope someone can explain how this is done?
Just a quick comment on the structure of your feature file ... the 'Then' step in your feature should be asserting that something has or has not been done successfully.
Given I have logged into the site
When I add a new Cleaner to the site
Then I should see that the Cleaner has been added successfully
I would recommend using language that can be easily understood. Your scenario doesn't need to be instructions on how to use the site. Excessive navigational steps can make you lose track of the purpose of the scenario.
To answer your question regarding days_available accurately, would require some knowledge of how the site is structured and how the days_available are entered. Are you choosing from select lists, filling in form fields, etc? Also, since you are testing, you could consider setting the data from within your step (ie. hash, array) instead of passing all of the info in via a table.
Just some food for thought. Cheers.
Based on your updated post, I would suggest the following:
The step And I want to add a new cleaner to the database doesn't seem like an actionable step and could be removed. Same for the step When I have entered valid data. If you handle filling out the form in the previous step, you have already entered valid data.
If you need to multiple available days, I would consider making it its own step
And(/^the cleaner is available from (.*?) to (.*?) on (.*?)$/) do |start_time, end_time, day|
#fill in start time
#fill in end time
#select day
end
Background:
Given I am currently logged in to my account
And I have navigated to the "Cleaners" page
Scenario:
And I bring up the "Add Cleaners" form
And I complete the form with
| first name | Bob |
| last name | Smith |
...
And the cleaner is available from 0600 to 1800 on W
When I submit the Add Cleaners form
Then I should see the new cleaner has been successfully added
Related
I have a scenario with following structure:
Scenario Outline: Sections displayed on login
Given Robert is at the home page
When Robert logs in as "<role>"
Then the "<section1>" should be displayed
And the "<section2>" should be displayed
Examples:
| email | section1 | section2 |
| Administrator | Administration | Profile |
| External | IGNORED | Profile |
As you can see, there is a parameter "IGNORED" in the second example.
In case I detect this keyword during runtime, I want the step, the keyword appeared in, to be skipped.
At the moment I use this:
#Then("the {string} should be displayed")
public void the_section_should_be_displayed(String sectionName) {
if(sectionName.contentEquals("IGNORED"))
return;
// rest of code
}
Here the step will be set as PASSED if the IGNORED keyword is there.
What I want instead, is that this single step is marked as SKIPPED and that the following steps are still executed and the full test scenario is afterwards marked as PASSED or FAILED depending on the status of the other steps.
So my question is:
Is there a way to manually set a Cucumber step to status SKIPPED without skipping the rest of the scenario?
I am aware that I could simply create two scenarios, one for each role. But I currently have no choice. I can not change anything within the feature file and need to solve this with code. So please try to answer the question if you can.
I appreciate any help!
Instead of adding logic to your step definition, consider making a separate scenario that skips this step. I'm assuming there is a reason that "section1" is not relevant to the role of "External"? It would be considered good practice to capture that in a different scenario with a different name. Remember that a goal of the feature files is to describe the intended behaviour of your system; using 2 different scenarios here allows you to specify what the difference in behaviour is for different roles.
For example, as follows:
Scenario Outline: Admin section is visible to Admin
Given Robert is at the home page
When Robert logs in as Administrator
Then the Administration section should be displayed
And the Profile section should be displayed
Scenario Outline: Relevant sections are visible to External
Given Robert is at the home page
When Robert logs in as External
Then the Profile section should be displayed
Alternatively, if you want to check that specific section are / are not displayed, you could do something like this, and use the step definition to check a sectio is / is not displayed based on the provided value:
Scenario Outline: Sections displayed on login
Given Robert is at the home page
When Robert logs in as "<role>"
Then the admin section "<admin>" be displayed
And the "<section2>" should be displayed
Examples:
| email | admin | section2 |
| Administrator | should | Profile |
| External | should not | Profile |
(My example might not be correct Gherkin, but should give you an idea)
If you have a simple form, you enter your name, Gender and save it. When you select the Gender drop-down it will list [Male | Female].
So when writing test scenarios for the above, the typical way is to Write it in steps.
Precondition : User Loged in and Form Opened
Steps | Expected Result
------------------------------------------------------------------------
1 : User Enters the name | Entered name should be there
2 : User Clicks on Gender Drop-down | Male and Female should be listed
3 : Users Selects a Gender | Selected Gender should be there
4 : Clicks on Save | Information get saved.
Following is one way to represent this is Cucumber.
Given User Loged in and Form Opened
When User Enters the name
Then Entered name should be there
When User Clicks on Gender Drop-down
Then Male and Female should be listed
When Users Selects a Gender
Then Selected Gender should be there
When Clicks on Save
Then Information get saved.
Now How can we represent this in Cucumber? As I read you are not suppose to have multiple actions within the same scenario. If you add multiple testcases for each step above, the Testcases will grow exponentially. What is the best way to handle this?
My approach would be to think about documenting in Gherkin (using principles of BDD) - the application behavior and not test cases.
In fact, this article provides some good context around misconceptions of BDD.
With that said, even though you are trying to validate the above criteria in a single scenario, I would recommend at least splitting into 2, to keep your acceptance tests succinct, readable and maintainable.
Here's my attempt, at reformulating:
Scenario: Gender Dropdown values
Given a user is logged in
When the user clicks the Gender dropdown
Then Male and Female options are displayed
#EndtoEnd
Scenario Outline: Saving User information
Given a user is logged in
When the user enters a <Name> and selects a <Gender>
And Clicks on Save
Then the information gets saved
Examples:
|Name|Gender|
|Keith|Male|
|Jenn|Female|
||Female| # Negative
|Rob|| # Negative
Additionally, you can also think about throwing in some negative test scenarios as well.
If you need to test on cucumber with multiple data, you can go ahead and use the scenario outline feature, where you load the data in the examples after the scenarios.
Scenario Outline: User enters details and stores
Given User Loged in and Form Opened
When User Enters the <Name>
And Users Enters the <Gender>
And Clicks on Save
Then Information get saved.
Then I Go back (In case view info)
Then I assert for <Name>
Then I assert for <Gender>
Examples:
|Name| |Gender|
|x| |Male|
|y| |female|
Cucumber is not about testing how you do things, its about specifying why you do things. This scenario is all about how the user interacts with the form, its all about clicking on this and entering that, none of this has any place in scenarios.
Your scenario and question doesn't even tell us what you are trying to do, so I'll just have to make something up. Lets say you are trying to add a friend
Feature: Adding a friend
Scenario: Add Alison
Given I am logged in
When I add Alison to my friends
Then I should see Alison is my friend
and thats pretty much that. Note how none of the details about how you add a friend are captured in the scenario, thats not what Cucumber is for.
Now on the technical side lets explore how we get this scenario to actually add a friend. First of all the step definition
When 'I add Alison to my friends' do
add_a_friend name: 'Alison' # perhaps add a gender param here
end
Notice how even the step definition doesn't know how to fill in the form.
Finally a helper method to actually do the work (done in Ruby cos its clearer)
module FriendStepHelper
def add_a_friend(name:)
# here is where we fill in the form and choose the gender
end
end
World FriendStepHelper # makes add_a_friend visible to step def
So technically this is how you represent your problem in Cucumber you write WHY you doing things in using your scenarios and you push down HOW you do things to helper methods used by your step definitions
I have one problems, but i can't understand how to describe you for solve my problems. I m tying to understand you.
I have create a custom module that create a form and has some fields like id,url,dom pattern,time,schedule.
** After submit 2 item by using this form, it store all data to my database table.
pattern_store_table
id | url | pattern | time schedule
--------------------------------------------------------------------
1 | http://example.com/page1 | #div_1234 h2 | 1460864020 | 60
2 | http://example.com/page2 | #div_4567 h2 | 1465311839 | 30
Then I have created some function for collect data from other websites using third party dom parsing script, based on there websites url and Html Dom pattern. Then, i store this data as my drupal node.
And i create a list page based on "pattern_store_table" table data items. And create a function for call my scrap functionality.
So, when i hit "//example.com/scrap/id/1" into my browser, it scrap title from "http://example.com/page1" and store as my drupal node, and when i hit "//example.com/scrap/id/2" into my browser, it scrap title from "http://example.com/page2" and store as my drupal node.
My Problem is:
I don't want to hit always "//example.com/scrap/id/1" into browser. I want to create a function that call "//example.com/scrap/id/1" automatically every "schedule" fields timewise like "60 (for id 1)", "30 (for id 2)" then collect and store data into my database.
I listen about CRON, but i don't know how can i use it with my custom module.
Anybody please help me to automate this system step by step?
Sorry for my bad english. :(
Could any please suggest me some way we could use cucumber to repeat a test (e.g Login/Logout) multiple time, but changing only username/password for each time?
I could do for a single pair of username/password, but I'm looking for a way to re-use the test for multiple data set (The data set may be an array which store username/password, and the expected result which is true or false).
Thanks.
Scenario Outline allows you to run your Features based on the provided Examples in a tabular format, so to test login multiple time with different values you instruct to your step definition to run for every provided examples, In this we need to mention table column field in angle brackets in feature file.
Scenario Outline: Creating a new account
Given I am not authenticated
When I go to Login page
And I fill in "user_email" with "<email>"
And I fill in "user_password" with "<password>"
And I press "Sign up"
Then I should see "logged in as <email>"
Examples:
| email | password |
| testing#xyz.com | secretpass |
| testing2#xyz.com | fr33z3 |
For more references, Cucumber tutorials
i am using cassandra for a blogging app. one of my column families is for storing all the followers of of a user - UserFollowers. where each row is a user and the columns are sorted keys for the followers composed of firstname+lastname+uuid. the composite key is so i can search ranges on the followers and serve them paginated.
example - followers of user A would look like:
A | john:2f432t3 | sam:f242fg | joe:f24gf24
all well and good so far. when i add a follower he falls into his sorted place and i can search and retrieve however i like. but now sam decided to stop being a follower and i need to delete him. moreover - just before that sam changed his name to samuel so the delete message i send now is samuel:f242fg. that value will not be found and the column sam:f242fg will stay.
my only solution for it now is that when i want to delete i have to pull out the entire row. locate sam by his id only. get the key that was stored initially and remove it. very inefficient for people with many followers and depends on these kinds of removals not happening a lot.
any better strategies out there?
thanks
or
I suggest the following:
Change your key on UserFollowers to an ID that represents the user.
Add a "name" column that contains the name of that user.
Instead of storing followers' names, store their IDs.
So your data now looks like this:
f1341df | name: george | 2f432t3 | f242fg | f24gf24
2f432t3 | name: john | f242fg | f1341df
... etc
Now you can get a list of followers' names by first querying the user and getting a list of IDs, then doing a multi-get with all those keys in a single query. If a user changes their name, this doesn't break your model.
ok i think ive found a way to do it more efficiently. it requires a bit more work application side but it works and allows deletions regardless of changes made to source.
just to define the problem again:
we have 2 entities that reference each other. example - User and Other Users. Users follow Other Users and Other Users are followed by Users.
we want to store the related entities horizontally. so we have a CF UserFollowers that stores in each row all the followers of the user.
we also have in inverse CF UserFollowing to store all the users this user is following.
what we actually store is a column for each followed or following user where the name is a key composed of firstname:lastname:uuid and the value is a compact json of the user.
now getting followers or following users is easy enough with range queries on the name.
removing a user from either one of the lists is however more tricky because we need to send a delete message with the original key that was stored.
example: if sam:jones:safg8sdfg followed abe:maxwell:fh2497h9 we would have -
in UserFollowers: fh2497h9 | sam:jones:safg8sdfg<json for sam>
and in UserFollowing: safg8sdfg | abe:maxwell:fh2497h9<json for abe>
if sam changes his name to sammy and tries to unfollow abe it wont work because the delete message will now attempt to delete a column in UserFollowers with name sammy:jones:safg8sdfg when the actual column stored is sam:jones:safg8sdfg.
so my solution to this was to store a reverseKey with the stored json on each side so that each side knows what key was actually stored on the other side and can use that to remove itself from there.
it would look like:
in UserFollowers: fh2497h9 | sam:jones:safg8sdfg<json for sam.. reversKey:abe:maxwell:fh2497h9>
and in UserFollowing: safg8sdfg | abe:maxwell:fh2497h9<json for abe..reverseKey:sam:jones:safg8sdfg>
now when sam wants removes abe from his Following he can use the reverseKey:sam:jones:safg8sdfg to remove himself from abes follower list.
and everyone is happy.