Interface SeleniumTask


public interface SeleniumTask
This is a simple interface for an async selenium task. This interface is used to describe a set of actions to be performed asynchronously.

Example #1
The following code example creates an async script to get and print the page title to the STDIO, and then asks to be unregistered from further executions.


 Observer o = new AsyncTask(driver, new SeleniumTask() {
             <code>@Override</code>
             public boolean doTask() {
                 String pageTitle = driver.getCurrentUrl();
                 System.out.println("Time is " + LocalTime.now() + ", page url is " + pageTitle);
                 return false;
             }
         });
         driver.async().setDispatchInterval(2, ChronoUnit.SECONDS);
         driver.async().register(o);
         


Example #2
The following code waits for a popup to appear on the screen, and after it appears, click on dismiss and then asks to be unregistered from further executions. It uses the default dispatch interval, which is 1 second:


 Observer o = new AsyncTask(driver, new SeleniumTask() {
             <code>@Override</code>
             public boolean doTask() {
                 boolean result = false;

                 <code>List<WebElement></code> elements = driver.findElements(By.id("popup-button-dismiss-locator"));
                 if (elements.isEmpty())
                     return false;

                 try{
                     elements.get(0).click();
                     result = true;
                 }
                 catch(Throwable t)
                     result = false;

                 return result;
             }
         });
         driver.async().register(o);
         


Since:
2.0.3
Author:
Nir Gallner @ www.VeriSoft.co
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Asynchronous task to be performed, repeatedly until the tasks asks to be unregistered
  • Method Details

    • doTask

      boolean doTask()
      Asynchronous task to be performed, repeatedly until the tasks asks to be unregistered
      Returns:

      true, meaning the task is completed and wishes to be unregistered and not to be invoked again
      false, meaning the task needs to run again, and should be invoked next time as well