本文將介紹一套比較完整的appium自動化框架,以python為編寫腳本語言,是因為python有強大的庫,同時易學易懂。
最終的測試框架代碼,將在jenkins項目中一鍵構建,執行自動化測試用例,並輸出展現形式豐富的測試報告。
appium及python的環境,自行安裝和配置,本人使用pycharam進行自動化開發。
一、安裝nose及依賴庫
- pip install nose
- pip install nose-allure-plugin
- pip install nose-html-reporting
- pip install nose-ittr
- pip install nosehtmlouput-2
二、安裝allure及依賴庫
- pip install allure-behave
- pip install allure-python-commons
三、編寫測試用例
import unittest import nose from nose.tools import * import logging from page.common.tab_bar_page import TabBarPage from page.video.video_tab_bar_page import VideoTabBarPage from common.common_operate import * class TestVideoTabBar(unittest.TestCase): log = logging.getLogger(__name__) @classmethod def setUpClass(cls): cls.tab_bar = TabBarPage() cls.tab_bar.click_vedio_tab_bar() cls.video_tab_bar = VideoTabBarPage() def setUp(cls): pass # 點擊視頻文章標題 @nose.allure.feature('視頻Tab') @nose.allure.story('點擊標題-查看視頻文章') def test_01_click_video_title(self): try: self.video_tab_bar.click_video_title(0) assert_true(is_visibility(self.video_tab_bar.video_article_comments_btn_loc)) except TimeoutException as e: take_screenShot(u"點擊標題-查看視頻文章'") logging.error(e) assert_false(True) # 點擊視頻預覽圖 @nose.allure.feature('視頻Tab') @nose.allure.story('點擊視頻預覽圖-查看視頻文章') def test_02_video_preview(self): try: self.video_tab_bar.click_video_preview(0) assert_true(is_visibility(self.video_tab_bar.video_article_list_comments_btn_loc)) except TimeoutException as e: take_screenShot(u"點擊視頻預覽圖-查看視頻文章'") logging.error(e) assert_false(True) def tearDown(cls): get_press_keycode(4) @classmethod def tearDownClass(cls): time.sleep(3) get_press_keycode(4)
這里先貼一下測試用例腳本,后面會介紹自動化項目代碼、設計、運行原理等。