使用appium实现登录功能的自动化

# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

from appium import webdriver
import time,os
import pytest


from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
time.sleep(3)
# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)




class LoginTest():
    def setUp(self):
        caps = {}
        caps["platformName"] = "Android"
        caps["platformVersion"] = "6.0.1"
        caps["deviceName"] = "2cbaea23"
        caps["app"] = "/Downloads/lazyfit2-bugly-debug(1).apk"
        caps["appPackage"] = "com.lryj.lazyfit"
        caps["appActivity"] = "com.lryj.lazyfit.ui.bootload.BootLoadActivity"
        self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
        #self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

    def test_start(self):
        # 申请授权
        for i in range(2):
            loc = ("xpath", "//*[@text='允许']")
            try:
                e = WebDriverWait(self.driver, 1, 0.5).until(EC.presence_of_element_located(loc))
                e.click()
            except:
                pass

        # 滑动第一页
        #self.driver.swipe(127,731)
        current = self.driver.current_context
        print(current)

        '''向左滑动屏幕'''
        l = self.driver.get_window_size()
        xs = l['width'] * 0.75
        ys = l['height'] * 0.5
        xe = l['width'] * 0.05
        for i in range(2):
            self.driver.swipe(xs, ys, xe, ys, 500)

        time.sleep(1)

        # 点击第三页立即体验按钮
        self.driver.find_element_by_id("com.lryj.lazyfit:id/bt_start").click()
        time.sleep(1)
        # 输入手机号码
        elEdit = self.driver.find_element_by_id("com.lryj.lazyfit:id/mPhoneEditText")
        self.assertIsNotNone(elEdit)
        elEdit.send_keys("17773237428")
        '''
        # 获取验证码
        #elCode = driver.find_element_by_id("com.lryj.lazyfit:id/mGetSmsCodeButton")
        #self.assertIsNotNone(elCode)
        #elCode.click()'''
        # 输入验证码
        #8350
        elCodeEdit = self.driver.find_element_by_id("com.lryj.lazyfit:id/mSmsCodeEditText")
        self.assertIsNotNone(elCodeEdit)
        elCodeEdit.send_keys(8350)

        # 点击登录按钮
        elInButton = self.driver.find_element_by_id("com.lryj.lazyfit:id/mSignInButton")
        self.assertIsNotNone(elInButton)
        elInButton.click()

    def tearDown(self):
        self.driver.quit()

if __name__=='__main__':
    LoginTest()

你可能感兴趣的:(appium)