国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

網(wǎng)頁設(shè)計制作的流程seo優(yōu)化服務(wù)

網(wǎng)頁設(shè)計制作的流程,seo優(yōu)化服務(wù),wordpress 同步 朋友圈,網(wǎng)站建設(shè)制作設(shè)計seo優(yōu)化湖北數(shù)據(jù)驅(qū)動模式的測試好處相比普通模式的測試就顯而易見了吧!使用數(shù)據(jù)驅(qū)動的模式,可以根據(jù)業(yè)務(wù)分解測試數(shù)據(jù),只需定義變量,使用外部或者自定義的數(shù)據(jù)使其參數(shù)化,從而避免了使用之前測試腳本中固定的數(shù)據(jù)??梢詫y試腳本…

數(shù)據(jù)驅(qū)動模式的測試好處相比普通模式的測試就顯而易見了吧!使用數(shù)據(jù)驅(qū)動的模式,可以根據(jù)業(yè)務(wù)分解測試數(shù)據(jù),只需定義變量,使用外部或者自定義的數(shù)據(jù)使其參數(shù)化,從而避免了使用之前測試腳本中固定的數(shù)據(jù)??梢詫y試腳本與測試數(shù)據(jù)分離,使得測試腳本在不同數(shù)據(jù)集合下高度復(fù)用。不僅可以增加復(fù)雜條件場景的測試覆蓋,還可以極大減少測試腳本的編寫與維護(hù)工作。

下面將使用Python下的數(shù)據(jù)驅(qū)動模式(ddt)庫,結(jié)合unittest庫以數(shù)據(jù)驅(qū)動模式創(chuàng)建百度搜索的測試。

ddt庫包含一組類和方法用于實(shí)現(xiàn)數(shù)據(jù)驅(qū)動測試??梢詫y試中的變量進(jìn)行參數(shù)化。

可以通過python自帶的pip命令進(jìn)行下載并安裝:pip install ddt .

一個簡單的數(shù)據(jù)驅(qū)動測試

為了創(chuàng)建數(shù)據(jù)驅(qū)動測試,需要在測試類上使用@ddt裝飾符,在測試方法上使用@data裝飾符。@data裝飾符把參數(shù)當(dāng)作測試數(shù)據(jù),參數(shù)可以是單個值、列表、元組、字典。對于列表,需要用@unpack裝飾符把元組和列表解析成多個參數(shù)。

下面實(shí)現(xiàn)百度搜索測試,傳入搜索關(guān)鍵詞和期望結(jié)果,代碼如下:

import unittest
from selenium import webdriver
from ddt import ddt, data, unpack@ddt
class SearchDDT(unittest.TestCase):'''docstring for SearchDDT'''def setUp(self):self.driver = webdriver.Chrome()self.driver.implicitly_wait(30)self.driver.maximize_window()self.driver.get("https://www.baidu.com")# specify test data using @data decorator@data(('python', 'PyPI'))@unpackdef test_search(self, search_value, expected_result):search_text = self.driver.find_element_by_id('kw')search_text.clear()search_text.send_keys(search_value)search_button = self.driver.find_element_by_id('su')search_button.click()tag = self.driver.find_element_by_link_text("PyPI").textself.assertEqual(expected_result, tag)def tearDown(self):self.driver.quit()if __name__ == '__main__':unittest.main(verbosity=2)

在test_search()方法中,search_value與expected_result兩個參數(shù)用來接收元組解析的數(shù)據(jù)。當(dāng)運(yùn)行腳本時,ddt把測試數(shù)據(jù)轉(zhuǎn)換為有效的python標(biāo)識符,生成名稱為更有意義的測試方法。結(jié)果如下:

現(xiàn)在我也找了很多測試的朋友,做了一個分享技術(shù)的交流群,共享了很多我們收集的技術(shù)文檔和視頻教程。
如果你不想再體驗(yàn)自學(xué)時找不到資源,沒人解答問題,堅持幾天便放棄的感受
可以加入我們一起交流。而且還有很多在自動化,性能,安全,測試開發(fā)等等方面有一定建樹的技術(shù)大牛
分享他們的經(jīng)驗(yàn),還會分享很多直播講座和技術(shù)沙龍
可以免費(fèi)學(xué)習(xí)!劃重點(diǎn)!開源的!!!
qq群號:110685036

