In Selenium WebDriver 2.53.0 release, we have new methods addition in ExpectedConditions class. All are really helpful for extensive validations and adding synchronization points in test scripts.
The White framework does not send an action until a window has entered the idle state after the previous action. In that case, White framework waits automatically if a window is busy.
But how to wait for an element or a particular condition? How to avoid Thread.sleep during automation script development? In White, we can write our synchronization points. In this article, we will show you White framework waiting techniques and commands which are being used in all our desktop automation testing projects at Codoid.
Wait Based On HourGlass
Using WaitBasedOnHourGlass property (default value true), you can configure wait based on presence of hour glass.
WaitWhileBusy method makes your script wait until the window is busy. Note: You no need to call this method for every action as it is called automatically at the end of every action.
Wait Hook
If you want to write your custom delay and the written custom code needs to be called after every action, then you can use IWaitHook interface as shown below.
public class CustomWait : IWaitHook
{
public CustomWait()
{
CoreAppXmlConfiguration.Instance.AdditionalWaitHook = this;
}
// Implementation of the IWaitHook interface
public void WaitFor(UIItemContainer uiItemContainer)
{
...
}
}
[/code]
Browser window resizing and positioning can be done easily using Selenium WebDriver. Consider we have opened multiple browser windows in same machine for parallel execution; it is very useful to view execution on each window, if it is positioned and re-sized for user view at run-time.
Window Resize
driver.manage().window().setSize(new Dimension(100,100));
//Note: Dimension should be imported using org.openqa.selenium.Dimension
Window Position
driver.manage().window().setPosition(new Point(100,100));
//Note: Point should be imported using org.openqa.selenium.Point
In this blog article, we show you how to stop Selenium Server using Apache HTTP Client GET method. The Apache HttpClient library simplifies handling HTTP requests. To use this library download the binaries with dependencies from http://hc.apache.org/.
//URL to stop Selenium Server
String strURL="http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer";
//HTTP Default client Object
HttpClient client = new DefaultHttpClient();
//HTTP Get Object
HttpGet request = new HttpGet(strURL);
//Executing the request
HttpResponse response = client.execute(request);
In CSS Selector, we have a very useful structural pseudo-class selector i.e. ‘nth-child’ selector. ‘nth-child’ can be used to select ordered elements by giving the expression (an+b) or single element with positive integer as an argument. Consider if you want to get odd rows from a HTML table using Selenium WebDriver, your immediate idea will be ‘separating odd rows using FOR loop’. But we can accomplish it using nth-child (2n+1) selector.