How to mark scenario as failed when the background fails - jvm

I am using cucumber jvm with with background before each scenario. When the background fails the test is skipped but in the end is marked as passed (in the cucumber report).
How can I mark a scenario as failed once it's background failed?

Technically It is not possible that Scenario pass. For Couple reason,
Background always run after every scenario.
Step Definition, You always do assertion to verify background did right job. As you are using Appium, You could verify you are on right page or verify title. It will skipped if you are not using assertion (I believe).
We used background for Selenium automation and in implementation, We verified Title , page URL and certain elements are there to start test. We use given statement.
Background: I login in as system admin
Scenario: Create customer
Given I am on create customer page (Using Assertion verify How all condition)
When I click "Create Customer"
And Verify Field "Username","Address","Gender" "Cell Number"
And I enter customer detail "BostonStar","Boston Downtown","Female" and "888888"
Then I am able to create customer successfully (Verify message)
Scenario:Update Customer
Given I am on create customer page (Using Assertion verify How all condition)
When I update created customer "BostonStar" (Verify customer is in list)
And I select customer and click Update "BostonStar"
And I update address from "Boston Downtown" to "Chicago"
Then I am able to update customer successfully
In both scenario Background will do job or not, I will verify in step stage and decide my further step or failed test

Related

In a hosted Azure Devops environment is it possible to create notifications for fields not provide out-of-the-box?

We are using a hosted AzureDevops (ADO) instance to track requirements, bugs, and manual test runs. I know how to create notifications, and i know how to create new fields in ADO.
My question is: is it possible to create notifications for fields such as "Outcome" which is the result of a manual test case the values of which are active, blocked, or failed.
The goal is to create a notification when: assignedTo=#me AND outcome CHANGES (although, I'd accept most combinations.
From the document Default and supported notifications, We can see it is impossible to create a notification from the test case results on the change of the outcome. For test case results is not a work item, the results changed but the test work item is not changed.
Though it cannot be created in a standard way, you can create a custom field (named OutCome) by creating an inherited process. And change your current process to this inherited process
Then create a custom notification to send you an email on the change of the field outcome. You have to manually update the outcome field of the test case from Boards.
You can also go to Developer community to submit suggest a feature request. Hopely Microsoft development team will consider this feature and adding the notification for Test case results.

Automated testing - Best practice - getting test data before test

I have a question about getting test data for automated testing, here is my problem:
I need to prepare automated testing scripts for a clothes shop.
And I need to know what is the best practice for getting test data needed for the following scenario:
Scenario description: Checking if a user can correctly add a product to the basket.
Given I am on the "WOMEN'S DRESSES" page
When I add "XXX" product to the bag
Then I can see "XXX" product displayed in the basket
My question is: how to ensure that the "XXX" product is always available and what is the best practice for this?
Do I have to always connect to the env database and check if the "XXX" product is available and if not then insert it into DB?
Or maybe should modify a little BDD scenario and get the list of currently available products on the "WOMEN'S DRESSES" page, chose any product, add it to the bag and check if it is correctly added to the basket? ( but in that case what to do if there are no products available for the testing env ?)
I want to have efficient and strong automated tests.
There are a few options for this. Some developers and I looked into a similar problem we had for a car-marketplace. We actually found out that the "dirty" way was the best way for us.
We simply did a BeforeFeature database query and picked up all brands which were available in the test environment. We added these brands to FeatureContext and ScenarioContext, depending on the required context. Because of the Feature/Scenario context, you can use these values during the run of that particular feature/scenario. During the "When" step, in the code, we created a list of all the brands available in the database.
Then, we passed every brand through specflow to the code and checked the list if it contained the brand. If the list did contain the brand, a click had to take place on that brand and we checked in the last step if we were landed on the page of that brand.
You could do something similar with the dresses.
So our specflow looked somewhat like:
Scenario Outline: Check available brands till vehicle detail page
Given I navigate to Vehichle Search Page
When I search '<Brand>', if available in test environment
Then I am navigated to the vehicle detail page
Examples:
|Brand|
|Audi |
|BMW |
|etc |
Just an addition:
This way of writing test keeps your test very BDD. Business can read what your are testing. Also, as long as the data model remains as-is, your tests are very maintainable. You can add unlimited amounts of dresses to your table and you will only get test results if the brands are available. So if the database is swiped clean, sure, not a single test will be executed, but you won't get any false positives or unnecessary negatives.
Also, you can choose to add brands to the database if they weren't found in the first place. You could do this within the "When" step. If the dress is not found in the list, you can add it with a query in the database at that moment.
In your case you have to add one more precondition:
GIVEN: XXX product is available on the "WOMEN'S DRESSES" page.
If product is not available - it's another test case )
Create XXX product just before test using most suitable way:
api call
web UI
DB update (not recommended)
or just mock api response for XXX product

