Windows Build Appium + Android+python Automated test environment

Source: Internet
Author: User
Tags appium

Objective

It was not intended to write such an article, but the practice came to discover that there were two problems in various tutorials on the web. First, the article some keep up with the times, the current Android development and testing technology updates are relatively fast, the content has expired. Second, the details are not too complete, patchwork can also be completed, but for the novice is more painful. Well, I'll try to summarize the pits I've stepped on.

remark: The Android Automation test environment and the development environment are not exactly the same, the test environment can be very simple and rough, many tools can not be installed, such as JDK,SDK tools, test scripts with C#,python can be done, but the development environment is generally required JDK and a lot of compiler tools.

Practice Platform

Windows Ten Pro 64bit + Python 3.5.3

Installing the JAVA Environment

If it's just an automated test, install the JRE and install the JDK if you need to develop or debug the APK.

    1. JRE = JVM + Java SE Standard Class library, equivalent to the most basic operating environment of Java program.

    2. JDK = JRE + Development Toolset, including Javac compilation tools, and more.

JRE only more than 50 mb,jdk is close to 200MB, please go to the Java official website to download the latest version of the installation, select 64-bit.

Install Android STUDIO/SDK

The previous tutorials will let you install the Android SDK, but now it's hard to find the download link to the Android SDK from Google or Bing, as there are currently two recommended practices on the website:

    1. Install Android Studio (including Android SDK)--Recommended

    2. Install only the android SDK command-line tool

The new version of the Android SDK is not the same as it used to be, we used to have an SDK Manager.exe tool for updating and downloading versions of the API, and an AVD Manager.exe tool to emulate various types of Android devices. The latest SDK tools remove the basic UI interface, leaving only the command-line tool, which can be used to refer to the official documentation:

    • Https://developer.android.com ...

So much less than one thing, I recommend you to install Android Studio directly, so not only easy, and in case you want to write an app to play, is also extremely convenient.

: https://developer.android.com ...

The installation process is very simple, double-click on the next, you can also specify the SDK installation target path (not recommended modification). Once installed, launch Android Studio directly and you will first be prompted to download some of the necessary tools (you need a good network and a ladder) on the Internet.

Once you're ready, you can open the SDK Manager from the Start screen.

or create a new project to open the SDK Manager from the engineering interface.

Once the SDK Manager is open, the method used is at a glance. This is a tool that lets you update the API and various development tools.

If it's just for automated testing you just have to remember the SDK installation directory and you don't need to install any extra tools. The installation directory for the SDK needs to be used when configuring environment variables.

If your network is not unblocked, you need to set up the agent first. You can then install the SDK version and developer tools you want.

Installing the Android Emulator

If you already have Android Studio installed and the emulator is already available, you can find the AVD Manager button from the engineering interface and add and launch an emulator in three steps.

Whenever you install a new version of the emulator is required FQ or proxy, the first time you start Android Studio it has given you the next latest version of Android, my current emulator version of Android is 7.1.1.

If all goes well, then when you start the simulator, you can see a virtual Android device, the manual test basic conditions have been achieved, automated testing is within reach.

To say a few words, in addition to using the Android SDK comes with the simulator, we have two options, one is to use the real machine, speed and experience will be better. Another option is to choose other simulator products, such as [Genymotion] (), because it is commercial software, so there are many restrictions on individual users (free), however, its maturity is much higher than the Android SDK comes with the simulator. Because the concrete implementation of these two scenarios involves more content, it is not discussed in this article.

Installing Appium

Appium is an open source automated testing framework for automated testing of ios,android and mobile platforms such as Windows apps. The introduction of the official website is that it implements a set of webdriver protocols that apply to the mobile side, so the use of appium depends on the selenium, and the main difference between Web Automation testing is driver.

For example, if we need to run selenium's automated tests with Google Chrome, we need a chromedriver first. If you need to run on IE, then you need a iedriver. So now you need to run selenium on the mobile side like Android, and you need a appium to do it, and it plays the role of driver. Appium implemented a set of standard Webdriver, as long as Appium service up, your code only need to interact with Appium, Appium will tell the device what to do. The devices mentioned here can be iOS or Android, or even Windows Phone and Firefox OS.

