This is going to be a follow-up post in regards to the approach i showed at my SeleniumConf talk, on doing Selenium tests by using an Object Oriented approach.
I will have a series of such posts, to show more examples and to make it easier to understand how to use it. All the code presented here will be available in GitHub under this location: https://github.com/iamalittletester/learning-project. Continue reading Selenium tests, the Object Oriented way – example 1 (with code)
Here’s a new and (possibly) cool feature regarding the blog: there are now code examples to be checked out and tried that you can download from Github.
The code location is: https://github.com/iamalittletester/learning-project.
Here are some details and how to run the test project: Continue reading GitHub project available with code examples
When i look at a test class, what i want to see is clean code. What i mean by that is, well a few things, but the most important one: i want the test class to hold the code for the tests, not the code for everything but the kitchen sink.
When we write tests we have a lot of data to prepare for them. Whether this is the ‘expected’ or the ‘actual’ data used in the tests, or some auxiliary code that we need, there always is some processing that needs to be done, apart from the actual asserts that a test should do. What the test class should contain is only the checking / asserting part, while having specialized classes generate all the data that is required in the test. A test class should only check the actual data against the expected data. This is the separation of concerns principle. Continue reading Write clean code for your tests by using the separation of concerns principle
Following on from some of my earlier posts, where I described some of the useful utils from the apache.commons.lang3 library (like that very nice RandomStringUtils class), this time I will focus a bit on the StringUtils class. As the name suggests, it provides developers and testers an easy way to deal with certain String related operations. The class is quite large, so in this post I will cover the ‘substring’ category. As the name suggests, these methods deal with extracting substrings from a larger string, based on some conditions. Continue reading Extracting substrings with StringUtils from the Apache library
In my previous post i talked about how to check whether an element is displayed or not. There are times when tests where such an action is performed fail randomly (sometimes they will pass, other times they won’t). The assumption here is that the element was not displayed within a decent amount of time when there were test failures, but would have appeared later on. Therefore if the test would have waited a little bit before performing the presence check, it would have passed. Continue reading Selenium: How to wait for an element to be displayed / not displayed
One of the most frequent kind of interactions with the web page when testing with Selenium is checking whether a particular element is present. More specifically, whether it is visible when looking at the page and does not have a “hidden” attribute. The isDisplayed() method is used for such checks, but in many cases it is not used properly. Some tests appear to be unreliable Continue reading Selenium: How to correctly test whether an element is displayed (or not)
When you have more than one assertion in your test, you might want one of two things:
- Have your tests fail once the first assertion failure is encountered.
- Have all your assertions run, no matter if they have passed or failed. Of course, after they are run, if there are failures, you want the test to fail, and also show you where the issues were.
Continue reading SoftAssert – don’t make your test fail on the first assertion failure