使用外部數(shù)據(jù)的數(shù)據(jù)驅(qū)動測試

如果外部已經(jīng)存在了需要的測試數(shù)據(jù),如一個文本文件、電子表格或者數(shù)據(jù)庫,那也可以用ddt來直接獲取數(shù)據(jù)并傳入測試方法進(jìn)行測試。

下面將借助外部的CSV(逗號分隔值)文件和EXCLE表格數(shù)據(jù)來實(shí)現(xiàn)ddt。

通過CSV獲取數(shù)據(jù)

同上在@data裝飾符使用解析外部的CSV(testdata.csv)來作為測試數(shù)據(jù)(代替之前的測試數(shù)據(jù))。其中數(shù)據(jù)如下:

接下來,先要創(chuàng)建一個get_data()方法,其中包括路徑(這里默認(rèn)使用當(dāng)前路徑)、CSV文件名。調(diào)用CSV庫去讀取文件并返回一行數(shù)據(jù)。再使用@ddt及@data實(shí)現(xiàn)外部數(shù)據(jù)驅(qū)動測試百度搜索,代碼如下:

import csv, unittest
from selenium import webdriver
from ddt import ddt, data, unpackdef get_data(file_name):# create an empty list to store rowsrows = []# open the CSV filedata_file = open(file_name, "r")# create a CSV Reader from CSV filereader = csv.reader(data_file)# skip the headersnext(reader, None)# add rows from reader to listfor row in reader:rows.append(row)return rows@ddt
class SearchCSVDDT(unittest.TestCase):def setUp(self):self.driver = webdriver.Chrome()self.driver.implicitly_wait(30)self.driver.maximize_window()self.driver.get("https://www.baidu.com")# get test data from specified csv file by using the get_data funcion@data(*get_data('testdata.csv'))@unpackdef test_search(self, search_value, expected_result):search_text = self.driver.find_element_by_id('kw')search_text.clear()search_text.send_keys(search_value)search_button = self.driver.find_element_by_id('su')search_button.click()tag = self.driver.find_element_by_link_text("PyPI").textself.assertEqual(expected_result, tag)def tearDown(self):self.driver.quit()if __name__ == '__main__':unittest.main(verbosity=2)

測試執(zhí)行時,@data將調(diào)用get_data()方法讀取外部數(shù)據(jù)文件,并將數(shù)據(jù)逐行返回給@data。執(zhí)行的結(jié)果也同上~
如果對軟件測試、接口測試、自動化測試、面試經(jīng)驗(yàn)交流。感興趣可以加軟件測試交流:1085991341,還會有同行一起技術(shù)交流。

通過Excel獲取數(shù)據(jù)

測試中經(jīng)常用Excle存放測試數(shù)據(jù),同上在也可以使用@data裝飾符來解析外部的CSV(testdata.csv)來作為測試數(shù)據(jù)(代替之前的測試數(shù)據(jù))。其中數(shù)據(jù)如下:

接下來,先要創(chuàng)建一個get_data()方法,其中包括路徑(這里默認(rèn)使用當(dāng)前路徑)、EXCEL文件名。調(diào)用xlrd庫去讀取文件并返回數(shù)據(jù)。再使用@ddt及@data實(shí)現(xiàn)外部數(shù)據(jù)驅(qū)動測試百度搜索,代碼如下:

import xlrd, unittest
from selenium import webdriver
from ddt import ddt, data, unpackdef get_data(file_name):# create an empty list to store rowsrows = []# open the CSV filebook = xlrd.open_workbook(file_name)# get the frist sheetsheet = book.sheet_by_index(0)# iterate through the sheet and get data from rows in listfor row_idx in range(1, sheet.nrows): #iterate 1 to maxrowsrows.append(list(sheet.row_values(row_idx, 0, sheet.ncols)))return rows@ddt
class SearchEXCLEDDT(unittest.TestCase):def setUp(self):self.driver = webdriver.Chrome()self.driver.implicitly_wait(30)self.driver.maximize_window()self.driver.get("https://www.baidu.com")# get test data from specified excle spreadsheet by using the get_data funcion@data(*get_data('TestData.xlsx'))@unpackdef test_search(self, search_value, expected_result):search_text = self.driver.find_element_by_id('kw')search_text.clear()search_text.send_keys(search_value)search_button = self.driver.find_element_by_id('su')search_button.click()tag = self.driver.find_element_by_link_text("PyPI").textself.assertEqual(expected_result, tag)def tearDown(self):self.driver.quit()if __name__ == '__main__':unittest.main(verbosity=2)

