Visual analysis with RemoteWebDriver

When testing a mobile website or application, it is always recommended to use visual analysis for user checkpoints. The reason for that is because only visual analysis acts as a real user, "seeing" real life bugs like corrupted or cut text, something which you might not find when using only native or web driver.

So how do we use the visual driver? The simple answer is very easy: We need to switch context, by using the switchToContext function, which is part of the Perfecto template when creating a new Eclipse mobile project, then just call the findElement(By.linkText) command:

Copy
switchToContext(driver, "VISUAL");
remoteWebDriver.findElement(By.linkText("needle"));

But what if the text we're looking for can be found only by scrolling the screen? or the default threshold of 60% is not enough for our need? 
Then we need to use the executeScript function which Selenium provides, sending the relevant parameters to the proprietary Perfecto function. The example below shows how to call this function.

  1. Create a string with the proprietary command. 
  2. Create a hashMap and put all the needed parameters in it.
  3. Call executeScript function and pass the command string and hashMap as parameters. 
Copy
String findCommand = "mobile:text:find"; // The proprietary function call
Map params = new HashMap<>();
params.put("content", "needle");    // The text we're looking for
params.put("dpi", "300");           // Optional DPI parameter
params.put("scrolling", "scroll");  // Add the scroll and search
params.put("next", "SWIPE_UP");     // Next is mandatory if using scroll and search
                                    // Can also use customized swipe like:
                                    // "SWIPE=(50%,80%),(50%,60%);WAIT=1000"params.put("maxscroll", "3");       // Not mandatory, default is 5
params.put("threshold", "100");     // Adding threshold
remoteWebdriver.executeScript(findCommand, params); // Calling the script
// Clarification: The "dpi" and "threshold" params 
// are not related to the "scroll and search" param,
// and can be called or not called regardless of the "scroll and search"