In my previous article Design Grid Control Automated Tests Part 1
I started this mini-series about writing decent grid control's automated tests. In this second part, I am going to talk about how to automate floating-point and date columns.
Design Grid Control's Tests- Floating-point Column
There are six filters that need to be automated- EqualTo, NotEqualTo, GreaterThan, GreaterThanOrEqualTo, LessThan and LessThanOrEqualTo. Also, an additional test should be added to verify that the clear filter functionality is working as expected.
Freight EqualTo Filter
First, we create a new item in the DB. After that, we assign to the freight a new unique value. We can filter directly on it, and we expect that only one entity should be displayed. After the filtration, we wait for the grid to load a single item, get all the elements and assert that only one item is present.
Freight NotEqualTo Filter
The arrange phase is identical. However, the additional thing that we do is to filter by the order id. This way, only the arrange order should be visible after the first filter. After that, we apply the NotEqualTo filter and assert that no elements are visible in the grid.
Freight GreaterThanOrEqualTo Filter
The arrange phase for this test is a little bit trickier. First, we get the biggest freight amount from the DB. Then create two new items. We make sure that we update the freight amount of the first element with a greater value than the currently largest freight. The second item's freight value is bigger than the second item's one. This way we have two unique numbers located at the end of the array of all freights' values. When we filter by the first item's freight amount, we expect that only our two new entities should be visible on the grid. If we want to extend the idea even further, we can create a new third entity and assert that it is not displayed.
Freight GreaterThan Filter
The only difference with the previous example is the type of the applied filter. When we apply the GreaterThan filter, we assert that only the second item is visible on the grid.
Freight LessThanOrEqualTo Filter
The arrange phase for this test is similar to the ones for the GreaterThan filter. We create two new items. Then get the smallest freight amount from the DB. We assign an even smaller new unique number to the first item's freight. Using it, we initialize the second item's freight with a lower value. When we apply the filter, we assert that only these two elements are displayed.
Freight LessThan Filter
The arrange is identical, at the end we assert that only the second item is visible.
Freight Clear Filter
Here we create two new items. The first one has a unique freight. When we filter, it is the only element displayed on the grid. When we clear the applied filters, we assert that both entities are visible.
Design Grid Control's Tests- Date Column
There are six filters that need to be automated- EqualTo, NotEqualTo, IsAfter, IsAfterOrEqualTo, IsBefore, IsBeforeOrEqualTo. Three additional test cases should be added- one for clearing the applied filters, sorting ascending and sorting descending.
OrderDate EqualTo Filter
We create a new item. Then we get the biggest order date from the DB. After that, update the new item's order date with the biggest order date + 1 day. This way when you apply the EqualTo filter by order date, only the new item should be displayed. Again, if you want to run the tests against an empty DB, probably it is a good idea to create a second entity and make sure that it is not visible.
OrderDate NotEqualTo Filter
Here we create two new entities. Make sure that they have new bigger order dates than the largest date present in the DB. Also, the new items contain an identical new unique shipping name. The first filter we apply is by the shipping name. We expect that only the new entities should be displayed. With the second NotEqualTo filter by the shipping name, we expect that only the new objects should be shown. With the second NotEqualTo filter, we can verify that only the second item is visible on the grid.
OrderDate IsAfter Filter
The arrange phase is the same as the one for the NotEqualTo filter. The dates are arranged in such a way that the first item's date is before the second item's one. So when we apply the After filter, only the second entity should be displayed.
OrderDate IsAfterOrEqualTo Filter
Identical to the above example except we assert that both items are visible on the grid.
OrderDate IsBefore Filter
The only difference from the After filters is that instead of adding days to the smallest date we subtract them. When we apply the IsBeforeOrEqualTo filter only the second item should be displayed.
OrderDate IsBeforeOrEqualTo Filter
Only the applied filter is different, and we assert that both entities are shown. If you want to execute the tests against an empty DB, create a third new object, otherwise you cannot be sure that the filter is doing the right thing.
OrderDate Clear Filter
We create a new item. After that, we filter on a non-existing date. No items should be visible. When we remove the filter the new item should be displayed.
OrderDate Sort Ascending
We apply the same arrange as for the Before filters. After the filter application, we sort ascending. At the end of the test the items are asserted that are displayed in the correct order.
OrderDate Sort Decending
Only the assert order of the entities is different as well as the applied filter.
If you enjoy my publications, Get Instant Access to my future PRO tips and trips.
So Far in the 'Pragmatic Automation with WebDriver' Series
The post Design Grid Control Automated Tests Part 2 appeared first on Automate The Planet.
All images are purchased from DepositPhotos.com and cannot be downloaded and used for free.