程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python appium simulates human operation to obtain app data

編輯:Python

Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right

List of articles

  • Preface
  • One 、appium What is it? ?
  • Two 、 Use steps
    • 1. Prepare the environment
    • 2. Realize the idea
    • 3. Project implementation
  • summary


Preface

use appium Simulate human sliding operation to obtain app Data to avoid frequent replacement ip The situation of , The disadvantage is that the speed of obtaining data will be relatively slow , This article introduces appium Get data content .


One 、appium What is it? ?

1,appium It's an open source mobile automation testing framework ;
2,appium You can test native 、 Mixed 、 And mobile web project ;
3,appium You can test ios,android application ( Yes, of course , also firefox os);
4,appium It's cross platform , Can be used in ios,windows as well as linux On the desktop ;

Two 、 Use steps

1. Prepare the environment

Appium Server GUI 1.22.3-4
Appium Inspector 2022.5.4
Night God Simulator The Android system used is 5.1.1
Android system needs to open developer mode , Turn on USB debugging

2. Realize the idea

  1. get data

adopt Appium To operate the simulator to obtain data , use Appium Inspector, We can get app Of data in class,id,xpath etc. , To locate the data in the element .

  1. Element of judgement

In this way, you can only get the content displayed on the screen , Therefore, the code to judge the existence of elements through methods is as follows
The code is as follows :

from selenium.common.exceptions import NoSuchElementException
def isElementPresent(by, value):
try:
driver.find_element(by=by, value=value)
except NoSuchElementException:
# Print exception information
# print(NoSuchElementException)
# Something goes wrong , The element was not found in the description page , return False
return False
else:
# No abnormality , Indicates that the element was found in the page , return True
return True
  1. Simulate sliding
    Simulate human sliding app Internal content , Press and hold to get the new data generated below , Want to slide without sliding inertia , It can only be released by pressing and sliding ,
    The code is as follows :
from appium.webdriver.common.touch_action import TouchAction
# Get the mouse position
def get_size():
x = driver.get_window_size()['width']
y = driver.get_window_size()['height']
return(x,y)
l = get_size()
# Take half of the width
x1 = int(l[0]*0.5)
# Slide from below
y1 = int(l[1]*0.8)
# Stop at a position above
y2 = int(l[1]*0.25)
action.long_press(x=x1 ,y=y1,duration=2000).move_to(x=x1,y=y2).release().perform()

3. Project implementation


summary

That's what we're going to talk about today , This article briefly introduces appium Use , For learning and communication only


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved