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.
Related
I need to show the Product's Name in the Menu, I think image says it all:
Click here to see the image
I have a menu, with two options, and the first show a text with a variable, but {!Product} don't works, there is a way of this work?
When I put {!Product} in Message or Question, this works normal...
I didn't find any solution for showing the variable in the title dialog, my solution was to change the message to "Know more about this product", I left a generic message.
Old topic but the answer might help someone.
There's a great article explaining how to get some dynamic information https://www.infallibletechie.com/2021/11/how-to-create-case-from-einstein-bot.html
In your case, I guess you need to
Query your products (the out-of-the-box Einstein Bot query is simple and has a limit of 3 items but you could call a flow or apex to get better granularity on the filter/logic and control le size)
Store the query result in a Custom record list Variable
Query data with a flow
Use a dynamic question and merge fields to display what you want
Top configuration of the dynamic question
Down configuration of the dynamic question
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.
I just can't seem to wrap my head around Drupal relationships. I have been reading and watching tutorials, but as soon as I try to get my own project done - I fail. I think it's very basic, so I would love to understand it. Maybe someone here can help me understand how it works :)
On my drupal site, I want to keep track of some private game tournaments.
I have created a content type called contestant, which has fields like: Tournament date, Player name, Final Position. I can then create a view that list the information from one tournament. I used the help I got from this thread: drupal views dynamic filter
I would like to have the view described above as a block. And then place that block-view on a "tournament description" page. I could do this, by simply creating a new block each time, and then manually place it on the page it should be shown (structure-->Blocks-->configure), but that is not an elegant way to do it. I am pretty sure this is where Relationships should be used. But I fail to understand how to create this relationship, so that the specific block view, that matches the specific tournament description page will be displayed together.
Use a Content:Nid as a Contextual filter.
WHEN the Filter value is not in the URL >>
Provide default value
Content ID from URL
I am trying to create a custom lookup page on Salesforce: from a first Visualforce page, I open a second one in which there are a series of available choices; then I click on one of those choices and then I expect the latter page (the custom lookup) to close and the value of my choice to appear in the first page's lookup field.
I am unsure on this very last point: how do I make my choice appear in the earlier page?
As described in this awesome Jeff Douglas post you need to call function lookupPick2 in following manner
top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false);
Please read the entire post to get the full picture.
Where is LookupPick2 documented? When I google for it all I find is code examples and blog posts. Is there any documentation for it? I'll keep looking, but wherever it may be doesn't rank very high...
I have the next issue.
I have a custom object called 'Application', and I have this requirement:
"Show all Contacts related to an Application. Create a field on Application object, must be read only".
I solve it with apex code. 'Application' has a lookup to Opportunity, Opportunity to Account, and all my contacts have AccountId, so this way, I get all the contacts using apex code in a trigger.
But, I've been ask to change this to a Formula field in Application object.
So, my issue is next. I'm not able to get all contacts with advance formula editor, because they're not part of any object. I have no master-detail relationship.
Does any one know how can I achieve this using configuration? I should not use apex code for this req.
Thank in advance guys.
I don't think you can do it.
In formulas / merge fields syntax there's no way to go "up, up then down" (Application -> Opportunity -> Account -> down to Contacts related list). There's also nothing that would let you loop through Contacts (and display what? Ids? Names? Emails?). Roughly speaking you can only go up through dots.
You might want to explore path of "cross object workflow" rules but I imagine that when I add a new Contact to Account it should somehow "spread itself" to all related Applications? There's no straight way to fire a workflow on delete too - so you'd eventually end up with inaccurate list.
I'd say trigger was a good solution. Maybe it ws unoptimized but if it has to be in a field - tough.
There might be a fairly simple way of achieving that by embedding a visualforce page within Application page layout.
This should be doable with pure Visualforce (so technically there will be no Apex code ;))
Something as simple as
<apex:relatedList list="Contacts" subject="Application__c.Opportunity__r.AccountId" />
would be a good start (if you want your own layout and not a rel. list - you should be still able to pull it off with <apex:repeat> or <apex:pageBlockTable>.
There's one BUT here: it's not a field, just a display trick. Forget about using it in reports, mobile applications etc.
Another way - would it be acceptable to be 1 click away from these contacts? You could make a report "Account with Contacts", filter it by Id of one Account and later use "URL hacking" to change the filter depending on from which Application you'll click it. This link could be either a formula field or a real custom button/link. Technically - it's pure config, no apex & VF.
You can read more about URL hacking at Ray Dehler's excellent post and specifically about dynamic Reports here or here.