How to handle common steps in Behave - python-behave

I have 4 feature files like login, add to cart, search by product, shipping method calculation. All 4 are separate feature file and all have first 4 steps are exact same like below :
Given I go to website
When I click on the login button
Then I enter username and password
And I verify I am logged in successfully
In behave if I use the same steps in all feature files, it does not work. It has an Ambiguous Step error.
My goal is to log in first in all 4 feature files and then move to the next corresponding step.
The error I am facing :
raise AmbiguousStep(message % (new_step, existing_step))
behave.step_registry.AmbiguousStep: #given('I am loggedin into website') has already been defined in
existing step #given('I am loggedin into website') at features/steps/Steps_cart.py:5

Related

Only 2 steps are different when compared to two feature files. (cucumber-selenium-java)

I am learning cucumber. I have two scenarios. I can't say the exact due to company policies. First Step file is like
Scenario 1: Flow with attachments
Given Login to APP
When User chooses "country"
And clicks "Yes"
And attaches "files"
And Go to location page
And add comments
Then Submit
Scenario2: Flow without attachments
Given Login to APP
When User chooses "country"
And clicks "Yes"
And add players manually
And User picks players
And User clicks on a player
And does the settings
And Go to location page
And add comments
Then Submit
Do I need to write all the steps again in Scenario 2 or can I do something so that I can bypass writing all the steps in feature file.
I mean can I maintain only different steps in the 2nd feature while like we do in writing step file or glue code for that.
If yes how to do it, so that it run all the previous steps. Please help
Instead of writing all the steps in terms of small actions the users performs on the system (like "go to page", "click this" , "submit that"), think about what the user is trying to achieve and create a step that describes that in a way that is meaningful to the user (i.e. "add players from a file", or "add players manually"). The step definition for that step will then contain all of these actions on the system (click this, fill that, etc). You can also use what we call "helper methods" from your step definition; for example create a method that will navigate to a certain page, and call that method with the relevant page to go to from your various step definitions.
That way your scenarios will describe the intended behaviour of the system, or what the user is supposed to be allowed to do (or not do).
Also, from the examples you've provided it is not clear to me what it is you are testing/asserting. I've always found it helpful to use "Given/And" to set up the original state of the system, "When/And" for the actions to be performed that you want to test the outcome of, and "Then/And" to verify the expected result.
The title of the scenario should clearly describe what it is the scenario tests for.
From your example, I've assumed that you are testing that a user is able to add players either from a file or manually. In that case, the scenarios could look something like the following:
Scenario: User is able to add players from a file
Given a user who is logged in
And the user has selected "country"
When the user attaches "files"
And adds a comment about location
Then the players are added
And the comment is saved
Scenario: user is able to add players manually
Given a user who is logged in
And the user has selected "country"
When the user adds players manually
And adds a comment about location
Then the players are added
And the comment is saved
In the example above, I am also assuming that the following steps:
And add players manually
And User picks players
And User clicks on a player
And does the settings
are actually all (always) needed to add players manually, so all of those actions would be performed in the one step "And add players manually" (either by implementing them all in one step, or calling several helper methods from that one step).
By describing the behaviour like this it is much clearer what you are testing in each scenario and what the expected behaviour of the system is.
Also, it will lead to way less duplication of "steps" (as was your original question, I believe).

How to return login value to database on custom ISL for Micros Simphony?

We are running Micros Simphony 2 and Micros can't support the use of our own employee cards because of a leading 0 which database cannot handle... I put myself in search of developing custom ISL file which would trim the 0 before login the employee in. I managed successfully to do so with some test.
var auth_code : A40 //Declare global variable
event inq : 1
Input auth_code{ M2,1,3,4 }, "Enter authorization code" //State that the infos are on track 2 (M2) field 1 start on character 3 and is 4 digits long
endevent
So this code above does the job but doesn't make any call to database to compare the login. So I tried to implement a macro that call for Micros Login function as first step then Wait for Input as second step and then Sim Inquire that call my code as third step however when swiping the card the value is returned straight away to the database. I tried also to make a macro starting for the wait for input then put my function it wouldn't work.
Since any swipe on the Home screen sign you in I was thinking of putting in place my own Sign In. Is there any way to open a connection to the SQL Server database and create maybe my own "Sign In" function?
Many thanks in advance!

Uploading file on Step in Bonita

i would like to upload and download a file. I know the FileUploadDownload Example but i required to upload document on step not on instantiation form.how can i achieve that i have made contract on step and assigned it to document variable initialized at pool level, but its not working. it gives error that "Error submitting form". I am new to bonita help anybody.
Steps for process building are given as follows:
Step 1:
Step 2:
Step 3:
Step 4:
Error:
When i submit form Error generates which is given as follows:
To solve your issue, you need to remove the contract inputs on the process instantiation, change the default value for the document variables and remove the process instantiation form:
Remove contract inputs
Select the pool.
Go to Execution -> Contract.
Remove the file inputs.
Document variables default value
Select the pool
Go to Data -> Documents
For each variable, Edit -> Select None in Initial content
Process instantiation form
Select the pool
Go to Execution -> Instantiation form
Remove the current Target form
That should do the trick :)
Also, check the new version of the file upload example, I removed the limitation that duplicate the document each time the steps is submit:
https://github.com/Bonitasoft-Community/file-upload-download-example
Cheers

Website "you can do this" script

I want to create a training path for new users accessing my site. This training path must display info bubbles showing what you can do on every page, but only the first time you access it.
So, for example, if a user enters a page where there's an edit button an info box should appear next to the edit button telling the user that he can edit that page.
I will create the script myself, I just want to know what's the best method to check if the user has already seen that box or not. I was thinking about storing in database a boolean value for each info box which will be set to true if the user has seen the box. To save some queries from the DB I think I can also store the same values in localStorage or in Cookies.
What is the best practice for creating user training paths for a website?
The way I suggest is to store user id (ip or username ? ) and a bit value for each bubble like you say.
PS: for your script you can use this:
http://www.maxvergelli.com/jquery-bubble-popup/documentation/
Jérôme

Global soft validation for multiple registation forms in cakephp

I've created my website registration functionality using six different steps with different forms..now i want to create
global soft validation for all six steps..
suppose i am new website user..now i clicked on directly registration step 3 then i can able to go directly step 3 without
enterting information for step 1 and step 2..now suppose clicked on previous step from step 3 then i want one global validation array for step1 and step 2..
which will be display on step 2 form when i clicked on previos step from step 3..
If any one have idea about then please let me know ASAP..
You could have a look at the 'validating data from the controller' chapter. You have to write some logic and checks to see which steps/fields been set:
http://book.cakephp.org/2.0/en/models/data-validation/validating-data-from-the-controller.html

Resources