與上面讀取CVS文件一樣,測試執(zhí)行時,@data將調(diào)用get_data()方法讀取外部數(shù)據(jù)文件,并將數(shù)據(jù)逐行返回給@data。執(zhí)行的結(jié)果也同上~

如果想從數(shù)據(jù)庫的庫表中獲取數(shù)據(jù),同樣也需要一個get_data()方法,并且通過DB相關(guān)的庫來連接數(shù)據(jù)庫、SQL查詢來獲取測試數(shù)據(jù)。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。有被幫助到的朋友歡迎點(diǎn)贊,評論。

http://aloenet.com.cn/news/40263.html

相關(guān)文章:

  • 佛山網(wǎng)站建設(shè)服務(wù)公司什么搜索引擎搜索最全
  • 黃村網(wǎng)站開發(fā)公司電話東莞營銷型網(wǎng)站建設(shè)
  • b2c商城網(wǎng)站網(wǎng)站搜什么關(guān)鍵詞
  • 黃岐做網(wǎng)站網(wǎng)站建設(shè)技術(shù)托管
  • 宜昌網(wǎng)站推廣關(guān)鍵詞優(yōu)化怎么弄
  • 優(yōu)化企業(yè)網(wǎng)站標(biāo)題河北百度競價優(yōu)化
  • 備案網(wǎng)站制作北京百度關(guān)鍵詞推廣
  • 企業(yè)注冊在哪個網(wǎng)站申請網(wǎng)絡(luò)營銷的發(fā)展現(xiàn)狀及趨勢
  • 合肥公司網(wǎng)站建設(shè)搜索引擎優(yōu)化排名seo
  • 在上面網(wǎng)站上可以做統(tǒng)計圖今日深圳新聞最新消息
  • 長沙專業(yè)網(wǎng)站設(shè)計平臺高質(zhì)量軟文
  • 音樂外鏈網(wǎng)站網(wǎng)站推廣引流最快方法
  • 設(shè)計素材網(wǎng)站0百度認(rèn)證怎么認(rèn)證
  • 旅行社門店做網(wǎng)站嘛營銷文案
  • 推廣網(wǎng)站排名優(yōu)化seo教程福州seo優(yōu)化
  • 盤縣做會計兼職的網(wǎng)站愛站網(wǎng)關(guān)鍵詞密度
  • 做網(wǎng)站有效果嗎揚(yáng)州整站seo
  • 江西響應(yīng)式網(wǎng)頁建設(shè)沙洋縣seo優(yōu)化排名價格
  • 教程網(wǎng)站搭建優(yōu)化網(wǎng)站快速排名軟件
  • 天津百度優(yōu)化武漢seo認(rèn)可搜點(diǎn)網(wǎng)絡(luò)
  • 公司做網(wǎng)站賣東西要什么證太原網(wǎng)站制作優(yōu)化seo公司
  • 網(wǎng)頁設(shè)計實(shí)訓(xùn)報告工作內(nèi)容和步驟長春網(wǎng)站建設(shè)方案優(yōu)化
  • 自己做的網(wǎng)站怎么賺錢嗎百度推廣助手客戶端
  • 大豐網(wǎng)站建設(shè)新東方教育培訓(xùn)機(jī)構(gòu)官網(wǎng)
  • 新余做網(wǎng)站公司培訓(xùn)班報名
  • 網(wǎng)站開發(fā)所需技能北京seo優(yōu)化廠家
  • 公司網(wǎng)站建設(shè)做分錄谷歌seo顧問
  • php網(wǎng)站的部署愛站網(wǎng)站長seo綜合查詢工具
  • 機(jī)械公司網(wǎng)站建設(shè)中國法律服務(wù)網(wǎng)app最新下載
  • wordpress 圖片 分離seo研究所