How to write scenario to verlify a list of values displayed? - gherkin

How to write a gherkin scenario in which the user clicks on a menu button and he should see a list of sub-menus displayed.I tried:
Scenario Outline:Display of the login page
Given User is an admin
When user clicks on the menu
Then he should see the <list> displayed
Examples:
| list |
| loginform, UsernameField, PasswordField |

Your description of the scenario and the scenario itself contradict each other. You write about sub-menus, the scenario lists fields. As the very first step, discuss the scenarios with your colleagues. When you have a clear plan, you can take on the syntax.
Syntax: why would you use a Scenario Outline when you only have a single example?

Related

Cucumber: loop over only part of the Scenario

is there any possibility to loop part of the scenario instead of all steps.
Below I have prepared an example, I want to login and click a list of links, but I want to execute the login-part only once. After logging the clicking part should be looped.
Scenario Outline
Given I am on Homepage
When I enter Email and Password and press send
And I am logged in
*And I click the link <link>
Examples:
| link1 |
| link2 |
| link3 |
| link4 |*
You should split your scenario in that case. Make the login as a scenario, do not close your driver in between scenarios. Now make the I click the link as a scenario outline in the same feature file.

How to use data table in background in cucumber

I want to execute common steps for few test cases.below are the common steps.But in background,since i cannot use Scenario Outline,what is the alternate?
Background:To test employee id search
Scenario Outline:
Given I am on login Screen
When I enter credentials "<User_ID>" and "<Password>"
When I clicks on search button
And search by "<Employee_id>"
Examples:
|User_ID|Password |Employee_id|
|Admin |Password | Q58ewQ |
A scenario outline is a way to run several scenarios whilst writing just a single scenario. Background is a set of steps to run before each scenario. You can't put an outline in a background, it makes no sense.
A Background is used for steps that will be run before each Scenario (or Example) in the feature file.
Each Scenario Outline will run as a separate Scenario / Example.
You cannot use Scenario Outline inside a Background, as that would make no sense.
Please check the links to the documentation for more information.
This is example is very imperative, BDD need to be declarative. Best Pratices BDD
Why do you create one method that do login.
Login(username, password){
set username = username;
set password = password;
clickButton;
}
And create one step.
Given the user logged on the system
login(username, password)
This is step do you use with background.
You can use Data Table in Cucumber Background :
Background:
Given User is on Home Page
When User Navigate to LogIn Page
And User enters Credentials to LogIn
| testuser_1 | Test#153 |
You can use a table in Cucumber Background:
Background:
Given I open Google's search page
When I use the following keywords to search in the Google's search page:
| CucumberBDD |
| CucumberHooks |

Can we use scenario outline for background steps

I am using POM with cucumber. I have 3 scenarios to execute where half of the steps are common for all the scenarios. So I am using background keyword for common steps. But I need to pass data through Example keyword to the steps defined in Background as well. How do I do it?
Below is my background
Given User is on login Screen
When user enters "<User_ID>" and "<Password>"
Then verify successfull login
When user clicks on search button
And search by "<reference_number>"
Examples:
| User_ID | Password |reference number |
| Abc | XYZ |ABC123 |
You are not able to pass example data from a scenario outline to the background. You will need to include those parameterized steps in the scenario outline rather than the background. If one step depends on another, they are probably stuck repeating steps in each scenario.

Broadleaf commerce display some product to logged in users only

I am developing an e-commerce application using broad-leaf commerce.
My requirement is I have to add an product from login panel and display that product to only logged in users. Here few product products will be visible to all users (guest too) and few will be visible to only logged in users.
is there any way to do this?
Thanx soulfly1983 fou your try,but I found another alternative to do this without any customization. here is the full procedure..
Add a new category from admin panel.
Add a new page from admin panel (under content tab) and note the URL should be the same of category and page.
3 In the page click on rule tab.
4 Check the yes button in "Restrict to certain customers?"
Click +rule button and the select "match all" and select customer registered is equal to false
So this page will be visible to only guest users.
In the HTML body section of the rule (in general tab) write a message "you need to log in to view this stuff"
When user will log in successfully the user will not be able to the page , because we applied a rule that only logged out users can see the page so this time user will see the category and products added to that category.
am I doing right? any regarding this suggestion?
You can either extend the Product entity and add a field that will indicate whether that product will be visible to all users, or alternatively you could simply add an attribute for each product via the admin interface. Either way you will need to modify the UI logic so that it will take this additional field (or attribute) into consideration.

What is a good way to test with Cucumber

I start learning to write Cucumber test, and now I can write the test, but my test is too silly; I don't know I should focus what and ignore what. I always ask my co.op how to write a good test with Cucumber, and they give me some advices, but I feel not satisfy enough. So, please tell me about your opinion and give me some examples, thanks so much!
EDIT
I had an index page with a table, and 3 buttons(edit, detail, delete) in the last column each row of the table
and 1 button Create below the table, and the nav bar has a login form
So what thing I should check?
In my opinion, I think we shouldn't check login function and the content of the nav bar, because every page in this controller has the same layout
Maybe we should check total columns, total rows, the title, the icon css, the content of button, the css of whole page (border of table, width, height, font-family) ... Is this true?
I think you should prioritise the elements in your page, and check them.
As an example, when you test the login page:
Important elements of the login page
user name, password text boxes
login button
Not important elements (This all depends on your business requirement)
cancel button
other fancy text
etc..
and then in your Cucumber test, make sure you check the availability of user name, password text boxes and login button. The rest of the elements you can ignore. Otherwise you will be spending unnecessary time on testing non-important things.
Again, the priorities of your given page is depending on the business requirements of your project.