Tipo diferente de dados de entrada entre o arquivo Robot Framework e Python
-
20-12-2019 - |
Pergunta
Estou escrevendo uma biblioteca do Excel para meus próprios testes.
Biblioteca Python original '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
Execute um exemplo para verificar se este programa pode obter o valor de cell(0,1) via Eclipse ou não?
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)
Copie este arquivo python para a pasta Python Library/Site-Package e renomeie para 'ReadExcel1.py' e, em seguida
*** 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
O log mostra a mensagem abaixo:
The list indices must be integers, not unicode
Então, acho que devido à entrada '0 1' em Valor da célula a linha de comando é uma string, então eu os forço a digitar inteiro em ReadExcel1.py
self.row_index = int(row_index)
self.col_index = int(col_index)
Isso resolve meu problema.
Mas eu me pergunto por que não precisamos forçar a mudança de tipo no ReadExcel.py original, e o python pode entender que a entrada '0 1' é um número.Mas em ReadExcel1.py, Robot entende que '0 1' é uma string e temos que forçar a mudança de tipo para 'row_index, col_index' ?
Por favor, ajude-me a esclarecer esse problema.
Obrigado.
Solução
Por padrão, o RF passará esses argumentos como string 0 e string 1.Se você quiser passá-los como número inteiro 0 e número inteiro 1, use ${0} e ${1}
Ver http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#number-variables