机器人框架文件和Python之间的不同类型的输入数据
-
20-12-2019 - |
题
我正在为自己的测试编写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获取单元格(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库/ 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'处 cell值命令行是一个字符串,所以我强迫它们在readexcel1.py
中的整数类型self.row_index = int(row_index)
self.col_index = int(col_index)
.
这解决了我的问题。
但我想知道为什么我们不需要强制改变原始readexcel.py中的类型,而python可以理解输入'0 1'是数字。但在readexcel1.py中,机器人理解'0 1'是一个字符串,我们必须强制更改'row_index,col_index'的类型?
请帮我清楚地提出这个问题。
谢谢。
解决方案
默认情况下,RF将通过那些参数作为字符串0和字符串1.如果要将那些传递为整数0和整数1,则使用$ {0}和$ {1}
看 http://robotframework.org/robotframework/latest/robotframeworkuserguide。HTML#数字变量
不隶属于 StackOverflow