0 Basic App Automation Test Tutorial (i)

Source: Internet
Author: User
Tags http request sleep install node python script appium
App Automation Framework selection

The current comparison of the Fire Automation tool features: Appium (for android&ios; support multi-lingual, no application source code) Uiautomator (for Android; Java-only language; no application source required) Robotium (for Android; Java only; no application source) Calabash (for Android&ios;ruby languages (other languages are unfriendly); you need to apply the source code on IOS)

Through the above comparison, actually already can see that we should choose which tool, here may wish to repeat the choice appium reason and its other advantages: At present domestic discussion about it in full swing, convenient to consult the relevant data support many multi-languages, wayward choice development language is a happy thing Do not need to apply the source code, give the test development work a certain degree of freedom can be tested across the application, very good and strong support for iOS and Android platform, in the face of dual-platform app, mother no longer have to worry about me with two sets of test framework, reduce cognitive cost support Android native and hybrid applications, Come on, Let the developers how to toss I can resist the appium introduction

First, an introduction to the official style to introduce Appium

Appium is an open-source, cross-platform testing framework that can be used to test native and hybrid mobile applications. Appium supports iOS, Android, and Firefoxos platforms. Appium uses Webdriver's JSON wire protocol to drive the UIAutomation Library of the Apple system and the Uiautomator framework of the Android system. Appium support for iOS systems thanks to Dan Cuellar's research on iOS automation. Appium also integrates the selendroid to support the old Android version. Appium supports all languages supported by selenium Webdriver, such as Java, Object-c, JavaScript, PHP, Python, Ruby, C #, Clojure, or the Perl language, and can be used selenium The Webdriver API. Appium supports any kind of test framework. If you only use Apple's uiautomation, we can only use JavaScript to write test cases, and only use instruction to run test cases. Similarly, if you only use Google's uiautomation, we can only write test cases in Java. Appium enables True cross-platform automation testing.

And I'm going to give you a brief introduction to the principle of appium:
Appium The reason why cattle broke, because it is a high-level test framework. The ability to cross-platform (Android&ios), support for multiple development languages, and the reason for it to have these features is due to its Webdriver API. We can simply understand it as a test script and the middle tier of the mobile system, it encapsulates the underlying automation framework and exposes a unified API, the client, regardless of what language script can be sent to the server through the HTTP request to complete the automated operation, as shown in the following figure:

So how to use the artifact to carry out our automated testing work. To talk about the general process.
First, we need to write the corresponding test script according to the test case, verify the feasibility of the script and add the script library. The next step is to execute our script library and output the test results, which can be used to automate the testing of Jenkins to achieve continuous integration, combining the building of code, validation, and output of test results together. Specific programmes need to be further studied.

Appium Practice

Said so many background knowledge, perhaps you crossing already impatient, then hurriedly come to combat a, through a "small chestnut" to teach you step to use Appium. Installing the Appium environment

工欲善其事 its prerequisite, installing the appium operation and development environment is the first step. Here I take an example of the Android App test environment under window platform.
List of files to install: Install Android environment, there is not much to say, it should be emphasized that the Android SDK is stored in a path without spaces, such as: C:\Program-Files\Android\android-sdk is OK, and C:\Program (space) files\android\android-sdk is sorry. If you are determined to add a space in the path, then I can only respect you as a man, because later you may encounter Appium run script failed to happen. Install node. js, here to download the installation package installation, do not forget to add the corresponding environment variables in the system. Install Appium, you can also go to the official website to download the latest installation package installation. Install the development language environment, here I use Pyhthon, so need to install its corresponding environment. The environment here includes the Python development environment and the corresponding dependent library (appium_python_client), which can be quickly installed using the following command line:
Pip Install Appium-python-client
Similar to other languages, you also need to install the development language environment and the corresponding dependent library, here do not repeat, please search for the corresponding method. Writing Scripts

Here I wrote a python script to run on the real machine I am following the magic of the app, verify that the user login log out function is normal use, and the abnormal result screenshot saved, so that we can follow the location of the problem.

#-*-Coding:utf-8-*-from appium import webdriver from time import Sleep def login (): Try:desired_caps = {} desired_caps[' platformname '] = ' Android ' desired_caps[' platformversion '] = ' 6.0.1 ' desired_caps [' devicename '] = ' Galaxy S6 ' desired_caps[' apppackage '] = ' dji.go.v4 ' desired_caps[' appactivity '] = ' DJI.P Ilot.main.activity.DJILauncherActivity ' Driver = webdriver. Remote (' Http://localhost:4723/wd/hub ', desired_caps) driver.find_element_by_name (' I '). Click () driver.find _element_by_name (' login '). Click () driver.find_element_by_name (' Please enter your registered email '). Send_keys (' account ') Driver.find_ele

        ment_by_id (' Dji.go.v4:id/cw1 '). Send_keys (' password ') driver.find_element_by_name (' login '). Click () sleep (3) Driver.find_element_by_name (' Settings '). Click () driver.find_element_by_name (' Exit DJI Account '). Click () Driver.fin D_element_by_name (' OK '). Click () sleep (1) driver.quit () excePT Exception as E:print (e) driver.get_screenshot_as_file ("Failed.jpg") return False return Tr UE if __name__== ' __main__ ': if (True==login ()): Print ("The execution of this use case succeeds") Else:print ("The use case failed to execute")

The logic of this code is: launch the app and let the app follow the path we specify to log in and out, if not as required to enter the next interface, the exception message will be reported, at this time we save the exception screen screenshot to the specified folder, the decision case execution failed and end the script, and vice versa, the use case execution succeeds. Execute Script

Before executing the script, we need to connect to the real machine and open the Appium, click on the "Android Robot" icon in the upper right corner, adjust the platformversion to the Android version of our real computer, device Namet fill in the script should be the name. If you are an Android emulator user, please adjust the platformversion to the Android version of our simulator.

When you are finished, click the triangle arrow in the upper-right corner to run Appium. Then, we just run the script we just wrote, silently waiting for the test result output. The image below is the login screen for this magical app, which automatically clicks the login button and enters the account/password after the script launches the app, and then logs out of the app.

View Results

For example, here I deliberately lost the login password, so that the bar to verify the normal login log out of the use case execution failed, the program will feedback "The failure of the use of this case" and save the exception screenshot to our designated path.

To summarize, this article gives you a brief introduction to why you chose Appium and how to install it using appium through a small example. However, through a blog post may still not be able to apply Appium automated testing work, follow-up will bring you more detailed use of the method, please look forward to.

I am Gavin, a willing to share the test practitioners, welcome to communicate with me, if you want to reprint this article please indicate the source.

Author: Gavin Eat Watermelon
Links: http://www.jianshu.com/p/cc44b756a458
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

Related Article

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.