python-3.xseleniumpycharmrobotframeworkautomation-testing

How to take file path from excel in robot framework


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


Solution

  • 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