10

I am running into an issue with my Robot Framework test suites. I have a simple test structure like this:

robotframework
|_foo
 |_tests folder
 |_pages folder
 |_firefoxTestProfile folder
 |_...

I have set a bare bones Firefox Profile path to run my tests and have set the variable like so:

*** Variables ***
${FF_PROFILE}    foo\firefoxTestProfile
*** Keywords ***
Open browser window
    Open Browser    ${test_url}    ${browser}   
... ff_profile_dir=${FF_PROFILE}

When I run my tests from the top directory, it runs fine:

C:/robotframework$  pybot foo/tests/test.txt

However, if I try to run it from the foo directory, like this:

C:/robotframework/foo$  pybot tests/test.txt

The tests throw fails, stating

"The system cannot find the path specified: foo/firefoxTestProfile/*.*"

I tried various things, such as putting the path as

../foo/firefoxTestProfile
/foo/firefoxTestProfile
firefoxTestProfile

as well as moving the firefoxTestProfile folder to a different path within the file structure and updating to that new path, but none of this worked and displayed the same error message as before.

It's also important because I want a default firefox profile to run with the tests, and these tests are passed between different people for running them locally on their machines. Any help would be greatly appreciated.

3 Answers 3

25

There are several built-in variables that can help you define the path correctly.

The one that is most interesting here is ${CURDIR}

From the documentation:

${CURDIR}   An absolute path to the directory where the test data file is located.  This variable is case-sensitive.

I usually define a master suite setup file (in your case, in the root tests folder) and in there, I would define the following 3 global level variables

Create a file __init.robot at the root tests folder.

In it create a suite setup section (which will run before any test - but only once!)

Set Global Variable  ${testsRootFolder}  ${CURDIR}
Set Global Variable  ${pagesRootFolder}  %{CURDIR}${/}..${/}_pages
Set Global Variable  ${firefoxProfileFolder}  %{CURDIR}${/}..${/}firefoxTestProfile
Sign up to request clarification or add additional context in comments.

1 Comment

${CURDIR} seems to be the best option for achieving this. Thank you!
2

Unfortunately, Selenium has troubles - at least on Windows - with non-canonical paths. The ${/}..${/} turns out to be problematic and Selenium fails with file references using such strings.

A solution to this is to use the String library along with ${CURDIR}:

${UpperDir} ${Leaf} Split String From Right ${CURDIR}   ${/}    1

Comments

1

you can use relative path like this:

..${/}..${/}foo${/}firefoxTestProfile

You should mention the relative path of 'firefoxTestProfile' from the file which runs the tests.

1 Comment

No you can't. It is relative to where the file is exicuted, not relative to where the file is

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.