Appium + python Automation - start app

Appium + python Automation - start app

 

Environmental already be in place, the next step is the need to start APP, how to start the app do? First of all to get the package name, and then get launcherActivity. The two key things get a lot of ways, not one by one to say, small partners can recount. Xiao Bian here to recommend major sdk comes with a utility aapt. 

 

    aapt i.e. the Android Asset Packaging Tool, in the SDK build-tools directory. The tool can view the apk package name and launcherActivity, of course, more features, are interested can view the data.

 

First, download aapt

    1. Double-click inside android-sdk SDK-manager, download buidl-tools

 

 

 

 

 

    2. Check the build-tools, pick a version, here I chose the version 24

 

 

 

 

 

    3. After the download is complete, in D: \ androidsdk \ androidsdk-windows \ found under build-tools \ 24.0.0 directory aapt.exe, this will set the path environment variable, add the path to the next

 

 

 

 

 

    4. Open cmd. Aapt enter the following interface, indicating that the environment is OK

 

 

 

Second, get the package name apk

    1. APK will be ready to test the D drive into a directory, such as D: \ test

 

2. Open cmd, enter the command aapt dump badging D: \ test \ xxx.apk (full name of APK, such as mobile phones Taobao .apk)

 

If APK name with spaces, put the path in double quotes.

 

aapt d badging "d:\apktest\QQ 7.1.8.apk"

 

 

 

The result is

 

package: name='com.tencent.mobileqq' versionCode='718' versionName='7.1.8' platformBuildVersionName=''

 

install-location:'auto'

 

sdkVersion:'15'

 

targetSdkVersion:'9'

 

   3. phone Taobao .apk, for example, the following chart

 

 

 

    4. Here you can see the apk's package name: com.taobao.taobao

 

NOTE: The old drivers may apk directly on the desktop, drag enter the command cmd box

 

Third, access to launcherActivity

    1. Then the operation step, cmd intermediate drag the screen to find launcherActivity

 

    2. Here you can see, Taobao launcherActivity value com.taobao.tao.welcome.Welcome

 

 

 

QQ的launchable

 

launchable-activity: name='com.tencent.mobileqq.activity.SplashActivity' label='QQ'

 

Fourth, write a script

    1platformName: Here is the android apk

 

    2.deviceName: phone device name, view through adb devices

 

    3.platformVersion: the version number of the android system. Asked Questions in the version corresponding to the API. Note To be consistent with the APPNIUM in compatibility version number.

 

    4.appPackage: apk package name

 

    5.appActivity:apk的launcherActivity

 

 

 

   

 

6.3.5 Operating appium

    1. Start appium, upper right corner triangle button, to square, is activated state.

 

 

 

    2. Make sure the phone connected to the computer

 

 

 

    3. pycharm run the script, then the following two prompts will pop up installation of software on the phone, after installation, two icons on the desktop and more. Then congratulations started successfully!

 

 

 

 

 

4. The app will then see Taobao has started it, there is a small wooden excited ~ ~

 

 

 

Before running Notes

First empty appium in the log contents, click the trash, restart about her, click on the upper right corner of the box, let it become restart triangle, then changed the box.

 

 

2 / inspection equipment connection

 

 

3. Check the settings in the device in the system version number.

4. Run the following two commands in DOS, allowed to re-use every time

C:\.....>adb uninstall io.appium.unlock

 

Return Success

 

C:\.....>adb uninstall io.appium.settings

 

Return Success

 

 

 

5. Check the version number of the same

Android SDK version number in the acquisition, APPNIUM in Android version number is set, and the script platform version, the need remains consistent.

 

 

 

   

 

 

 

6. Run appium wrong, please see appium skills and problem highlights the document.

Sixth, the following final code

# coding=utf-8

 

from appium import webdriver

 

desired_caps = {

 

                'platformName': 'Android',

 

                'deviceName': '30d4e606',

 

                'platformVersion': '5.0',

 

                # Apk package name

 

                'appPackage': 'com.taobao.taobao',

 

                # apk的launcherActivity

 

                'appActivity': 'com.taobao.tao.welcome.Welcome'

 

                }

 

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

 

This is how to address it?

 

 

 

 

 

This is a major aapt learn to use tools, and then start a process app after app start, the next step is to locate elements of a positioning element android sdk which comes with a uiautomatorviewer, appium and there was a Inspector, next in detail introduction.

 

 

 

QQ startup script as follows

 

# coding=utf-8

 

from appium import webdriver

 

desired_caps = {

 

'platformName': 'Android',

 

'deviceName': 'C4Y5T16C08002942',

 

'platformVersion': '6.0',

 

# Apk package name

 

'appPackage': 'com.tencent.mobileqq',

 

# apk的launcherActivity

 

'appActivity': 'com.tencent.mobileqq.activity.SplashActivity'

 

}

 

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

 

Eight Questions

1.Adb deviecs Q & A

