Dowemo
0 0 0 0

Some of the recent projects need to test android devices using the robot framework, which is the most appropriate library for testing mobile devices.

In the process of building environment, the chosen pc host environment is ubuntu, and you can choose windows or mac.

However, the installation of this small article is tested with ubutu 14.04 for example.


This article is divided into the following parts

robot framework

Two..

A pair of three. Robot framework and appium --.

Four. Build environment I tallation steps.

test the android calculator

test build number

A preliminary study of the keyword"open application"

Eight. your red cover header -- lets uiautomatorviewer parse the properties of the control under the current window of the anroid.


Let's walk through the side and look at each part of the key.

( just a look ), if you want to go deeper, you'll see the body body force line and improve in actual projects.

robot framework

The robot framework is just a common framework, and his name reflects his features ( robot representative automation, framework representative framework ).

The robot framework is rich in various libraries, and some libraries are included with the robot framework ( such as string xml, etc. ), and more to third party development, and then open source for community everyone development and use. Appium is a library of third party development, and there are many people who have no name in the community that have been assigned to appium.

The robot framework has many advantages, and we introduce.

1."keyword"driver, which is the most important feature of the robot framework. In addition, programming is supported, which greatly reduces the difficulty of programming; Grammar is simple and flexible, it's easy to understand;

2. The newly created keyword ( keyword ) can use the previously defined keyword ( keyword ).

3. Allow the user to create a definition"keyword".

4. The program is portability, and the host environment ( pc, such as ubuntu, windows, mac ) is independent of the test program ( such as testing chrome, ie, firefox ).

5. Rich library support, with the robot framework, also has a third party class library ( library ), also customized.

The ( tag ) classification function, which can be used to select a test case for some notes ( tag ), or after the results are generated, to see the results of

7. Generate the report and log ( log ) in html format for reading.

Robot framwork follows the apache license 2.0 protocol, all of which can be developed and used freely under this agreement, and more details can be referenced by://robotframework. Org/.


Two..

Appium is a class library ( library ) developed by third parties, primarily for testing mobile devices, currently supporting Android/iOS/Firefox/Windows phone.

The strengths of appium are as follows.

1. The source code for the test isn't required.

2. Don't modify or recompile the test program.

Appium supports multiple languages, such as python, java, robot framework, etc.

For more information, you can refer to the website http://appium. Io/.


A pair of three. Robot framework and appium --.

The figure below is the block diagram of the robot framework + appium



The following figure shows the timing diagram of the mobile device using the robot framework + appium


Appium: run on node. Js, respo & ible for handling the UI and appium interaction of mobile devices. Appium server runs on the background to respond to the commands sent by the appium library.

Appium-python: using json wire protocol to interact with the library and server, the appiium python client requests server to initialize a session with the python client. After the request succeeds, the server is assigned to a session id with the appium, and all subsequent interactions are done through this session.

Pybot: read the test file script, control the library; then generate the resulting results and log.


setup steps ( ubuntu )

1. Environment installation.

1. 1 I talling node. Js.

Download, unzip, and add the bin directory to the environment variable from the following links

https://nodejs. org/download/release/v5.6.0./.

Verify that node. Js is configured successfully and run the following command to verify that the version number is correct.

$ node -v
 v5.6.0
$ npm -v
 3.6.0
1.2 I & talling appium and appium
$ npm install -g appium
$ npm install -g appium-doctor

1. 3 I talling the android sdk and configuring environment variables as follows.

export ANDROID_HOME=your_android_sdk_path/sdk
PATH=$PATH:$ANDROID_HOME/tools/:$ANDROID_HOME/platform-tools
1.4 I & talling the appium python client
$ pip install Appium-Python-Client
1.5 check the environment configuration correctly and start the




2. Install robot framwork.

2. 1 I talling pip tools.

$ sudo apt install python-pip
2.2 I & talling the robot framework
$ sudo pip install robotframework
2.3 I talling 2.8
$ sudo apt install python-wxgtk2.8
Note that if the ubuntu version is relatively high, g1 may have upgraded to a higher version, using the following command to demote the installation
$ echo"deb http://archive.ubuntu.com/ubuntu wily main universe" | sudo tee/etc/apt/sources.list.d/wily-copies.list
$ sudo apt update
$ sudo apt install python-wxgtk2.8
$ sudo rm/etc/apt/sources.list.d/wily-copies.list
$ sudo apt update
2.4 installation robotframework-ride
$ sudo pip install robotframework-ride
2.5 installation Robotframework-appiumlibrary
$ sudo pip install robotframework-appiumlibrary
2.6 starting ride
$ ride.py


test the android calculator

The main purpose of this test is to test the addition and subtraction of two numbers, and then verify the results.

Here's the code written on the ride editor.

