0

I want to upload a text file in application under test. The path of text file is put in one of the cells of excel. I tried using excel library but I am facing issue here. My code is not identifying excel library. I have installed robot framework excel library package in pycharm. Below is my excel and code snippet.

*** Settings ***
    Library           Selenium2Library
    Library           ExcelLibrary
    Library           Collections

*** Variables ***
${path_excel}   D:\\Users\\test.xls

*** Test Cases ***
open Excel    ${path_excel}
   #Click File Upload Here   
    Choose File   xpath=//input[@class="dz-hidden-input"]    ${path}
    

*** Keywords ***
[Arguments]  ${path}

enter image description here enter image description here

Amaze_Rock
  • 163
  • 3
  • 16

1 Answers1

1

You need to give your test case a name and run the excel keyword within it (indented)

e.g.

*** Settings ***
Library           Selenium2Library
Library           ExcelLibrary
Library           Collections

*** Test Cases ***
Test Case A
   ${path}  Get Path From Excel   D:\\Users\\test.xls
   Choose File   xpath=//input[@class="dz-hidden-input"]    ${path}

*** Keywords ***
Get Path From Excel
    [Arguments]  ${excel_file_path}
    Open Excel    ${excel_file_path}
    ${path}   Read Cell Data By Name   Robot_framework   A2
    [Return]  ${path}  

   

Your keyword also needs a name, just argument in keyword section isn't correct format, you use a keyword similar to how functions work in other languages

User Keyword Syntax

Matthew King
  • 624
  • 4
  • 11
  • Thanks Matthew but it is not working. Can you elaborate more specific with my example. – Amaze_Rock Apr 06 '22 at 08:28
  • @Amaze_Rock can you tell me please the error you are getting in the output? – Matthew King Apr 06 '22 at 09:43
  • I have put this in keywords *** Keywords *** ${my_data} open Excel ${path_excel} :For ${i} in range 2 \ ${my_data} Read Cell Data By Name Robot_framework A${i} \ Append To List ${my_datalist} ${my_data} Log ${my_data} and then below under test case Choose File xpath=//input[@class="dz-hidden-input"] ${my_data} and error is Keyword '${my_data}' expected 0 arguments, got 1. – Amaze_Rock Apr 06 '22 at 10:02
  • @Amaze_Rock okay I added a basic example of how to define a keyword, although this is unrelated to the question of not identifying an excel keyword. You really need to look up some fundamentals in the docs like in the link – Matthew King Apr 06 '22 at 10:27
  • Another error Replacing variables from keyword return value failed: Variable '${Path}' not found. I think it is not reading the cell where file path has been defined to upload. – Amaze_Rock Apr 06 '22 at 10:37
  • @Amaze_Rock I made the line a comment so you can put in your code how you want it. I'll update the example but I'm not sure what you want to do with the for loop – Matthew King Apr 06 '22 at 12:27
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/243651/discussion-between-matthew-king-and-amaze-rock). – Matthew King Apr 06 '22 at 12:41
  • Its working Matthew. Actually I have done that but somewhere it was taking a space. Its Resolved. Thanks ! – Amaze_Rock Apr 06 '22 at 16:42