appium-封装屏幕滑动方法

from common.logger import Logger
logger=Logger().get_logger()
class BasePage:
    def __init__(self,driver):
        self.driver=driver
    def get_window_size(self):
        logger.info("正在准备获取当前屏幕的大小")
        try:
            size=self.driver.get_window_size()
            width=size["width"]
            height=size["height"]
            logger.info("获取当前屏幕大小成功:宽:{}   高:{}".format(width,height))
            return width,height
        except:
            logger.exception("获取当前屏幕大小失败")
    def swipe_down(self,t=500,n=1):
        logger.info("正在准备向下滑动屏幕")
        try:
            size=self.get_window_size()
            x=size[0]*0.5
            y=size[1]*0.2
            x1=size[0]*0.5
            y1=size[1]*0.8
            for i in range(n):
                self.driver.swipe(x,y,x1,y1,t)
                logger.info("屏幕第{}次向下滑动成功".format(i+1))
        except:
            logger.exception("屏幕向下滑动失败")
    def swipe_up(self,t=500,n=1):
        logger.info("正在准备向上滑动屏幕")
        try:
            size=self.get_window_size()
            x=size[0]*0.5
            y=size[1]*0.8
            x1=size[0]*0.5
            y1=size[1]*0.2
            for i in range(n):
                self.driver.swipe(x,y,x1,y1,t)
                logger.info("屏幕第{}次向上滑动成功".format(i+1))
        except:
            logger.exception("屏幕向上滑动失败")
    def swipe_right(self,t=500,n=1):
        logger.info("正在准备向右滑动屏幕")
        try:
            size = self.get_window_size()
            x = size[0] * 0.2
            y = size[1] * 0.5
            x1 = size[0] * 0.8
            y1 = size[1] * 0.5
            for i in range(n):
                self.driver.swipe(x, y, x1, y1, t)
                logger.info("屏幕第{}次向右滑动成功".format(i + 1))
        except:
            logger.exception("屏幕向右滑动失败")

    def swipe_left(self, t=500, n=1):
        logger.info("正在准备向左滑动屏幕")
        try:
            size = self.get_window_size()
            x = size[0] * 0.8
            y = size[1] * 0.5
            x1 = size[0] * 0.2
            y1 = size[1] * 0.5
            for i in range(n):
                self.driver.swipe(x, y, x1, y1, t)
                logger.info("屏幕第{}次向左滑动成功".format(i + 1))
        except:
            logger.exception("屏幕向左滑动失败")

原文地址:https://www.cnblogs.com/Be-your-own-hero/p/11345279.html

时间: 2024-08-30 15:06:41

appium-封装屏幕滑动方法的相关文章

python appium 封装获取toast方法

获取toast text封装,传入toast 部分文本,返回全部文本 def get_toast_text(self,text): try: toast_loc = (By.XPATH, "//*[contains(@text,'"+text+"')]") logger.info(toast_loc) ele = WebDriverWait(self.driver, 10, 0.1).until(EC.presence_of_element_located(toas

滑动操作以及滑动方法封装

滑动解析 滑动主要分为:水平滑动.垂直滑动.任意方向滑动 滑动轨迹 在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. 从一个点滑动到另一个点,duration是滑动时间 :Args: - st

python+appium app自动化的方法实例运用

# -*- coding: utf-8 -*-import osimport sysimport timeimport unittest from appium import webdriver# from selenium import webdriverfrom HTMLTestRunner import HTMLTestRunnerfrom appium.webdriver.common.touch_action import TouchAction global driver class

Android4.4-Launcher源码分析系列之WorkSpace及屏幕滑动

一.WorkSpace是什么 前面已经介绍了一个WorkSpace包含了多个CellLayout,再回忆下之前画过的图 WorkSpace是一个ViewGroup,它的布局如下 <com.android.launcher3.Workspace android:id="@+id/workspace" android:layout_width="match_parent" android:layout_height="match_parent"

iOS中tableview中headerview总保持在屏幕上方和随着屏幕滑动一起移动至消失

1 : tableview中headerview总保持在屏幕上方 :  在代理方法中创建view,并添加到headerview上 l例子: - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if ([self.title isEqualToString:@"幕后"]) { NSArray *array = @[@"全部",@"

封装SQL访问方法

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using System.Data.SqlClient; namespace _04封装SQL访问方法 { public class SqlHelper { //读取连接字符串 private static readonly string str = Configurat

PHP封装Excel表方法使用流程

今天总结了一下Excel表的封装和导出使用,原理 经常使用与一些日常报表, 数据报表, 实现方法比较简单, 一次封装, 简单的方法调用,简单~ 废话不多说,直接入正题, 先说下重要的参数要记住的东西 impUser() 导入方法 exportExcel($xlsName,$xlsCell,$xlsData);导出方法 PHPExcel.php  PHP主文件, 放置各种class结合核心文件 <Fatal error:Class 'ZipArchive' not found in.....  这

jQuery滑动方法

jQuery 滑动方法 通过 jQuery,您可以在元素上创建滑动效果. jQuery 拥有以下滑动方法: slideDown() slideUp() slideToggle() jQuery slideDown() 方法 jQuery slideDown() 方法用于向下滑动元素. 语法: $(selector).slideDown(speed,callback); 可选的 speed 参数规定效果的时长.它可以取以下值:"slow"."fast" 或毫秒. 可选

如何调用封装的私有方法或私有对象

一般情况下,一个对象的私有方法或私有属性,是无法调用的,但在开发过程中,突然发现我们要钻牛角了,你不准调,但我一定要调 例前段时间,在项目中客户提出了能对报表的列进行顺序调整,并且同一台机子上不同的账号登录修改后的保存能独立,这个好解决应用微软的CacheManager能很好的解决,牛角来了....如果我要在项目中删除所有关于某个报表的记忆缓存咋办,可是只有一个公共的Remove(String Key)方法:问题是Key我用的是用户账号,我不想循环系统所有的账号去删除..... 在调试过程我发现