Repeat steps from a previous scenario in later scenarios - python-behave

So I have a scenario outline where I need to repeat those steps in the other scenarios of this feature and I don't want to duplicate the steps manually in feature file.
I tried Background but without success yet.
Here is the scenario:
Scenario Outline: Adding an item to shopping cart
Given I am on home page
When i browse to category
And i click on the product
And I add <x> product to the bag
Then I should see the <x> in my mini-bag
And I click on the basket to verify if I have <x> items
Examples:
|x|
|1|
Second scenario:
Scenario Outline: ...
[I want the steps in the scenario above until
"Then I should see the <x> in my mini-bag" to be executed here.]
Given I am on the basket
When I edit the quantity to <y>
And I click the apply button
Then I should the quantity <y>
Examples:
|x|
|1|
I don't want to use execute_steps for all the scenario's which is duplicating in all the steps.

Related

OpenQA.Selenium.WebDriverTimeoutException : Timed out after 10 seconds

This is my feature file
Given site is opened
Then I Close the modal
Then Find your restaurant page displays
When I select a restaurant name
Then The selected restaurant page displays
When I click "Go" button
I’m totally new to automation testing with bdd using selenium webdriver. I wanted to book a table in a restaurant .When I execute my project I see only first three steps other steps not working and Not selecting the restaurant as well. To select a restaurant I have used SelectByIndex(3) method. I get the below error. Could anyone please help me to rectify this issue?
This is the code I have given in my WebDriverExtensions.cs file
https://i.stack.imgur.com/KflLp.png
enter image description here
I wanted to book a table in a restaurant
The first issue here is one of clarity; Your question omits the code you're using (you mention the method but don't demonstrate it's use), there's no logical Then statement to Assert the end result, and the order of your BDD scenarios is generally unclear.
Due to the lack of information, I can only suggest a change to your BDD scenario syntax to improve the readability of your test. If you want help with the error, I would suggest adding your code in full to the comments or amend your question (please use StackOverflow's formatting tools).
Test Readability - Good Practice:
It's good practice to keep tests short and snappy, in both execution and for readability. Well structured scenarios should ideally have one Given, followed by one When followed by one Then, usually in that order. You can also make use of And and But.
E.g.
Given this is where we start
When I do a thing
Then this is the outcome
Here's your scenario:
Given site is opened
Then I Close the modal [enter image description here][1]
Then Find your restaurant page displays
When I select a restaurant name
Then The selected restaurant page displays
When I click "Go" button
There's a lot of set-up there so it'd benefit from a shared background, and there's no ending Then statement. How you could re-structure it:
Background:
Given the site is open
And the modal has been closed
And the Find your Restaurant page is displayed
Scenario: I can book a table
When I select a restaurant name
And the selected restaurant page displays
When I book a table
Then the success page is displayed
Assuming you're using a SpecFlow / Page Object Model approach, each of those steps creates a Step Definition which, in turn, look at the methods to complete each step. The background can also be used for any other test in the same feature file beginning at the Find your Restaurant page, so you don't need to duplicate those lines.
You could further condense it for readability and just include the necessary methods in fewer step definitions:
Scenario: I can book a table
When I select a restaurant name
And I book a table at a selected restaurant
Then the success page is displayed
If you add comments to your Assertions, you'll still know at what point the test fails.
Making your tests readable, short and snappy will mean you can maintain them better down the line.
Best of luck.

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).

Visualforce Page displaying case count as per case category, On clicking each category I want to get a detailed view of the cases. How?

I have a visualforce page that displays the cases as per categorization(ex - Complaint, feedback etc) and beside each categorization the count of open cases of the category for the particular account. (Ex - Complaint 10, Feedback 5)
Now I want to provide a detailed view of the said 10 cases on clicking the count (ex complaint - 10) on clicking 10.
How to achieve this?
I have used Apex:column to display the case category and count in output link. On clicking this count how do i show the said 10 cases in detail view. Maybe on same VF page or redirect to another page? Which one will be better and how to implement. Any suggestions,Ideas with sample code will be highly helpful. (VF + Controller)
You just need to add the onclick attribute beside each case or use the anchor tag like this <a href='/recordid'>case name</a> so when u click you are just open to a single and details of the single case.
To print the 10 case use <apex:reapeat> tag which can be helpful for iteration the 10 cases
hope it might help you.

