Python編寫Appium測試案例(2)

來源:互聯網
上載者:User

標籤:

 

#coding=utf-8
import os,sys
import unittest
from appium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

 

# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
ISOTIMEFORMAT=‘%Y-%m-%d %X‘

class LoginTests(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps[‘platformName‘] = ‘Android‘
        desired_caps[‘platformVersion‘] = ‘4.4.4‘
        desired_caps[‘deviceName‘] = ‘24c13456‘
        #desired_caps[‘app‘] = PATH(‘ContactManager/ContactManager.apk‘)
        desired_caps[‘appPackage‘] = ‘com.aaa.bbb‘
        desired_caps[‘appActivity‘] = ‘.MainActivity‘

        self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘, desired_caps)

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

    def test_user_login(self):
        WebDriverWait(self.driver,20).until(EC.presence_of_element_located((By.NAME, u‘個人中心‘)))
        #開啟個人中心
        el_login = self.driver.find_element_by_name(u"個人中心")
        el_login.click()

        #判斷當前元素是否存在,若是存在,則使用者已登入;若不存在,則執行登入操作

        if(WebDriverWait(self.driver, 10).until(EC.invisibility_of_element_located((By.ID,‘id_username‘)))):
            pass
        else:
            sys.exit()
        #開啟登入頁面
        login_register = self.driver.find_element_by_id(‘btn_islogin‘)
        login_register.click()
        #輸入使用者名稱,密碼,然後登入
        user_name = self.driver.find_element_by_id(‘et_usename‘)
        user_name.send_keys(‘aaa‘)
        user_pass = self.driver.find_element_by_id(‘et_passwrod‘)
        user_pass.send_keys(‘123456‘)
        butn_login = self.driver.find_element_by_id(‘btn_login‘)
        butn_login.click()

    def test_user_logout(self):
        #重新開啟用戶端,然後退出app
        WebDriverWait(self.driver,20).until(EC.presence_of_element_located((By.NAME, u‘個人中心‘)))
        el_logout = self.driver.find_element_by_name(u"個人中心")
        el_logout.click()
        #開啟個人資訊頁面
        WebDriverWait(self.driver,20).until(EC.presence_of_element_located((By.ID, ‘id_username‘)))
        login_pic = self.driver.find_element_by_id(‘btn_islogin‘)
        login_pic.click()
        user_logout = self.driver.find_element_by_id(‘id_logout‘)
        user_logout.click()

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

 

 參考文章:

a) http://www.tuicool.com/articles/vQ36nyZ

 

Python編寫Appium測試案例(2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.