Question

I'm writing Excel library for my own testing.

  1. Original Python library '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
    

Run an example to check whether this program can get the value of cell(0,1) via Eclipse or not?

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)

Copy this python file to Python Library/site-package folder and rename to 'ReadExcel1.py' Then write test case base on ReadExcel1.py library

*** 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 log show message as below:

The list indices must be integers, not unicode

So, I think due to the input '0 1' at Cell Value command line is a string, so i force them to integer type in ReadExcel1.py

self.row_index = int(row_index)
self.col_index = int(col_index) 

This solves my problem.

But I wonder why we don't need to force changing type in original ReadExcel.py, and python can understand the input '0 1' is number. But in ReadExcel1.py, Robot understands '0 1' is a string and we have to force changing type for 'row_index, col_index' ?

Please help me make this issue clearly.

Thanks.

Was it helpful?

Solution

By default RF will pass those arguments as string 0 and string 1. If you want to pass those as integer 0 and integer 1, then use ${0} and ${1}

See http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#number-variables

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top