Last updated: Sep 22, 2019 17:35
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, then just call the findElement(By.linkText) command.
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.
- Create a String with the proprietary command.
- Create a hashMap and put all the needed parameters in it.
- Call executeScript function and pass the command String and hashMap as parameters.
Some short notes about using visual analysis advanced parameters:
- Use the screen.top, screen.height, and screen.width parameters to limit the area of the screen searched and speed up the visual analysis operation.
- Use the index parameter if the string that you are searching for appears multiple times on the screen and you need to identify (for example) the second or third appearance.
- Some visual analysis commands, for example mobile:test:select, throw an exception if the text is not found.
- The timeout parameter can be used to wait for the text to appear on the screen. Similar to Selenium wait functions.