appium===登陆应用的案例

import time
import os 
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from swipe import swipeLeft #调用向左滑动的方法
import unittest



PATH=lambda p:os.path.abspath(os.path.join(os.path.dirname(__file__),p))

class tChatAndroidTests(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        desired_caps={}
        desired_caps['platformName']='Android'
        desired_caps['platformVersion']='5.1'
        desired_caps['deviceName']='ZTEC880U'
        desired_caps['app']=PATH('F:\Tchat_kaifa_V3.0.12_456_TS49169.apk')     
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)#初始化    
        desired_caps['unicodeKeyboard']=True,#使用unicodeKeyboard的编码方式来发送字符串
        desired_caps['resetKeyboard']=True#将键盘给隐藏起来
            
    def test_login1(self):
        time.sleep(2)
        swipeLeft(self.driver)
        swipeLeft(self.driver)
        swipeLeft(self.driver)
        time.sleep(2)
        self.driver.get_screenshot_as_file('C:\\Users\\yangbo\\Desktop\\Tchat\\screenshot\\login1.png')     #截图
        self.driver.find_element_by_id("com.sinosun.tchats:id/welcome_btnstart").click()

        
    def test_login2(self):    
        time.sleep(2)
        self.driver.find_element_by_id("com.sinosun.tchats:id/loginview_inputphone_textfield").click()
        '''
        account
        '''
        self.driver.find_element_by_id("com.sinosun.tchats:id/loginview_inputphone_textfield").send_keys("15760926259")
        time.sleep(2)
        '''
        password
        '''
        self.driver.find_element_by_id("com.sinosun.tchats:id/loginview_inputpassword_textfield").send_keys("a123456")
        time.sleep(2)
        '''
        login
        '''
        self.driver.find_element_by_id("com.sinosun.tchats:id/loginview_loginuser_button").click()
        time.sleep(5)
        self.driver.get_screenshot_as_file('C:\\Users\\yangbo\\Desktop\\Tchat\\screenshot\\login2.png')     #截图
        #self.driver.find_element_by_id("com.sinosun.tchats:id/myText").click()
        '''
        code
        '''
       # self.driver.find_element_by_id("com.sinosun.tchats:id/securityCode").send_keys("000000")
       # time.sleep(2)
        #self.driver.find_element_by_id("com.sinosun.tchats:id/next_btn").click()
        time.sleep(10)
        
    @classmethod
    def tearDownClass(self):
        self.driver.quit()


if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(tChatAndroidTests)
    unittest.TextTestRunner(verbosity=2).run(suite)

        
#swipe的方法

def getSize(driver):
    x = driver.get_window_size()['width']
    y = driver.get_window_size()['height']
    return (x, y)

#屏幕向上滑动
def swipeUp(driver,t=1000):
    l = getSize(driver)
    x1 = int(l[0] * 0.5)    #x坐标
    y1 = int(l[1] * 0.75)   #起始y坐标
    y2 = int(l[1] * 0.25)   #终点y坐标
    driver.swipe(x1, y1, x1, y2,t)

#屏幕向下滑动
def swipeDown(driver,t=1000):
    l = getSize(driver)
    x1 = int(l[0] * 0.5)  #x坐标
    y1 = int(l[1] * 0.25)   #起始y坐标
    y2 = int(l[1] * 0.75)   #终点y坐标
    driver.swipe(x1, y1, x1, y2,t)
#屏幕向左滑动
def swipeLeft(driver,t=1000):
    l=getSize(driver)
    x1=int(l[0]*0.75)
    y1=int(l[1]*0.5)
    x2=int(l[0]*0.05)
    driver.swipe(x1,y1,x2,y1,t)
#屏幕向右滑动
def swipeRight(driver,t=1000):
    l=getSize(driver)
    x1=int(l[0]*0.05)
    y1=int(l[1]*0.5)
    x2=int(l[0]*0.75)
    driver.swipe(x1,y1,x2,y1,t)
 
'''
使用方法:
先导入方法,如果在同一个目录下,最好
例如使用左滑的方法:
from swipe import swipeLeft
直接调用:swipeLeft(driver)
即可
'''
    

 

转载于:https://www.cnblogs.com/botoo/p/9002534.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值