require ’win32ole’ #使用win32ole可以操作excell文件,使數據保存在excell文檔中
require ’net/http’
excel = WIN32OLE.new(\"excel.application\") # 定義一個excel對象
excel.Visible = false
excel.WorkBooks.Open(\"d:\\\\default.xls\") #打開excel文件
[1,3].each do |j| #循環讀取excel文件的sheet,這里的有3個sheet
sheet = \"Action\" + j.to_s #sheet的名稱
excel.WorkSheets(sheet).Activate #激活sheet
rows = excel.WorkSheets(sheet).UsedRange.Rows.Count #取得每個sheet的行數
(2..rows).each do |i| #循環讀取各個sheet的數據,第一行為數據類型,真實數據從第二行開始
url = excel.Cells(i,1).value
urlChar = excel.Cells(i,2).value
res = Net::HTTP.get_response(URI.parse(url)) #得到服務器的返回的數據
puts \"價格正序排序狀態\" + i.to_s
puts url + \" \" + urlChar
puts res.body.include?(urlChar) #得到是否取得了想要的數據
ok,通過以上的代碼可驗證,每個頁面從服務器返回的數據是否是正確的
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/