By DOS commands, execute connect the phone to view the situation, appear as abnormal

 

C:\Users\xu.lei>adb devices

 

List of devices attached

 

adb server version (31) doesn't match this client (39); killing...

 

error: could not install * smartsocket * listener: can not bind to 127.0.0.1:5037: each socket address (protocol / network address / port) is normally permitted. (10048)

 

 

 

This application has requested the Runtime to terminate it in an unusual way.

 

Please contact the application's support team for more information.

 

could not read ok from ADB Server

 

* failed to start daemon *

 

error: cannot connect to daemon

 

Cause Analysis:

This is the socket port is occupied, I'm here because 360 ​​Mobile Assistant occupied this port, so others will not be able to use.

 

Way to see whom the port occupied by two

 

The first method is to use a DOS command,

 

netstat -nao

 

The second method is the windows system comes "Explorer" can view the port usage, the specific operation is as follows:

 

(1) shown below red arrow, right-click the taskbar space, in the pop-up menu, select "Task Manager":

 

 

 

(2) as shown circled in red in the "Task Manager", switch to the "Performance" tab, then click "Open Windows Explorer":

 

 

 

(3) In the "Explorer", click on "Network", check process to be queried in the "process network activity" in this case the bottom of the column "Listening Port" will be shown this process (software) the use of the port:

 

 

 

 

 

 

 

Solution:

Uninstall the Mobile Assistant 360 on it,

 

First, open the 360 ​​security guards, click on the bottom right corner of the "more +" - "click on" My Tools "-" bottom left, click "Edit" - "click" Mobile Assistant "top X number

 

 

 

This time may not be deleted, then the process will delete mobile assistant, inside 360Mobile shown. . These, then you can delete the

 

Adb commands and then execute on it

 

 

 

2. adb view the device when the display List of devices attached

phenomenon

C:\>adb devices

 

View device when the display List of devices attached

 

 

 

Solution:

Device Manager to see if the driver installation was successful.

Check these drivers, there is no phone or have a drive Android logo with yellow exclamation mark, if these two cases arise the problem would be positioned on the phone the driver.

. Solution: 1 pea pod can be installed, it will automatically install the phone driver 2. You can find yourself a cell phone online drive, install it - this is the most direct way, Huawei phone is installed the drive, only to show up. Open Developers 3. debug mode on the phone, you can open the Settings - About - version number, click 5 times, you can turn on developer mode.

 

2、

 

5. Run the command line

 

adb kill-server

 

adb devices

 

You can view the device

 

C:\Users\XXXi>adb devices

 

List of devices attached

 

C4Y5T16C08002942 device

 

 

 

 

 

3.

Android 7.0 phone system can not execute the script problem appium

Appium Appium version 1.4.16, Android device firmware 7.x, when executing the script, being given the use of language: python given as follows:

WebDriverException: Message: A new session could not be created. (Original error: Could not extract PIDs from ps output. PIDS: [], Procs: ["bad pid 'uiautomator'"])

 

This is because of uiatumator1.0 appium version 1.4.16 does not support the use of lead? If you do not upgrade appium version, is there a solution?

 

Solution

uiautomator1.0 should not support 7.0-liter version will not switch to uiautomator2.0 it, or change the method by using the following script.

 

Concrete solutions to solve the Android 7.0 phone system implementation appium can not script, change the question as follows:

 

Appium find adb.js files in the installation directory, windows version of the directory as follows: Appium \ node_modules \ appium \ appium-adb node_modules \ \ lib

2, open adb.js, manually modify the contents of this file, I have successfully tested this method.

