• 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)
    即可
    '''
        
  • 相关阅读:
    MinGW GCC 7.1.0 2017年6月份出炉啦
    java面试题-框架篇九
    spring-AOP原理
    spring的bean管理(注解)
    23种设计模式(1)-单例模式
    SSH框架面试题集锦
    JQuery基础
    实现用户注册
    spring与hibernate的整合
    spring-IOC理解1
  • 原文地址:https://www.cnblogs.com/botoo/p/9002534.html
Copyright © 2020-2023  润新知