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
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.
*** 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
set PYTHONPATH=<path/to/resourcefile>;%PYTHONPATH
-- Replace <> with the actual path relative to current locationPYTHONPATH 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.