我正在为自己的测试编写Excel库。
原始Python库'ReadExcel.py':
from xlrd import open_workbook, XL_CELL_TEXT
class Read_Excel:
def __init__(self,excel_file):
self.excel_file = excel_file
self.book = open_workbook(self.excel_file)
self.sheet1_name = self.book.sheet_names()
def Take_Sheet_Name(self,name):
self.name = name
return self.name
def Cell_Value(self,row_index,col_index):
self.row_index = row_index
self.col_index = col_index
sheet = self.book.sheet_by_name(self.name)
cell_value = sheet.cell(self.row_index,self.col_index).value
return cell_value
运行一个例子来检查这个程序是否可以通过Eclipse获得cell(0,1)的值?
y = Read_Excel('simple.xlsx')
y.Take_Sheet_Name('name1')
print y.Cell_Value(0,1)
Result: 11 --> this number is the actual value on cell(0,1)
将此python文件复制到python Library/site package文件夹并重命名为“ReadExcel1.py” 然后基于ReadExcel1.py库编写测试用例
*** Settings ***
Documentation This is the resource file for Google test suite.
Library Selenium2Library
Library ReadExcel1 C:\\Automation_project\\Robot_framework\\Testing\\Check_activity\\simple.xlsx
*** Test Cases ***
Check Library
Take Sheet Name name1 --> pass
Cell Value 0 1 --> failed
日志显示消息如下:
The list indices must be integers, not unicode
因此,我认为由于输入'0 1'在单元格值命令行是一个字符串,所以我强制它们在ReadExcel1.py中为整数类型
self.row_index = int(row_index)
self.col_index = int(col_index)
这解决了我的问题。
但我想知道为什么我们不需要在原来的ReadExcel.py中强制更改类型,而python可以理解输入“01”是数字。但在ReadExcel1.py中,Robot知道“0 1”是一个字符串,我们必须强制更改“row_index,col_index”的类型?
请帮我把这个问题说清楚。
谢谢。
目前没有回答
相关问题 更多 >
编程相关推荐