0

So i have a robot project with selenium library as settings and i am currently executing on eclipse-ide. I have created a resource file with separate variables and keywords for easy usage. It was working fine, was able to run the project fine earlier. But suddenly i dont know what happened, but the resource file is not being considered even though no errors are shown with path. Let me just share the snippet.

This is the Resource file:

*** Settings ***
Library    SeleniumLibrary    


*** Variables ***

@{URL}  https://www.google.com   https://www.gmail.com


*** Keywords ***
URL_NavigationToGoogle
    Open Browser    ${URL}[0]  chrome
    Maximize Browser Window
    Set Browser Implicit Wait    10

This is robot file with test case:

*** Settings ***
Library    SeleniumLibrary       
Suite Setup    Log    Suite Setup    
Suite Teardown    Log    Suite Teardown    
Test Setup    Log    Test Setup    
Test Teardown    Log    Test Teardown   
Resource    ../../ResourceFile/Keywords_and_Variables.robot 
Default Tags    Google Page Test cases


    *** Test Cases ***
    
    Test_Case-1
        [Tags]  Entering google web page
        URL_NavigationToGoogle

This is the output:

Test_Case-1                                                           | FAIL |
No keyword with name 'URL_NavigationToGoogle' found.
------------------------------------------------------------------------------

Not able to determine the exact problem, but this was working perfectly fine before. I want to know why its not working now and how to resolve this. Any help would be appreciated. Let me know your thoughts and what i am doing wrong or if anything needs to be changed.

Thanks, Sandesh KS

Sandesh KS
  • 39
  • 6

1 Answers1

1

Basically the issue here is almost certainly related to the resource path or filename.

Easy way to make sure the issue is fixed and doesn't reappear is to adjust the PYTHONPATH variable either in command prompt or via a batch file before starting the test. If the file location is in the variable, the import can be done simply as

Resource    Keywords_and_Variables.robot

This way is also the easiest when importing any custom Python libraries, that are not packaged as you won't be able to import them as libraries without having the location in your PYTHONPATH variable.

To set the variable, use simply

set PYTHONPATH = <path/to/resources/>;%PYTHONPATH%

The ;%PYTHONPATH% makes sure that any earlier changes are not lost and you are simply adding new location to it.

Usually I have a batch file located somewhere with the test files and whenever executing tests I first run the batch script and only then start robot tests.

As an example, if running from a Command Prompt you'd do it like this.

  1. Import resource file to your script
*** Settings ***
Library    SeleniumLibrary       
Suite Setup    Log    Suite Setup    
Suite Teardown    Log    Suite Teardown    
Test Setup    Log    Test Setup    
Test Teardown    Log    Test Teardown   
Resource    ResourceFile/Keywords_and_Variables.robot  # Path not needed if already in PYTHONPATH
Default Tags    Google Page Test cases
  1. Open CMD
  2. type in set PYTHONPATH=<path/to/resourcefile>;%PYTHONPATH -- Replace <> with the actual path relative to current location
  3. Launch test normally

PYTHONPATH can also be set as environment variable to your Windows PATH if that's preferred.


Alternatively your issue has nothing to do with the PYTHONPATH and instead there is a syntax error in your resource file which would prevent the import.

Morkkis
  • 450
  • 3
  • 12
  • i dont quite follow the process. Could you explain what i need to do step by step please? – Sandesh KS Sep 14 '21 at 09:06
  • @SandeshKS I have added step-by-step to the answer. Just realised while writing that this may also be caused by a syntax error in your robot script. Because of Python you won't always get an error message from the import before attempting to use a missing keyword, causing this kind of error. – Morkkis Sep 15 '21 at 11:07
  • Thanks a lot for taking the time to reply. You were right. The problem was with a keyword syntax error. I have not shared that part of the keyword in my snippet above. But it was definitely a syntax error of a particular keyword. I changed it and now its working. Thanks a lot again. – Sandesh KS Sep 20 '21 at 08:50