Lesen von excel-Inhalten in robot framework
Ich bin neu in robot framework und python. Ich arbeite auf web services mit Hilfe SudsLibrary. Ich möchte Daten Lesen, Inhalte aus excel-Datei. Ich habe unten geschrieben code, sondern liest es nur 1 Zeile aus Datei. Ich will es Lesen, alle Zeilen aus der Datei.
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}
DataReader.py
import 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
`
- Haben Sie jemals Pandas? Es ist eine nette Funktion für Excel-Dateien Pandas.read_excel()
- Ich bin in der Lage zu Lesen alle Zeilen nun, jetzt habe ich zu tun, die gleiche Sache mit csv.
- Pandas-hat eine Funktion zum Einlesen der CSV-Dateien als auch: read_csv()
- Danke Euch allen, ich bin in der Lage zu tun, mit CSV-wie auch
- können Sie eine Antwort auf Ihre eigene Frage, so dass andere, die das gleiche problem haben, davon profitieren können?
- Der obige code für excel mit robot framework korrekt war, war ich mit falschen excel-Datei.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Hier ist Beispielcode zum Lesen von Werten aus Excel-Datei-
Variable strTempColValue haben nun den Wert der gewünschten Spalte index & bestimmten Zeile. Hier in diesem Beispiel haben wir bestimmte Zeile als 3.
http://navinet.github.io/robotframework-excellibrary/ExcelLibrary-KeywordDocumentation.html
Lesen von Daten Zeile für Zeile aus dem csv-Format, die ich unten verwendet python-code.
csvLibrary.py