Appium + Robotframework automated testing for iOS apps-6: solutions to gesture passwords, appium tutorial

Source: Internet
Author: User

Appium + Robotframework automated testing for iOS apps-6: solutions to gesture passwords, appium tutorial

The gesture password will be shipped in many applications. The gesture password requires at least four points to be connected, but the AppiumLibrary does not provide the corresponding keywords. I tried to solve this problem two times in a row using the Swipe keyword, why do I need to use it twice? Because the Swipe parameter is only the start point and the end point, if the start point and the end point of the gesture password are directly given, the middle point is ignored and the Swipe keyword can be used twice in a row to occasionally succeed in Android, however, I have never succeeded in iOS. In order to completely solve this problem, I carefully read the Appium documentation and finally found that, please refer to the official website of Appium as follows:


I learned that the problem of the gesture password can be solved.

Robotframework is based on Python, so only Python clients of Appium are installed.

Because AppiumLibrary does not provide the gesture password keyword, you can write a Library by yourself. However, this attempt fails because many context parameters are required during execution of Appium. However, it may be possible to solve the problem of how the self-written Library interacts with AppiumLibrary, but it may be troublesome.

Change the concept and save the country.

Since AppiumLibrary has been installed and is open-source, will it be possible to modify its source code directly?

Therefore, go to the AppiumLibrary installation folder and install it to/Library/Python/2.7/site-packages/AppiumLibrary by default. (for Android, I used Windows 7 for testing, the default installation path is C: \ Python27 \ Lib \ site-packages \ AppiumLibrary \ keywords), and _ touch is found in the keywords directory. py file.

Add a method gesture to the class _ TouchKeywords of this file. The specific code is as follows:

def gesture(self, platform):        """ Gesture the element """        driver = self._current_application()               action = TouchAction(driver)                  if platform == "iOS":            action.press(x=100, y=500).wait(ms=500).move_to(x=600, y=0). \         wait(ms=500).move_to(x=0, y=500).wait(ms=500).release()          else:            action.press(x=50, y=100).wait(ms=500).move_to(x=150, y=0). \         wait(ms=500).move_to(x=0, y=100).wait(ms=500).release()          action.perform()

The parameter platform of this method is used to pass in the platform. The value is iOS or Android. Here there are two key points:

1. the coordinates in the press method are absolute coordinates, while those in the move_to method are relative coordinates. Specifically, the coordinates in the first move_to method are relative to those in the press method, the coordinates in the second move_to method are relative to those in the first move_to method.

2. wait is required: At first, I didn't use wait, and the result was that it was moving too fast. From the first point to the last point, I skipped the middle point. After adding wait, it would be normal. Here ms is represented as millisecond, ms = 500 is to wait 500 milliseconds.

It is easy to use: Gesture iOS in iOS; Gesture Android in Android

Some may ask why the coordinate point is written to death and is not passed as a parameter?

In fact, at the beginning, I used coordinates as parameters. Three sets of coordinates were used to represent the start point, the center point, and the end point coordinate respectively. However, errors are always reported during execution and the cause is still not found, later I thought that the gesture password was not changed. I simply wrote it as hard-coded. If the coordinates changed, I would just change the file directly. Python is an interpreted language, it will automatically compile when used, saving the trouble of compiling and making it very convenient.

Both iOS and Android have passed the test.

Two questions in this article:

1. How to Write a Library to provide a gesture Password

2. How to pass coordinates as parameters

Please share your solutions with us.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.