How do I write this BDD script? - testing

I have an exit button in my application which I want to write a story for. It behaves this way:
If I have content filled in the form I am editing and I click on the exit button, it will pop up with a confirmation message letting me know there are unsaved content and if I am sure I want to exit from the page.
If I do not have any content filled in the form I am editing and I click on the exit button, the confirmation message will not show up and I am instantly exited from the form.
What I have so far is something like this:
Given as a User on New Profile page
And I fill in the customer name = "Bob"
When I click on the Exit button
And I click on the "Ok" in the confirmation dialog
Then I will be redirected to the landing page.
My question is the part on And when I fill in the customer name = "Bob" only covers one of the fields. How do I write the story in a succinct way that if any of the fields are filled or chosen (drop downs), the confirmation dialog will show up ? Secondly, is my story correct ?

You can use a scenario outline in conjunction with parameterizing the step that fills in a field with a dummy value.
Scenario Outline: The user is taken to the landing page after exiting new user profile
Given I am registering as a new user
And I have filled in the "<Profile Field>" field
And I have chosen to exit the current page
When I confirm I want to abandon my unsaved changes
Then I should be redirected to the landing page
Examples:
| Profile Field |
| Name |
| Phone Number |
| ... |
You didn't post the scenario title, which is just as important as the wording for each step, so I made on up. The important thing is to focus on the behavior:
Scenario Outline: The user is taken to the landing page after exiting new user profile
The step Given I am registering as a new user should navigate to the new user profile page.
The step Given I have filled in the "<Profile Field>" field should accept an argument where you name the field you want filled in. The definition for this step should fill in the field with dummy information, or blindly chose an option in a dropdown.
The step Given I have chosen to exit the current page should click the exit button. Notice there is no mention of "clicking" on anything. You should avoid language in your steps the sound like instructions on how to use the user interface, and instead focus on the behavior of the application using business terms.
Same thing for When I confirm I want to abandon my unsaved changes. It does not mention clicking on anything. It just focuses on the behavior (choosing to abandon your changes). The step definition should know how to click the "OK" button in the confirmation dialog. The fact a confirmation dialog even exists should only be known by the step definition.
Finally, Then I should be redirected to the landing page makes your assertion about where the user ends up. I like to include the word "should" in my Then steps. If find it easier to pinpoint the test failure when a Then step fails. The condition that comes after the "should" in my step is usually the thing that fails.

you can use datatable in that particular step as below
Given as a User on New Profile page
And I fill in the customer details
|name|address1|adress2|pincode| //can be accessed with DataTable datatype in SD*
When I click on the Exit button
And I click on the "Ok" in the confirmation dialog
Then I will be redirected to the landing page.
*SD-Stepdefinitions

Related

How to make Background keyword as a runner scenario in cucumber?

I am trying to test Amazon website with 3 scenarios on selenium with cucumber. For writing gherkin structure. I concat my login functionality with other scenarios with the Background keyword. But this time the problem is that my scenario number is decreased from 3 to 2. Basically, I want to also test the login functionality and make the terminal close and go to the other test scenarios. Instead, the code behaves login and searching product functionality as one scenario and closes its terminal.
The below gherkin language is my Amazon.feature;
Feature: To be able to shop through the website in e-commerce platform, Amazon.
Background:
Given User is on homepage
When Click accept cookies
When User click login button
When User click EmailBlank
And Enter e-mail address
And User press continue button
When User click PasswordBlank
And Enter password
And Click SignIn button
Scenario: Finding the product from the website
When Click the search button
When Write product name
When Click search button
When Filter for Shipped by Amazon
When Filter for Apple
Scenario: Adding and deleting product to cart
#the upper scenario
When Click the search button
When Write product name
When Click search button
When Filter for Shipped by Amazon
When Filter for Apple
#the upper scenario
When Click the first product
When Add to Cart
And Close the Cart
And Click the Cart
When Check at cart page
When Delete the product
I tried to put the Scenario below the Background but this time 2nd scenario is run without logging into the website. I also put Scenario before the Background and get the syntax error.
You can write an Scenario with 1 step that not exist in Background:
Scenario: Login with valid credentials
Then check some extra data here belongs to login function thaat is not included it background
Instead of writing
Given User is on homepage
When Click accept cookies
When User click login button
When User click EmailBlank
And Enter e-mail address
And User press continue button
When User click PasswordBlank
And Enter password
And Click SignIn button
write
Given I am signed in
and push HOW you sign in down into the step definitions. Once you have done that go further and push HOW you sign in down into helper methods called from your step definitions.

