Typing on Soft Keyboards
The TypeText
command can be used to have Eggplant Functional (EPF) enter text on any SUT. In most situations, this is the simplest and most straightforward approach. However, on mobile devices, it does not exactly imitate the user experience. In some situations it is desirable to type against the soft keyboard on a mobile device instead of injecting the TypeText events directly into the system. This is especially useful if your application has a custom soft keyboard that you want to test, or if you just want to imitate the user experience more closely.
Typing on the Soft Keyboard of a Mobile Device
This scenario is also a great example of where modularization of scripts is helpful. The code to type against a soft keyboard can be broken out into a handler and stored in a separate script or handler library. Once this has been created, that code and all of the associated images can be stored in a helper suite and reused over and over again. Every time you need to interact with a soft keyboard on a mobile device, simply call the related code, and pass the string you want to type to that handler.
Example of this type of handler:
to SoftType WordToType //The variable "WordToType" catches a string to type that is passed to it from a calling script.
put the remoteworkinterval into RWI //The remoteworkinterval can be adjusted for this handler depending on the soft keyboard being used and how it animates.
set the remoteworkinterval to .5 //The setting used in this example works with both iOS 6 and Android 4.1.1.
repeat with each character letter of WordToType //Iterates through the characters of the passed string and uses each letter as a reference to an image that is named the same as that letter. For example, an image of the letter "a" would be called "a".
Click letter //Clicks each letter in the sequence passed to the variable "WordToType”.
end repeat
set the remoteworkinterval to RWI //This re-sets the remoteworkinterval to its original value.
end SoftType
Typing on a Soft Keyboard using Swipe Type
Typing on a soft keyboard can be done with the method shown above, where each letter key is tapped individually, imitating the way a user types on the keyboard. However, swipe type can also be imitated with Eggplant Functional.
While this is a less common method of typing on keyboards, it can be important to test swipe type capability either to more closely mimic the user experience, or to verify swipe type capability on a custom soft keyboard. Additionally, this method used to script swipe-typing can be modified and applied to other kinds of shape drawing, such as when using a pattern to unlock a device.
Example of this type of handler:
Note: This script was written to work against the native Android swipe type keyboard on a Samsung device. Timing settings in this script may need adjustment depending on the device and keyboard being tested.
to SwipeType WordToType //The variable "WordToType" catches a string to type that is passed to it from a calling script.
put the remoteworkinterval into RWI//The remoteworkinterval can be adjusted for this handler depending on the soft keyboard being used and how it animates.
set the remoteworkinterval to .01 //The setting used in this example works with Android 4.1.1.
Repeat with each character letter of WordToType //Iterates through the characters of the passed string and uses each letter as a reference to an image that is named the same as that letter. For example, an image of the letter "a" would be called "a".
insert imagelocation(letter) nested after CharLoc //Find the location of each letter in the sequence and store it, so that the key can be referenced by location during an extended drag and drop.
end repeat
Repeat with each item Letter of CharLoc //This now iterates through the CharLoc list, which is a list of the saved locations of each letter image.
drag Letter //Clicks each letter in the sequence based on the location sequence in the CharLoc variable. This will drag through each location without dropping until the end of the sequence, creating the swipe type action for that word.
end repeat
drop
set the remoteworkinterval to RWI //Restore the remoteworkinterval to its original value.
end swipeType