TestNG Annotations list and execution order

TestNG is testing framework enhancing the Junit framework.

Lets look at different annotations it provides for the test execution stand point.

Following is the list of all annotations that one may require to control after or before facts of test execution. These methods will execute before or after the event is called. These annotations does not depend on the test execution status.


the sample test class with annotations produces following output. All the other annotations does not need any parameters except that before and after group annotation, following is how we can mention the group name.

	public void beforeGroups() {
		System.out.println("Calling before groups");

Output from java console :


While doing console logs, I have struggled to get rid off other console messages produced by the chrome driver. Following piece of code is used to suppress the console logs produced by chrome driver, added this just thought might be relevant to share.

System.setProperty("webdriver.chrome.driver", ChromeDriverPath);
System.setProperty("webdriver.chrome.silentOutput", "true");





Synchronizing web driver and Ignoring Exceptions in C# Selenium API

In general the website response times may cause issues while doing the UI automation testing. Most of the times test scripts will fail due to synchronizations issues from web-driver and the application web elements.

Following are the common reasons and if we see very frequent issues in synchronization it is suggested to do performance testing and tuning.

  • Location from where we are accessing the application (Latency)
  • Network bandwidth
  • Too much firewall checks
  • Website architecture and technology on which website built on.

Most of these cases are taken care while doing performance tuning and performance engineering, but yet we see page load issues, element enabling issues and visibility issues while doing UI automation.

In selenium we have several methods that we can use to make sure that these things are taken care. Following is the just enough explanation about waits in Selenium driver.

Implicit waits will wait until the defined action (example page loading ) is complete.

Example of it is managed time outs, and they are defined at driver level.

Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(30);

When we want to wait explicitly at certain number of seconds we will use explicit waits. As the name suggests the test execution will be halted during this time. Example of it is sleep


here the parameter indicates the number of milliseconds to wait for.

The other case of waiting for dynamic web elements is using wait until or web driver waits. These are most common implicit waits that are used. There are two ways we can use these.

We can declare the web driver wait and and it will wait for max wait in this case it is 30 seconds, and repeatedly we can check for the expected conditions i this case we are looking for visibility of the element google search text box.

IWebElement textbox;
WebDriverWait waits = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
textbox = waits.Until(SeleniumExtras

There is another way we can use this as function delegate, following is how it is used.

//there is another way using function delegate
//delegate parameters and return value = new delegate parameters return value of passed parameters
//delegate is on the fly function generator
Func<IWebDriver,IWebElement>checkForvisibilityOfWebElement = new Func<IWebDriver, IWebElement>((IWebDriver Driver) =>
     IWebElement textBoxDelegate = Driver.FindElement(By.Name(SEARCH_TEXT_BOX_NAME));
       if (textBoxDelegate.Displayed)
           return textBoxDelegate;
          return null;
 textbox = waits.Until(checkForvisibilityOfWebElement);

When you look at above code, its function delegate takes one argument as IWebDriver and returns the IWebElement. The last argument of function delegate is always a return type.

The wait until function will take this and checks for the condition mentioned in the delegate periodically.

If you look at the until you can clearly see this text.


But if we look closely, the description says it will throw exception if it is not listed in the Ignore Exception list.

For that purpose. We have to configure our waits object what exceptions that we want to ignore while we periodically check for our condition. We can achieve this by following.

IWebElement textbox;
WebDriverWait waits = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));


There are list of exceptions that we may want to ignore, following is the snap shot.


And finally following is the list of element states we can wait for.


Please comment if you see anything is incorrect or you want to add something you know. Thank you.