Dynamic action to update database record AND redirect to a different page

I'm building a system of modal dialogs to allow users to edit database records.
The user clicks the "Edit" button on a specific row in a report somewhere
A modal dialog pops up, with fields that the user can edit and manipulate
The dialog has four standard buttons the user can select: Cancel, Delete, Save, and Create
Let's start with the Save button.
By default for modal dialogs, the Save button has the following behavior:
I presume this 1) submits the information from the items in the modal dialog (which refreshes the browser, closing the modal dialog), and then 2) performs the SQL UPDATE action with the submitted information, in time for the refreshed page to include the updated information?
This is fine, but I need to:
Avoid refreshing the browser (e.g. submit individual items, rather than the whole page), and
Manually redirect to another modal dialog (a different page) AFTER the SQL UPDATE action is completed
I presume this can be accomplished with dynamic actions, but I don't know how.
How can I ensure the database action is completed, before the dynamic action which navigates to a new page?
Manually redirect to another modal dialog (a different page) AFTER the SQL UPDATE action is completed
I'm thinking of creating a branch with Server-side condition set to "When button pressed" (for every button), or perhaps "Request is contained in value" where request name (by default) equals button name.
So: button would first do its processing part, and then branch to another page, without involving dynamic actions.

Multiple forms, keep original input even though form is never used again

in my project I have 3 forms.
On the first form is a textbox which gathers a username, which is then checked against a database and, if confirmed, logs the user into the project.
On the third form, there is a label that displays the username that was entered in the first forms' textbox. When the user is done with a project, they click a button that gives them the choice if they wish to start over...if yes is clicked, they start over from the second form (I don't want them to have to "login" again.
The first general run through the program works fine (first -> second -> third form)...
My problem is, since the first form was closed, never to be seen again, the data that was entered in the first forms' textbox is now gone and the third forms' label just displays "label1"
Is there a way to make it so they user logs in once (the first form) and then continues on about the project (going through the second and third forms over and over again) without having to login again? And having that label KEEP the original "username"?
Thanks to everyone in advance!

How to validate the optional field?

As per the requirements, "XYZ" field is mandatory field, but this field is optional in the form which I am testing.
"XYZ" is a text field. So when I automate the form, whether that field is empty or filled it passes. In reality, this test should fail.
I am using TestNG and selenium.
Thanks!!!
Leave the text field empty, click on Submit to submit the form.
Check for any validations "Please enter text here." or "1 missed field".
if the the validation alert is not seen, the test script will fail and that is how you will catch it.
Think of selenium as a way to replicate a real user click through on a website. So when manually clicking through, you clicked to submit the form and went to the next page when you actually expected a validation alert.

Wix - getting info from a Browse dialog for display in an Edit (not PathEdit) box?

I'm building an installer where a given page is asking for a directory. Unfortunately I'm not allowed (by the customer) to force an initial value into the entry (it must be blank), so using PathEdit is out--I have to use a raw Edit control. I've added a Browse button that invokes the BrowseDlg, but the question is: how to show the value entered in the browse dialog?
I've seen recommendations of duplicating the original page, since I can't update the original textbox on the initial page. While that seems workable, how can I get to the 2nd copy of the page? The button to open the Browse dialog invokes SpawnDialog. Doing it as a NewDialog looks really cheesy, and doesn't match the use of Browse dialog for the installation location, where it just pops up. But when the SpawnDialog returns, it just stays on the same page. There's no condition I could come up with that would allow me to add a NewDialog to go to the 2nd page, or to any other page for that matter.
Any ideas on how to proceed, so I can show the entered Browse value?
I suggest using a custom action and an edit box similar to this post. You can use a FolderBrowserDialog instead of the OpenFileDialog. It works for me, but upon a second install the field will be populated with the previous value.
http://community.saasgrid.com/developers/b/team/archive/2011/02/17/wix-managed-custom-actions-openfiledialog-example.aspx