Appium—python_ 安卓手机划屏幕操作

  开始的时候 不知道 python_unittest框架的命名规则,导致方法进不去,后来 改变方法名 能获取

# conding=utf-8
from appium import webdriver
import time
import unittest
class Login(unittest.TestCase):
  desired_caps = {
               'platformName':'Android',
               'deviceName':'FA56GB105163',
               'platformVersion':'5.0.2',
               'appPackage':'com.zhonghong.www.qianjinsuo',
               'appActivity':'com.zhonghong.www.qianjinsuo.main.activity.qjsMian.main.LoadingActivity',
               'unicodeKeyboard':True,#使用unicodeKeyboard的编码方式来发送字符串 ,可以实现输入中文
               'resetKeyboard':True #隐藏虚拟键盘,防止遮挡元素
                 }
  driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
#休眠15s等待程序启动
  time.sleep(5)
  print ("aaaaaaa")
#获取页面长宽
  def test_a_getSize(self):
      x=self.driver.get_window_size()['width']
      y=self.driver.get_window_size()['height']
      return(x,y)
#左向滑动,根据比例实现
  def test_b_swipeLeft(self):
        l=self.test_a_getSize()
        x1=int(l[0]*0.75)
        y1=int(l[1]*0.5)
        x2=int(l[0]*0.25)
        self.driver.swipe(x1,y1,x2,y1)
        #再滑动一次
        self.driver.swipe(x1,y1,x2,y1)
  
  def test_c_longin(self):
        self.driver.find_element_by_id("com.zhonghong.www.qianjinsuo:id/button_ok").click()
        time.sleep(2)
  """
#向右滑动
    def test_swipeRight(self,t):
        l=self.getSize()
        x1=int(l[0]*0.25)
        y1=int(l[1]*0.5)
        x2=int(l[0]*0.75)
        self.driver.swipe(x1,y1,x2,y1,t)

        

#向上滑动
    def test_swipeUp(self,t):
        l=self.getSize()
        x1=int(l[0]*0.5)
        y1=int(l[1]*0.75)
        y2=int(l[1]*0.25)

        self.driver.swipe(x1,y1,x1,y2,t)


#向下滑动

    def test_swipeDown(self,t):
        l=self.getSize()
        x1=int(l[0]*0.5)
        y1=int(l[1]*0.25)
        y2=int(l[1]*0.75)
        

 

posted @ 2016-10-11 14:20  明镜止水丨  阅读(2813)  评论(0编辑  收藏  举报