Gesture password in many applications will be shipped, gesture password are required to connect at least 4 points, but Appiumlibrary did not provide the corresponding keywords, I try to use the Swipe keyword two times to solve the problem, why use two times? Because the swipe parameter is only the starting point and the end point, if the start point and focus of the gesture password are given directly, the middle point will be ignored, and the consecutive use of two times swipe keyword can be successful occasionally in Android, but not once in iOS, in order to completely solve the problem, I carefully read the Appium documents, finally all found, please see from the official website of Appium as follows:
I know that the problem of gesture password can be solved.
Robotframework is based on Python, so only the Appium Python client is installed.
Since Appiumlibrary does not provide a gesture password keyword, write a library yourself. However, the attempt failed, mainly because the Appium execution requires a lot of context parameters, and how to write the library and appiumlibrary interaction is a problem, perhaps can be solved, but it may be more troublesome.
Change the concept, simply the curve to the National Salvation Bar.
Since the installation of appiumlibrary, and it is open source, directly to modify its source code is not fixed it?
So, go to the Appiumlibrary installed folder, the default will be installed to/library/python/2.7/site-packages/appiumlibrary (Android I use Windows 7 for testing, The default installation path is: C:\Python27\Lib\site-packages\AppiumLibrary\keywords), and then find the _touch.py file in the keywords directory, which is it.
Add a method gesture to the class _touchkeywords for this file, with the following code:
[Python]View Plaincopyprint?
- def gesture (self, platform):
- "" " Gesture The element" ""
- Driver = self._current_application ()
- Action = touchaction (Driver)
- if platform = = "IOS":
- Action.press (x=, y=). Wait (ms=).move_to (x=, y=0).
- Wait (ms=). Move_to (x=0, y=). Wait (ms=). Release ()
- Else:
- Action.press (x=, y=). Wait (ms=).move_to (x=, y=0).
- Wait (ms=). Move_to (x=0, y=). Wait (ms=). Release ()
- Action.perform ()
The parameter platform of this method is used for the incoming platform, the value is iOS or Android, here are two key knowledge points:
The coordinates in the 1.press method are absolute coordinates, and the coordinates in the Move_to method are relative coordinates, specifically the coordinates in the first move_to relative to the coordinates in the press method, and the coordinate in the second Move_to method relative to the coordinates in the first move_to method.
2.wait is a must: I did not use wait at the beginning, the result is that the effect is paddling too fast, directly from the first point to the last store, skimming the middle point, plus wait after the normal. Here MS is expressed as milliseconds, and ms=500 is waiting for 500 milliseconds.
It's easy to use: Gesture iOS in iOS, Android for: Gesture Android
Maybe some people will ask why the coordinate point is dead, not as a parameter to pass in it?
In fact, I started with the coordinates as parameters, a total of three sets of coordinates representing the starting point, the middle point and the endpoint coordinates, but the execution is always error, but also can not find the reason, and then thought that the gesture password is unchanged, do not need to change, simply write hard code, if the coordinate changes, then directly change the file can be Anyway, Python is interpreted as the language, the use of the time will be automatically compiled, but also save the trouble of compiling, is also very convenient.
Tested on both iOS and Android.
The two issues in this article are:
1. How to write a library to provide a gesture password
2. How to pass the coordinates in as parameters
Also ask your friends to share your solutions and welcome the interactive discussion.
Appium+robotframework automated testing for iOS apps-6: Solutions for gesture ciphers