adb.js 中1035 行this.shell("ps '" + name + "'", function (err, stdout) {

Corresponding to the instruction is executed ps 'uiautomator', Android7 format does not support this command, the execution result is bad pid 'uiautomator'

Currently Appium this is not treated, it is necessary to modify the implementation of this directive

Upcoming

this.shell("ps '" + name + "'", function (err, stdout) {

if (err) return cb(err);

Replaced

this.shell_grep("ps", name, function (err, stdout) {

 

if (err) {

 

logger.debug("No matching processes found");

return cb(null, []);

 

}

 

And increase shell_grep function used above:

ADB.prototype.shell_grep = function (cmd, grep, cb) {

if (cmd.indexOf('"') === -1) {

cmd = '"' + cmd + '"';

}

was execCmd = 'shell' + cmd + '| grip + grip;

this.exec(execCmd, cb);

 

};

 

 

 

 

 

 

 

There are online solution is modified as follows: The following I have not tested.

ADB.prototype.getPIDsByName = function (name, cb) {

logger.debug("Getting all processes with '" + name + "'");

this.shell("ps '" + name + "'", function (err, stdout) {

if (err) return cb(err);

stdout = stdout.trim();

var procs = [];

var outlines = stdout.split("\n");

outlines.shift (); // add this line of code where

3, restart appium

   

 

 

 

4. Andrews correspondence between the version number of the API

Android Platform Version correspondence table with API Level

 

   

 

Platform Version

 

API Level

 

VERSION_CODE

 

Notes

 

Android 6.0

 

23

 

M

 

Platform Highlights

 

Android 5.1

 

22

 

LOLLIPOP_MR1

 

Platform Highlights

 

Android 5.0

 

21

 

LOLLIPOP

 

Android 4.4W

 

20

 

KITKAT_WATCH

 

KitKat for Wearables Only

 

Android 4.4

 

19

 

KITKAT

 

Platform Highlights

 

Android 4.3

 

18

 

JELLY_BEAN_MR2

 

Platform Highlights

 

Android 4.2, 4.2.2

 

17

 

JELLY_BEAN_MR1

 

Platform Highlights

 

Android 4.1, 4.1.1

 

16

 

JELLY_BEAN

 

Platform Highlights

 

Android 4.0.3, 4.0.4

 

15

 

ICE_CREAM_SANDWICH_MR1

 

Platform Highlights

 

Android 4.0, 4.0.1, 4.0.2

 

14

 

ICE_CREAM_SANDWICH

 

Android 3.2

 

13

 

HONEYCOMB_MR2

 

  

 

Android 3.1.x

 

12

 

HONEYCOMB_MR1

 

Platform Highlights

 

Android 3.0.x

 

11

 

HONEYCOMB

 

Platform Highlights

 

Android 2.3.4

Android 2.3.3

 

10

 

GINGERBREAD_MR1

 

Platform Highlights

 

Android 2.3.2 Android 2.3.1

Android 2.3

 

9

 

GINGERBREAD

 

Android 2.2.x

 

8

 

FROYO

 

Platform Highlights

 

Android 2.1.x

 

7

 

ECLAIR_MR1

 

Platform Highlights

 

Android 2.0.1

 

6

 

ECLAIR_0_1

 

Android 2.0

 

5

 

ECLAIR

 

Android 1.6

 

4

 

DONUT

 

Platform Highlights

 

Android 1.5

 

3

 

CUPCAKE

 

Platform Highlights

 

Android 1.1

 

2

 

BASE_1_1

 

  

 

Android 1.0

 

1

 

BASE

 

  

 

 

 

 

 

We in the project development process, often need to look at API Level and sdk version, some of the ways to make the call, and sometimes also need to know the corresponding publisher's time, we can understand to a minimum compatible version when released.

 

Posted here later for easy viewing:

 

https://developer.android.com/guide/topics/manifest/uses-sdk-element.html

Android version history

Platform Version

 

API Level

 

VERSION_CODE

 

Issue Date

 

Android 1.0

 

1

 

Clockwork Robot

 

2008-09

 

Android 1.1

 

2

 

Petit Four fancy cupcakes

 

2009-02

 

Android 1.5

 

3

 

Cupcake cupcakes

 

2009-04

 

Android 1.6

 

4

 

Donut donuts

 

2009-09

 

Android 2.0

 

5

 

Éclair muffins

 

2009-10

 

Android 2.0.1

 

6

 

Éclair muffins

 

2009-10

 

Android 2.1

 

7

 

Éclair muffins

 

2009-10

 

Android 2.2-2.2.3

 

8

 

Froyo frozen yogurt

 

2010-05

 

Android 2.3-2.3.2

 

9

 

Gingerbread Gingerbread

 

2010-12

 

Android 2.3.3-2.3.7

 

10

 

Gingerbread Gingerbread

 

2010-12

 

Android 3.0

 

11

 

Honeycomb Honeycomb

 

2011-02

 

Android 3.1

 

12

 

Honeycomb Honeycomb

 

2011-02

 

Android 3.2

 

13

 

Honeycomb Honeycomb

 

2011-02

 

Android 4.0-4.0.2

 

14

 

Ice Cream Sandwich ice cream sandwiches

 

2011-10

 

Android 4.0.3-4.0.4

 

15

 

Ice Cream Sandwich ice cream sandwiches

 

2011-10

 

Android 4.1

 

16

 

Jelly Bean Jelly Bean

 

2012-07

 

Android 4.2

 

17

 

Jelly Bean Jelly Bean

 

2012-07

 

Android 4.3

 

18

 

Jelly Bean Jelly Bean

 

2012-07

 

Android 4.4

 

19

 

KitKat chocolate bar Kit Kat

 

2013-10

 

Android 4.4W

 

20

 

KitKat with wearable extensions Kit Kat chocolate

 

2013-10

 

Android 5.0-5.0.2

 

21

 

Lollipop Lollipop

 

2014-11

 

Android 5.1

 

22

 

Lollipop Lollipop

 

2014-11

 

Android 6.0-6.1

 

23

 

Marshmallow Marshmallow

 

2015-10

 

Android 7.0

 

24

 

Nougat nougat

 

2016-08

 

Android technology stack

 

Guess you like

Origin www.cnblogs.com/ceshi168/p/11964144.html