python读取robot文件内容_读取robot fram中的excel内容

我是机器人框架和python的新手。我正在使用SudsLibrary开发web服务。我想从excel文件中读取数据内容。我已经为它编写了下面的代码,但它只从文件中读取一行。我要它读取文件中的所有行。Test.robot

*** Settings ***

Library DataReader.py

*** Variables ***

${file} ${CURDIR}${/}Book2.xls

${sheet} ABC

*** Test Cases ***

Test data provider

[Setup] prepare data

Create Soap Client http://test.asmx?WSDL

${ABC} Create Wsdl Object ABC

:FOR ${ABC.Col1} ${ABC.Col2} ${ABC.Col3} ${ABC.Col4} ${ABC.Col5} ${ABC.Col6} ${ABC.Col7} in @{testData}

\ ${ABC.Col1} Set Variable ${ABC.Col1}

\ ${ABC.Col2} Set Variable ${ABC.Col2}

\ ${ABC.Col3} Set Variable ${ABC.Col3}

\ ${ABC.Col4} Set Variable ${ABC.Col4}

\ ${ABC.Col4} = convert to integer ${ABC.Col4}

\ ${ABC.Col5} Set Variable ${ABC.Col5}

\ ${ABC.Col6} Set Variable ${ABC.Col6}

\ ${ABC.Col6}= convert to integer ${ABC.Col6}

\ ${ABC.Col7} Set Variable ${ABC.Col7}

\ ${ABC.Col7}= convert to integer ${ABC.Col7}

\ Set Test Variable ${ABC}

\ Call Soap Method ABC ${ABC}

\ ${soap_response} Get Last Received

\ Log ${soap_response}

\ Element Text Should Be ${soap_response} 2.991880011689

*** Keywords ***

prepare data

${data}= getDataFromSpreadsheet ${file} ${sheet}

Set Test Variable ${testData} ${data}

数据读取器.pyimport xlrd

def getDataFromSpreadsheet(fileName, sheetname) :

workbook = xlrd.open_workbook(fileName)

worksheet = workbook.sheet_by_name(sheetname)

print worksheet

rowEndIndex = worksheet.nrows - 1

colEndIndex = worksheet.ncols - 1

rowStartIndex = 1

colStartIndex = 0

testData = []

dataRow = []

curr_row = rowStartIndex

while curr_row <= rowEndIndex:

cur_col = colStartIndex

while cur_col <= colEndIndex:

cell_type = worksheet.cell_type(curr_row, cur_col)

value = worksheet.cell_value(curr_row, cur_col)

dataRow.append(value)

cur_col+=1

curr_row += 1

# testData.append(dataRow)

# return testData

return dataRow

`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值