How to get Background title in BDD Specflow C#

How do I get the name of the pre test condition "Background" tag in a Feature using Specflow + Nunit in C #?
I can get the name of the "Feature" like this:
return FeatureContext.Current.FeatureInfo.Title;
And the name of the "Scenario" like this:
return ScenarioContext.Current.ScenarioInfo.Title;
I also need to get the name of the "Background", or check if it exists.
Feature: FeatureTest
Description Feature...
Background: Get Background name or check it exists (Return It)
...Given, And
Scenario: Scenario Test
...Given, And
TL;DR
The reason you can't access the Background, is because the steps contained within it are duplicated at runtime across all of the scenarios within a feature, effectively removing the background.
The Answer:
Generally speaking, Backgrounds do not have a title:
Ability: Adding and Removing items from the basket
As a customer,
I want the ability to add and remove items from my basket
In order to choose the items that I want to purchase from the site
Background:
Given I have logged in as a customer
And I visit the "Clothing" page
Scenario: Adding items to my basket
When I add "Black Jeans" to my basket in size "M"
Then the total should be "£9.99"
Scenario: Removing items from the basket
Given I have added an item of clothing to my basket
When I empty my basket
Then the total should be "£0.00"
The Background steps get duplicated across the scenarios within the feature, meaning that the scenarios in my example are effectively:
Scenario: Adding items to my basket
Given I have logged in as a customer
And I visit the "Clothing" page
When I add "Black Jeans" to my basket in size "M"
Then the total should be "£9.99"
Scenario: Removing items from the basket
Given I have logged in as a customer
And I visit the "Clothing" page
Given I have added an item of clothing to my basket
When I empty my basket
Then the total should be "£0.00"
Why would you need to access the Background description, if what you're actually testing is covered by the Scenario description?
That is why currently they do not offer this as a feature. It's additional information within a file that allow ease of reading and understanding of what is actually being tested - but if your steps are descriptive enough, do you need a description for the setup for a test?
This information is currently not available at runtime in SpecFlow. Please open an issue on GitHub for this, that we can potentially add this in later versions.
But generally it is bad practice to depend on such fragile (potential often changing magic strings).
Better way would be to check for a tag on Scenario or Feature level.
Also be aware, that you don't know at runtime, that you are currently executing parts of the background. There is no difference between these Given steps and the Given steps of your scenario.

Can angular ui loader handle complex cases with multiple views?

I have an app with multiple columns (about 3 columns as least), each column is a more detailed view of an item in a column on its left. This type of layout is similar to Asana's.
Lets take an example from 1 of the page I currently have:
Column 1 list all current users, clicking on 1 user will open a list of all sales orders of that user on column 2.
Column 2 show list of all orders of 1 selected user on column 1. Clicking on 1 order will show the details of that order
Column 3 show all details of an order selected on column 2. Clicking on a shipment in that order details will show the details of the shipment
Column 4 show all the details of a shipment selected on column 3
So on a so forth. Now there is another twist:
Column 2,3,4 show these details in a form, which mean they can be edited and submitted. Once they are submitted, it makes sense to reload all the column on the left of that edited column to refresh the info. However, for performance purpose I would like to reload them all in a single request and send them back in one json array hen update each column that has newly returned view code (lets assume the backend code is smart enough to handle all this)
I believe someone must have had this issue before, what is your solution to get around this?
Since you are loading different set of data. Its good not load them all at once. You can use ng-include and the the content of the ng-include can be triggered based on the clicks.
ng-inclue="<<scope variable>>"
For ex. In your controller,
Chnage the value of salesurl based on user action
<div class="slide-animate" ng-include="salesurl"></div>
The scope variable can be an URL, which renders the result set based on the parameters posted after user action.
Hope this help.

Resources