JBehave: How to run specific set of stories from the whole collection in .story file

Let's say I have a Main.story file which contains-
Login Scenario
Search Scenario
AddToCart Scenario
UpdateQuantity Scenario
Checkout Scenario
But now what if I only want to run-
Login Scenario → Search Scenario → AddToCart Scenario → Checkout Scenario and skipping UpdateQuantity Scenario
How could I possibly achieve this without removing/deleting anything from the story file.
BDD style scenarios are meant to be completely independent. In this case, you would have 2 scenarios:
Scenario: I can check out with an updated order quantity
Given I login
And I search
And I add to the cart
And I update the quantity
When I checkout
Then I get a confirmation email (or whatever)
Scenario: I can purchase items
Given I login
And I search
And I add to the cart
And I update the quantity
When I checkout
Then I get a confirmation email (or whatever)
If there's a concern about each of those steps actually being several steps and that looking really ugly in the scenario with 20 givens, so long as each of those actions is tested separately, you can use a compound step. That's a step that, in its definition, calls other steps (through code, not Gherkin). You take the same actions, but the Gherkin has far fewer entries.
The important part is that no scenario should require action from a previous scenario in BDD.
To further clarify, there is a way to re-order things if you really must, but it's very bad practice. If you choose to go that road, see this question:
How do i execute story files in specific order in serenity BDD Jbehave

What to do when an acceptance test has varying user choices and you want to test each of them

I'm writing some acceptance tests for a donation form. I'm using Codeception. For the sake of this example, lets say that the donation form has 3 parts:
Enter your personal information
Enter either Credit Card and Direct Transfer
Submit and receive e-mail confirmation
For the acceptance test I'd like to test the whole process--for both credit card AND direct transfer. Steps 1 and 3 are essentially the same between the two donation processes, but--obviously--you can't run the second step by itself (the donation form wouldn't submit without step 1).
So I'm wondering, would it be "normal" in this case to write two tests (e.g. canDonateWithCreditCard() and canDonateWithDirectTransfer()) that both test all three parts of the process? Even though that's partly testing the same thing twice?
If not, what would be the preferred way to do it?
This is perfectly acceptable at my work we have a sizable automation suite where the same pages get executed multiple times, because of scenarios similar to what you outlined above.
The only caveat I would mention is when building your tests (I don't know how codeception works) but look to build your tests using something along the lines of the page object model (http://martinfowler.com/bliki/PageObject.html) this will mean even though you have multiple tests that may implement the same scenarios each test doesn't have its own implementation of those steps.
This depends on your approach.
1. You can create two different test cases performing the action.
2. You can have a logic in your test to pass the mode of transfer as an argument to the method and perform activities accordingly.
It's always ideal to use Page object model to encapsulate all actions in each page class and also to avoid redundancy.
If both Credit card and Direct transfer actions navigate to a new page, create a new object of the page according to the argument passed, and call the method to do the transfer action.
A simple page object class can be created like this:
http://testautomationlove.blogspot.in/2016/02/page-object-design-pattern.html

How to i automate a test that targets values that change from one test to another?

Currently I am testing an online shop. I want to automate the checkout process but each time an item has been added to the cart and the checkout process is completed that particular item is removed from the list, and the second time the test runs, it returns an error because it can not find the item.
Is there any way I can build a test that completes the test without failing because it can not find that particular item ?
I am using Selenium with PHP and Selenium IDE.
Please note that I am just a beginner in automation.
Any help would be appreciated.
Best regards,
Radu
Whatever the test you do, you should be very confident with the expected initial situation of your system under test when the test starts. In your case, if your test needs a specific item to be available, then this should be part of your "test setup" section.
Let's say you have 100 tests that needs an item to be available.
I can see 2 different strategies to solve your issue:
At the beginning of your test suite, deploy a custom brand new web site with your 100 products available. Your tests will update/destroy those data but you don't case because next time you run the test, you will deploy a brand new set of items.
At the end of each test case, you do a custom-action that will clean your system by adding the item back in the shop.