Robot框架文件和Python之间不同类型的输入数据
我正在为自己的测试编写Excel库Robot框架文件和Python之间不同类型的输入数据,python,robotframework,Python,Robotframework,我正在为自己的测试编写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)
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
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库/站点包文件夹,并重命名为“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可以理解输入“0 1”是数字。但在ReadExcel1.py中,Robot理解“01”是一个字符串,我们必须强制更改“行索引,列索引”的类型
请帮我把这个问题说清楚
谢谢。默认情况下,RF将以字符串0和字符串1的形式传递这些参数。如果要将它们作为整数0和整数1传递,请使用${0}和${1}
请参见默认情况下,RF将以字符串0和字符串1的形式传递这些参数。如果要将它们作为整数0和整数1传递,请使用${0}和${1} 看