Python unittest架構實現appium登入

來源:互聯網
上載者:User

標籤:localhost   play   日誌   data   equal   cap   osi   host   spl   

import unittestfrom appium.webdriver import webdriverfrom ddt import data,ddt,unpackclass MyTestCase(unittest.TestCase):    def setUp(self):#準備的過程        desired_caps = {}        desired_caps["platformName"] = "Android"        desired_caps["platformVersion"] = "4.3"        desired_caps["deviceName"] = "127.0.0.1:62001"        desired_caps["appPackage"] = "com.syswin.baijingtoon"        desired_caps["appActivity"] = ""        desired_caps["unicodeKeyboard"] = "Ture"  # 支援漢字        desired_caps["resetKeyboard"] = "Ture"        self.driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)        print("setUp")        #使用ddt的data註解,編寫測試案例的參數,此時是多個參數的情況,每條參數就是一條測試案例    @data(("[email protected]","111111",False),          ("lsy.com", "1111112", True),          ("l%$%$", "111111", False))    @unpack    def test_login(self,username,password,expectedResult):#執行的過程,以test開頭的測試案例        self.driver.find_element_by_id("email").send_keys(username)#填寫郵箱        self.driver.find_element_by_id("pwd").send_keys(password)#填寫密碼        self.driver.find_element_by_id("btn").click()#點擊登入按鈕        try:            if self.driver.find_element_by_id("btn").is_displayed():#判斷是都還有登入按鈕,如果有result為False否則為Ture                result=False        except Exception :            result =True        self.assertEqual(result, expectedResult)#斷言    def tearDown(self):#清理的過程        self.driver.quit()  # 資源釋放,不釋放下次執行就會報錯new session 不能建立,不能建立時需要重啟appiumif __name__ == ‘__main__‘:    unittest.main()

測試案例執行層

import unittestimport unittestdemocases=unittest.TestLoader.loadTestsFromTestCase(unittestdemo.MyTestCase)#載入測試用例mysuit=unittest.TestSuite([cases])#通過用例套件來跑用例#用例套件外,想增加一條用例需要#注意如果使用ddt資料驅動,每條用例的名稱會自動產生,不是固定的test_login,所以不能通過以下方式添加單條用例,只能講所有csaes加到suit中mysuit.addTest(unittestdemo.MyTestCase("test_login"))#verbosity記錄層級# 0 (靜默模式): 只能獲得總的測試案例數和結果# 1 (預設模式): 非常類似靜默模式 只是在每個成功的用例前面有個“.” 每個失敗的用例前面有個 “F”# 2 (詳細模式):測試結果會顯示每個測試案例的所有相關的資訊myrunner=unittest.TextTestRunner(verbosity=2)myrunner.run(mysuit)

 

Python unittest架構實現appium登入

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.