appium滑动
在app应用日常使用过程中,会经常用到在屏幕滑动操作。如刷朋友圈上下滑操作、浏览图片左右滑动操作等。在自动化脚本该如何实现这些操作呢?
在Appium中模拟用户滑动操作需要使用swipe方法,该方法定义如下:
def swipe(self, start_x, start_y, end_x, end_y, duration=None):
"""Swipe from one point to another point, for an optional duration.
:Args:
- start_x - x-coordinate at which to start
- start_y - y-coordinate at which to start
- end_x - x-coordinate at which to stop
- end_y - y-coordinate at which to stop
- duration - (optional) time to take the swipe, in ms.
:Usage:
driver.swipe(100, 100, 100, 400)
滑动解析
滑动主要分为:
- 水平滑动
- 垂直滑动
- 任意方向滑动
滑动轨迹图如下:

实践应用
测试场景
- 安装启动考研帮,手动向水平左滑动首页引导页面。
- 点击“立即体验”进入登录页面。
代码实现
from time import sleep
from find_element.capability import driver
#获取屏幕尺寸
def get_size():
x=driver.get_window_size()['width']
y=driver.get_window_size()['height']
return x,y
#显示屏幕尺寸(width,height)
l=get_size()
print(l)
#向左滑动
def swipeLeft():
l=get_size()
x1=int(l[0]*0.9)
y1=int(l[1]*0.5)
x2=int(l[0]*0.1)
driver.swipe(x1,y1,x2,y1,1000)
#向左滑动2次
for i in range(2):
swipeLeft()
sleep(0.5)
driver.find_element_by_id('com.tal.kaoyan:id/activity_splash_guidfinish').click()
注意:运行前记得将capablity里面的check_skipBtn()先注释掉,否则直接跳过了无法滑动引导页面。
课后作业
把垂直上下滑动以及向右滑动的也封装并实践。
- def swipeUp()
- def swipeDown()
- def swipeRight()
参考答案
def swipeUp():
l = get_size()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.95)
y2 = int(l[1] * 0.35)
driver.swipe(x1, y1, x1, y2, 1000)
def swipeDown():
l=get_size()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.35)
y2 = int(l[1] * 0.85)
driver.swipe(x1, y1, x1, y2, 1000)
def swipeRight():
l=get_size()
y1 = int(l[1] * 0.5)
x1 = int(l[0] * 0.25)
x2 = int(l[0] * 0.95)
driver.swipe(x1, y1, x2, y1, 1000)
appium滑动的更多相关文章
- appium滑动操作(向上、向下、向左、向右)
appium滑动操作(向上滑动.向下滑动.向左滑动.向右滑动) 测试app:今日头条apk 测试设备:夜游神模拟器 代码如下: 先用x.y获取当前的width和height def getSize() ...
- Python Appium 滑动、点击等操作
Python Appium 滑动.点击等操作 1.手机滑动-swipe # FileName : Tmall_App.py # Author : Adil # DateTime : 2018/3/25 ...
- Appium 滑动界面swipe用法
Appium 滑动API:Swipe(int start x,int start y,int end x,int y,duration) 解释:int start x-开始滑动的x坐标, int st ...
- appium 滑动
前些日子,配置好了appium测试环境,至于环境怎么搭建,参考:http://www.cnblogs.com/tobecrazy/p/4562199.html 知乎Android客户端登陆:htt ...
- Appium滑动函数:Swipe()
Appium处理滑动方法是swipe 滑动API:Swipe(int start x,int start y,int end x,int y,duration) 解释: int start x-开始滑 ...
- Appium 滑动踩坑记
前言 对于不同java-client版本,很多的API已经产生大的变化,所以一些API大家会发现已经失效或者使用方式发生了变化,滑动就是其中一项,这篇文章对滑动在不同的java-client版本以及不 ...
- appium 滑动封装
#获得机器屏幕大小x,y def getSize(): x = dr.get_window_size()['width'] y = dr.get_window_size()['heig ...
- Appium for iOS setup
windows下appium设置 之前研究了一段时间的appium for native app 相应的总结如下: ...
- appium for hybrid app 处理webview
之前研究了一段时间的appium for native app 相应的总结如下: appium测试环境搭建 :ht ...
随机推荐
- linux c编程訪问数据库
源代码例如以下: #include <stdio.h> #include <stdlib.h> #include <mysql/mysql.h> int main( ...
- Apache server配置
Apacheserver在我们生活中非经常常使用 今天给大家将一下mac 下apache server的配置 这对程序来说是必备技能之中的一个,假设我们在公司开发都是用的公司的server 将自己的代 ...
- 【Nginx】模块化设计
高度模块化的设计是Nginx的架构基础.全部模块都是以ngx_module_t结构体表示,该结构体内部定义了7个回调方法.它们负责模块的初始化和退出.commands成员是一个包括有ngx_comma ...
- 查找存在某字符的文件列表,不包括svn文件
find . ! -wholename '*.svn*' -print | xargs grep "img" | awk -F ':.' '{print $1}' | uniq
- 试试pypy
pypy是一个python的解释器和JIT编译器.能够在不改动不论什么代码的情况下大幅提升python代码的性能. 使用超级简单,在官网下载编译好的二进制包进行安装,然后然后执行代码的时候指定这个解释 ...
- 二分图染色模板(P1330 封锁阳光大学)
二分图染色模板(P1330 封锁阳光大学) 题目描述 曹是一只爱刷街的老曹,暑假期间,他每天都欢快地在阳光大学的校园里刷街.河蟹看到欢快的曹,感到不爽.河蟹决定封锁阳光大学,不让曹刷街. 阳光大学的校 ...
- operator[] 重载
#include <iostream>#include <vector>#include <string> class Assoc { struct Pair ...
- Python 38 注册和修改密码
一:注册系统服务 1.添加环境变量:桌面点击我的电脑------>右键属性------>双击高级系统设置------>点击环境变量------>找到在系统变量中的Path后双击 ...
- 自学Python四 爬虫基础知识储备
首先,推荐两个关于python爬虫不错的博客:Python爬虫入门教程专栏 和 Python爬虫学习系列教程 .写的都非常不错,我学习到了很多东西!在此,我就我看到的学到的进行总结一下! 爬虫就是 ...
- SQLServer2008 关于数值字段列的累计
create table #temp20110610( id int identity(1,1), date varchar(8), qty float) insert int ...