Appium Official website: http://appium.io/

Installation method One: Install with Nodejs

First to [Nodejs official website] () download and install the latest nodejs,windows under the idiot installation. After installation you can configure Nodejs installation source, in the country generally use Taobao mirror, the speed is good.

Create a new. npmrc file in the personal directory, write:

registry=https://registry.npm.taobao.org/

Then use the NPM command to install Appium

npm install -g appium

It is recommended to install Appium-doctor by running the appium-doctor command to quickly check for appium environmental issues.

npm install -g appium-doctor

If the installation is successful, you can appium start appium server by command.

Close the command line or press Ctrl-c to stop Appium Server.

Installation Method II: Using the Appium installation package

Many tutorials on the web-guided Appium installation package is generally in Baidu network disk or bitbucket, in fact, both are not the latest. The latest version of the installation package should be downloaded from the official website, Appium currently hosted on GitHub, the correct should be:

    • Https://github.com/appium/app ...

This is the latest version of the Appium desktop installation after the boot.

Functionally and the old version are not much different, but the log and UI display is clearer, and once the error occurs, it's easier to find the problem.

Note that you can not install Appium Desktop Edition, but the command line version should still need to install, because the automated test run is generally through the command to start and close Appium, the desktop version does not provide command line functionality, just for debugging convenience.

About Appium, here's a very good document: Http://appium.io/slate/cn/master

Installing Appium-client

This article only discusses the Python implementation of the Appium test, so you only need to allow the following commands:

pip install Appium-Python-Client

If you need to use a different programming language, the following table is for reference:

Language/Framework GitHub repository and Installation Guide
Ruby Https://github.com/appium/ruby_lib
Python Https://github.com/appium/python-client
Java Https://github.com/appium/java-client
JavaScript (node. js) Https://github.com/admc/wd
Objective C Https://github.com/appium/selenium-objective-c
Php Https://github.com/appium/php-client
C # (. NET) Https://github.com/appium/appium-dotnet-driver
Robotframework Https://github.com/jollychang/robotframework-appiumlibrary
Necessary environment variable settings

If you already have Appium-doctor installed, you can just run the Appium-doctor command to know which environment variables you need to set up, such as:

Don't panic, but you just need to set the following environment variables:

Environment Variables value
Android_home Installation location of Android SDK
Java_home Installation location of JDK or JRE
Join PATH %android_home%tools
Join PATH %android_home%platform-tools
Join PATH %java_home%bin
Join PATH %android_home%build-tools?? Version?? (optional)

The last environment variable is to make it easier to use the AAPT tool, and after the environment variable is configured you can run Appium-doctor again to check. No accident, you should be able to pass the check.

Complete the first automated test

Finally came to move real thing time, a lot of people gave up at the beginning, more people started after the give up, go to this step really is not easy.

There are some things you should know before you start writing code:

    1. Simulator or test machine must be ready state, each start simulator is time-consuming, so it is recommended that the simulator does not shut down, the code to start the simulator is a way, but the time cost is a bit high.

    2. If you are debugging the code phase, it is recommended to keep the Appium desktop version running for a long time, and then automatically start and close Appium through code when the remote runs.

    3. Appium will find the device according to your test code, if you have more than one virtual machine or connected to multiple physical machines, explicitly specify the device name or version number in your code.

The first automated testing requirement is simple: launch the built-in dialer software and search for "Hello Toby". The code is as follows:

From AppiumImport Webdriverdesired_caps = {}desired_caps[' platformname '] = ' Android ' desired_caps[' platformversion '] = ' 7.1.1 ' desired_caps['devicename '] = ' Android Emulator ' desired_caps[' apppackage ' = ' Com.android.dialer ' desired_caps[' appactivity '] = ' dialtactsactivity ' driver = webdriver. Remote (' Http://localhost:4723/wd/hub ', desired_caps) driver.find_element_by_id (' Com.android.dialer:id/ Search_box_collapsed '). Click () Search_box = driver.find_element_by_id (' Com.android.dialer:id/search_view ') Search_box.click () search_box.send_keys (' Hello Toby ')          

Operating effect:

Congratulations, you have started to enter the mobile end of the automated testing door!

Windows Build Appium + Android+python Automated test environment

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.