Python自動化測試系列[v1.0.0][兼容性測試方法]

在實際的自動化測試過程中,有些產品必須進行兼容性測試,那就意味着在不同的環境中執行相同的測試用例,而這應該是發揮自動化測試優勢的非常重要的戰地。
自動化在編寫兼容性測試用例的時候,稍微有所不同,需要我們定義好一個測試方法,然後執行不同環境時調用該方法,從而實現在不同的環境中執行相同的測試,如下代碼所示。

# -*- coding: utf-8 -*-
from selenium import webdriver
from time import sleep
import unittest
class Compatibility_Test(unittest.TestCase):
    def setUp(self):
        self.base_url = "https://admin.leadscloud.com/Front-breeze/#/home"
    def login_leadscloud(self, driver):
        '''
        定義測試方法
        :param driver:
        :return:
        '''
        driver.get(self.base_url)
        sleep(5)
        driver.find_element_by_xpath("//*[@id='main']/div/div[1]/div/div[2]/form/div[1]/div/div/input").send_keys('xxxxxx')
        driver.find_element_by_xpath("//*[@id='main']/div/div[1]/div/div[2]/form/div[2]/div/div/input").send_keys('xxxxxx')
        driver.find_element_by_xpath("//*[@id='main']/div/div[1]/div/div[2]/form/div[3]/div/button").click()
        driver.quit()
    def test_chrome(self):
        '''
        啓動chrome瀏覽器執行測試用例
        :return:
        '''
        chrome_driver = webdriver.Chrome()
        self.login_leadscloud(chrome_driver)
    def test_firefox(self):
        '''
        啓動firefox執行測試用例
        :return:
        '''
        firefox_driver = webdriver.Firefox()
        self.login_leadscloud(firefox_driver)
    def test_ie(self):
        '''
        啓動IE執行測試用例
        :return:
        '''
        ie_driver = webdriver.Ie()
        self.login_leadscloud(ie_driver)
if __name__ == '__main__':
    unittest.main(verbosity=2)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章