biz.neustar.wpm.api
Interface WebDriver


public interface WebDriver

The WebDriver interface to a browser opened with Test.openBrowser(). Reference documentation for WebDriver can be found here: WebDriver Documentation. More specifically: WebDriver Documentation. Currently we are using Selenium WebDriver version 3.5.3.

Navigating

The following example navigates the browser to www.neustar.biz:
   driver.get("http://wwww.neustar.biz");
 
Clicking a link or submitting a form requires finding HTML elements and manipulating them. This is discussed below.

Finding Elements

Elements on the current page can be located by calling WebDriver.findElement(). For example to find an element named "q":

   var element = driver.findElement(By.name("q"));
 
Find an element by id:
   var element = driver.findElement(By.id("q"));
 
Find an element by link text:
   var element = driver.findElement(By.partialLinkText("Search"));
 
Find an element by text (in this case a div element with the text "this is the text"):
   var element = driver.findElement(By.xpath("//div[text()=\\"this is the text\\"]"));
 
Sometimes it is necessary to find an element in the DOM using more complex queries. For example, the element you want to interact with may not be uniquely named or its name may change every time the page is loaded. In these cases elements can be located using CSS Selectors or XPath: CSS Selector Example:
   var element = driver.findElement(By.css("a:first-child"));
 
XPath Example:
   var element = driver.findElement(By.xpath("//td[@class='gac_c']"));
 
WebDriver.findElement() returns a WebElement. This allows findElement() calls to be nested:
   var innerElement = driver.findElement(By.id("top")).findElement(By.id("inner"));
 

User Input

To click a link, find the WebElement and call WebElement.click():

   driver.findElement(By.partialLinkText("Search")).click();
 
To submit a form, find the WebElement corresponding to the form and call WebElement.submit():
   driver.findElement(By.id("my_form")).submit();
 
Typically before submitting a form, you will need to fill it out. This can be done by finding each field of the form and sending key presses to it. For example to enter text into a field with the id 'name':
   var form = driver.findElement(By.id("my_form"));
   var name = form.findElement(By.id("name"));
   name.sendKeys("mossy");
 
To select an item from a list or a drop down combo box use the Select class:
   var form = driver.findElement(By.id("my_form"));
   var selectState = new Select(driver.findElement(By.id("state")));
   selectState.selectByVisibleText("CA");
 
More complex interactions, like double clicks and drag and drop can done using the Actions class:
  var card = driver.findElement(By.id("card2"));
  var box = driver.findElement(By.xpath("//div[text()=\\"two\\"]"));
  var action = new Actions(driver);
  action.dragAndDrop(card, box).build().perform();
 

Waiting for elements

By default calling findElement() will throw an error if the element cannot be found.

It is also possible to force findElement() to wait a certain period before giving up. This can be done by extending the timeout on findElement() (by default this is zero seconds).

     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
 
Another flexible way to wait is to use Test.waitFor(NativeFunction, long):
 test.waitFor(function() {
   return driver.getTitle().toLowerCase().startsWith("cheese!");
   }, 2000);
 
This test.waitFor can be used to wait on any condition.


Method Summary
 void disableHttpChecks()
          Do no checking at all for valid HTTP responses when a page-load is triggered.
 void failOnHttpError(boolean shouldFailOnHttpError)
          Configure whether the WebDriver should throw an Exception in case a page-load receives one or more HTTP Error Responses (400 <= code < 600).
 void failOnHttpErrors(int[] failOnHttpErrorCodes)
          Configure whether the WebDriver should throw an Exception in case a page-load receives at least one of the http error codes specified in the input array.
 HttpClient getHttpClient()
          Returns the HTTP client through which browser requests are proxied.
 void scrollTo(int left, int top)
          Scrolls the browser by left and top amount.
 

Method Detail

getHttpClient

HttpClient getHttpClient()
Returns the HTTP client through which browser requests are proxied.

Returns:
the HttpClient interface

failOnHttpError

void failOnHttpError(boolean shouldFailOnHttpError)
Configure whether the WebDriver should throw an Exception in case a page-load receives one or more HTTP Error Responses (400 <= code < 600).

Default is "false": if a page-load returns at least one HTTP Valid Response, it is still considered valid. (same as calling failOnHttpErrors(int[]) with an empty array [])

failOnHttpError(boolean) and failOnHttpErrors(int[]) are mutually exclusive: if a script calls both only the last call will be have its effect.

Note: This is applied to a page-load only if it's executed inside a "step".

Note: Given this is set to "true", if either a Blacklist and/or a WhiteList has been defined the status codes of the affected requests will not be taken into account as the user has explicitly asked for those http codes.

Parameters:
shouldFailOnHttpError - A boolean expressing whether or not a page-load should be marked as failed if at least one http error code has been received

failOnHttpErrors

void failOnHttpErrors(int[] failOnHttpErrorCodes)
Configure whether the WebDriver should throw an Exception in case a page-load receives at least one of the http error codes specified in the input array.

Default is an empty array "[]": if a page-load returns at least one HTTP Valid Response, it is still considered valid. (same as calling failOnHttpError(boolean) with "false")

failOnHttpError(boolean) and failOnHttpErrors(int[]) are mutually exclusive: if a script calls both only the last call will be have its effect.

Note: This is applied to a page-load only if it's executed inside a "step".

Note: Given an input array (e.g. [ 404, 501 ], if either a Blacklist and/or a WhiteList has been defined the status codes of the requests affected by those lists will NOT be taken into account as the user has explicitly asked for those http codes.

Parameters:
failOnHttpErrorCodes - Am array of integers listing the http error codes that the user wants to cause a page-load to be marked as failed if at least one if those http error code has been received. Http error codes NOT passed in in this array will be ignored.

disableHttpChecks

void disableHttpChecks()
Do no checking at all for valid HTTP responses when a page-load is triggered.

When calling this function be sure to do your own checking to ensure that the page actually loaded. For example, check/wait for an element or text to show up on the page with a timeout.


scrollTo

void scrollTo(int left,
              int top)
Scrolls the browser by left and top amount. This amount scrolled is absolute, not relative.

Parameters:
left - the left amount to scroll
top - the top amount to scroll

Copyright © 2020 Neustar, Inc. All Rights Reserved.