Tag Archives: testing

Better Test Code Principles #5: Mind your try/catches

Using try/catches to handle exceptions has become quite fashionable when writing tests with Java. However, this approach is also a frequent source of having false positives while running tests. Many times when writing the tests people forget to consider both sections of this code block: they forget to write the appropriate code in both sections – the code that deals with not encountering the exception (if the code in try executes) and the code that deals with encountering the exception (if the code in catch executes).

Continue reading Better Test Code Principles #5: Mind your try/catches

Selenium: How to wait for an element to be displayed / not displayed

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

SoftAssert – don’t make your test fail on the first assertion failure

When you have more than one assertion in your test, you might want one of two things:

  1. Have your tests fail once the first assertion failure is encountered.
  2. 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

How to identify the test scenarios you have to automate

Suppose you are starting work on a new piece of software that you will need to write automated tests for. Your goal is to cover the most relevant test scenarios that apply to the feature , without missing or forgetting one. Below are a few steps (guidelines) to help you achieve identifying those required scenarios (a sort of ‘how i do it and it works for me’ guide). Continue reading How to identify the test scenarios you have to automate

Quick Tip: Selenium – Taking screenshots (of regular tests and test failures)

The What

During Selenium test execution, i want to store a screenshot of what is displayed in the browser to understand in what conditions the test ran.

Continue reading Quick Tip: Selenium – Taking screenshots (of regular tests and test failures)

Quick Tip: Running automated tests in parallel

The What

I have a bunch of tests that i would like to run faster, by making them execute in parallel. In my tests:

  1. I am not using a DataProvider and only want to make the same test run several times.
  2. I am using a DataProvider and want my test to run with the provided values from the provider, but in parallel.
  3. I am not using DataProviders, but my tests are ran by using the textng.xml file that specifies which tests to run (as per this article).

Continue reading Quick Tip: Running automated tests in parallel

Quick Tip: Selenium – select / deselect a value from a dropdown

The What

Having an HTML dropdown on a web page, i would like to select, via Selenium, an element from it, or deselect the selected one.

An example of an HTML representation of a dropdown can be found below – it displays a list of winter months:

<select id="winter">
 <option value="Dec">December</option>
 <option value="Jan">January</option>
 <option value="Feb">February</option>
 </select>

This element would look something like:

dropdown

The task is to easily select / deselect an element from the dropdwon.

The How

Continue reading Quick Tip: Selenium – select / deselect a value from a dropdown