Cross-Mobile Scripting
An Eggplant Functional (EPF) script (not including the images) can typically be used across all mobile devices with little or no modification. This is because the script simply describes the user workflow, and app creators try hard to keep this workflow consistent across all mobile devices.
Reference images can also often be re-used across different mobile devices and operating system versions, but sometimes references will have to be different for different devices. This document describes the situations in which different reference images will be required, and presents best practices for efficient cross-mobile scripting.
When Are Different Images Required?
There are three situations that typically lead to different reference images being required between two devices:
- Devices in different device families render images differently (e.g., with different smoothing effects), so different reference images are required.
- Devices in the same device family, but with different screen resolutions, will render images that include text differently. So if a reference image includes text, and two devices have different screen resolutions, then they will need to use different reference images.
- Major version changes of the operating system (OS) will often change the look-and-feel of native applications, like Settings or Messaging. So reference images related to native applications might have to be different for devices using different major OS versions.
Despite the above three situations, a huge amount of image re-use is possible, making cross-mobile scripting with Eggplant Functional very productive. For example, images for your application can typically be re-used across all OS versions within a single device family.
Device Families
Device families are sets of mobile devices that use the same basic OS and UI layer, and so render images the same way. They can re-use the same reference images unless the devices have different resolutions and the reference image includes text, or the reference image is for a native application and the devices have different major OS versions.
To make it easy to test against multiple devices and device operating systems, Eggplant Functional supports connections to Sauce Labs. Sauce Labs provides a virtual device compatibility lab so that you don't have to own the devices yourself. Click Here for more information.
The table below shows the most popular device families, further partitions these by resolution, and gives advice for re-using images.
| Family | Resolution | Devices | OS Version | Best Practice |
|---|---|---|---|---|
| Samsung Galaxy | 1080*1920 | S4, S5 | 4.1, 4.2, 4.4, 5.0, 5.1 | The same images can be used with tolerances raised slightly. Use images captured on the S5 for consistency. |
| 720*1280 | S3 | 4.1, 4.2, 4.4, 5.0, 5.1 | A single image can be captured for this device to work across all OS versions. | |
| 1440*2560 | Nexus 6 | 4.1, 4.2, 4.4, 5.0, 5.1 | The same images can be used, along with using scaling, as long as the images do not include text, where OCR can be used. Images should be captured on the Nexus 6 and scaled down for the Nexus 5. | |
| 1080*1920 | Nexus 5 | 4.1, 4.2, 4.4, 5.0, 5.1 | same as above | |
| iPad | 1536*2048 | Mini, 3, Air, Air 2 | 8.1, 8.2, 8.3, 8.4 | The same images can be used with tolerances raised slightly. Use images captured on the Air 2 for consistency. |
| iPhone | 1080*1920 | 6 Plus | 8.1, 8.2, 8.3, 8.4 | The same images can be used, along with using scaling, as long as the images do not include text, where OCR can be used. Images should be captured on the iPhone 6 Plus and scaled down for the iPhone 6. |
| 1334*750 | 6 | 8.1, 8.2, 8.3, 8.4 | same as above | |
| 640*1136 | 5S, 5, 4S | 8.1, 8.2, 8.3, 8.4 | The same images can be used with tolerances raised slightly. Use images captured on the 5S for consistency. |
Note again the huge amount of image re-use which is possible. Not only can you use the same images for all devices within a device family, you can also use the same images across all OS versions. This means that with just 8 reference images as shown above, you can cover 61 different combinations of device and OS version.
Best Practices for Cross-Platform Scripting
The remainder of this document presents best practices for efficient cross-mobile scripting:
- Use text searches (OCR) and search rectangles.
- Store images for each stream of devices in a separate suite.
- Separate out core code from OS-specific code.
- Run an environment setup script at the start of every test.
- Create a naming convention for devices.
- Create tests using the core code in a separate suite.
Use Text Searches (OCR) and Search Rectangles
One of the first things to do is start by using OCR. The OCR engine inside Eggplant Functional is independent of resolution, text size and color, so if any of these three things is different across your devices then you wont even need to re-capture any images.
To maximize the reliability and increase the speed of execution of the OCR, set the search rectangle around the area where you know the text is going to be. Below is some example code that sets the search rectangle in proportion to the resolution of the device, so the same code can be used among multiple mobile devices. Item 1 is referring to the x-coordinate and item 2 is referring to the y-coordinate.
set ScreenSize to the screensize of connectioninfo()
set the searchrectangle to (0,0.5* item 2 of ScreenSize,item 1 of screensize,item 2 of screensize)
If you know you are going to want to set lots of different rectangles throughout your test, use the code below, which allows you to easily set the rectangle to any area of the screen that you choose:
params TLx,TLy,BRx,BRy -- Values are between 0 and 1 and represent the proportion you want to go in the x and y direction for the top left and bottom right coordinates.
set the searchrectangle to (TLx * ConnectionInfo().ScreenSize.x,TLy * ConnectionInfo().ScreenSize.y, BRx * ConnectionInfo().ScreenSize.x, BRy * ConnectionInfo().ScreenSize.y)
You can also write it as a function so that you can use the search rectangle as part of other functions. Example code for the function below:
//Script called ScreenPart
params TLx,TLy,BRx,BRy -- Values are between 0 and 1 and represent the proportion you want to go in the x and y direction for the top left and bottom right coordinates.
return (TLx * ConnectionInfo().ScreenSize.x,TLy * ConnectionInfo().ScreenSize.y, BRx * ConnectionInfo().ScreenSize.x, BRy * ConnectionInfo().ScreenSize.y)
Example code to call the function is below:
Set the searchrectangle to ScreenPart( 0,0,1,1)
Moveto (Text:"Clock",searchrectangle:ScreenPart(0,0,0.5,0.5)) // This will only search the top left quarter of the screen
With the different screen sizes and resolutions of mobile, each mobile device has its own DPI and as such, you should set the DPI to the DPI of the device you are connected to to help increase the reliability of the OCR. You can do this by having a property list that sets the DPI depending on what device you are connecting to. Some example code is below:
//This code would be run at the very start of your test to set the DPI
set DeviceDPI to (iPhone_6S_91:"401","Galaxy_S6_51":"577")
set the readTextSettings to (DPI:DeviceDPI.(DeviceName))
The readTextSettings is a property list of the default settings used for the ReadText() and ReadTable() functions. After the above code sets the DPI, write your OCR code as usual. The following example uses the ReadText() function.
put (Readtext(0,0,1,1))