*** Settings ***
Suite Setup Open Calculator App
Suite Teardown Close Application
Library AppiumLibrary
*** Variables ***
# Appium Configurations
# Element locators for various objects on calculator app
${DISPLAYED_RESULT} xpath=//*[contains(@resource-id, 'id/result')]
# Test Data
${td_Digit1} 5
${td_Digit2} 2
${td_Expected_Addition_Result} 7
${td_Expected_Subtraction_Result} 3
*** Test Cases ***
Test Case 1: Addition
 [Documentation] Tests addition of two numbers on calculator app
 [Tags] android addition
 Log"STEP 1: Enter two digits to add."
 Enter Digits And Operator ${td_Digit1} ${td_Digit2} +
 Log"STEP 2: View result"
 View Result
 Log"STEP 3: Verify result"
 Verify Result ${td_Expected_Addition_Result}
Test Case 2: Subtraction
 [Documentation] Tests subtraction of two numbers on calculator app
 [Tags] android subtraction
 Log"STEP 1: Enter two digits to subtract."
 Enter Digits And Operator ${td_Digit1} ${td_Digit2} −
 Log"STEP 2: View result"
 View Result
 Log"STEP 3: Verify result"
 Verify Result ${td_Expected_Subtraction_Result}
*** Keywords ***
Open Calculator App
 [Documentation] Opens the calculator app with a new appium session.
 Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.1
. . . deviceName=falcon_ironman_mvS appPackage=com.android.calculator2 appActivity=.Calculator
Enter Digits And Operator
 [Arguments] ${digit1} ${digit2} ${operator}
 [Documentation] Taks two single digit numbers and the operator as input and presses the correspinding buttons on the calcualtor keypad.
 Click Element xpath=//*[contains(@text, '${digit1}')]
 Click Element xpath=//*[contains(@text, '${operator}')]
 Click Element xpath=//*[contains(@text, '${digit2}')]
View Result
 [Documentation] Presses the equal to button to view the result of the operation
 Click Element xpath=//*[contains(@text, '=')]
Verify Result
 [Arguments] ${expected_result}
 [Documentation] Verifies the result displayed with the expected answer.
 ${displayed_result} = Get Element Attribute ${DISPLAYED_RESULT} text
 Should Be Equal ${displayed_result} ${expected_result}

The following is the report and log generated by the test





test build number

The main purpose of this test is to test if build number in settings is correct, read build number and validate results.

The code is as follows,

*** Settings ***
Suite Setup Open Settings App
Suite Teardown Close Application
Library AppiumLibrary
*** Variables ***
${EXPECTED_BUILD_NUMBER} 91-12-04-MN-MV-111516
*** Test Cases ***
Test Case 1: Build Number Test
 [Documentation] Compare the"Build Number" is expected or not.
 Verify Build Number ${EXPECTED_BUILD_NUMBER}
*** Keywords ***
Open Settings App
 [Documentation] Opens the Settings app with a new appium session.
 Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.1
. . . deviceName=falcon_ironman_mvS appPackage=com.android.settings appActivity=.Settings
Verify Build Number
 [Arguments] ${expected_build_number}
 [Documentation] Verify the"Build Number" Correct or not
 Log Step 1: Swipe to the end of page
 Swipe 0 1000 0 500 300
 Swipe 0 1000 0 500 300
 Swipe 0 1000 0 500 300
 Swipe 0 1000 0 500 300
 Sleep 2s
 Log Step 2: Click the"About Phone" Label
 Click Element xpath=//*[contains(@text, 'About phone')]
 Sleep 2s
 Log Step 3: Swipe to the end of page
 Swipe 0 1000 0 500 300
 Swipe 0 1000 0 500 300
 Sleep 2s
 Log Step 4: Verify the Page if contains the right build number
 Page Should Contain Text ${expected_build_number} INFO

Test report and log are as follows




A preliminary study of the keyword"open application"

It's a few fields I'm starting to launch android, and the following english is simpler, and it's no longer translated into chinese.

Note that when I compile with ride, the fields of"open application"can't use variables, and when you're doing problems, you can try to do so without variables.



Eight. your red cover header -- lets uiautomatorviewer parse the properties of the control under the current window of the anroid.

Finally, we'll look at the magic uiautomatorviewer, which can be used to grab all the properties of the current page 's all controls.

With this application 's tool, we don't have the source code for the app, and you can also visualize the properties of each control in app.

In ubuntu, this tool is located in Sdk/tools/bin/uiautomatorviewer

It's divided into 3 parts,

1. The left side of the screen capture.

A list of all the controls above the right. Note that you can only capture controls on the current page.

3. The properties of the selected control, such as the common resource id, text, and so on.




Other co ideratio,

1. Adb display". insufficientpermissions for device"

Change /etc/udev/Rules. D./51-android. Rules, add the following statements in the file, and notice that idvendor is different from each device, and you can use the command lsusb.

SUBSYSTEM=="usb", ATTR{idVendor}=="05C6", MODE="0666", GROUP="plugdev"
2. The installation appium needs access to google sites, and you can refer to the load. Cn and modify the hosts file to implement the.


Reference resources

RobotFramework official web site- ://robotframework.orgAppiumofficicalweb site- ://appium. Io./. RobotFramework For Mobile Test Automation- ://www. Xoriant. com/blog/product-engineering/robot-framework-mobile-test-automation. Html.



Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs