Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I import a file with common keywords in robot framework?

In a robot framework, I have a test suite like this:

test-suite/
  ├── Common.robot
  ├── TestCaseA.robot
  └── TestCaseB.robot

The file Common.robot defines some keywords which will used by both TestCaseA.robot and TestCaseB.robot. In other languages Common.robot would be called a library, but trying to import it like this

*** Settings ***
Library         Commons

or like that

*** Settings ***
Library         Commons.robot

results in an error.

[ ERROR ] Error in file '[...]/TestCaseA.robot': Importing test library 'Commons' failed: ImportError: No module named Commons

The keyword Library seems to work only for low level test libraries. I am sure there has to be another way. How can user-defined libraries be included in robot framework?

like image 259
jotrocken Avatar asked Aug 27 '15 08:08

jotrocken


People also ask

Where can the keywords in the robot framework be imported from?

Library Keywords are keywords that come from the library we import in Robot Framework. We will now take a look at the Selenium library, which helps us interact with the browser.

How do I run keywords in Robot Framework?

END Use Run Keyword If in Robot Framework Run Keyword If ${True} Log This line IS executed. Run Keyword If ${False} Log This line is NOT executed. Use Run Keyword Unless in Robot Framework Run Keyword Unless ${True} Log This line is NOT executed. Run Keyword Unless ${False} Log This line IS executed.

How do you import variables in robot framework?

yml` extension is new in Robot Framework 3.2. YAML variable files can be used exactly like normal variable files from the command line using :option:`--variablefile` option, in the Settings section using :setting:`Variables` setting, and dynamically using the :name:`Import Variables` keyword.

How do I upload files to Robot Framework?

Choose File id:file-upload /Users/alapan/PycharmProjects/Robot-Framework/Resources/Upload/sunset. jpg – Choose File inputs the file path into the file input field locator. Here we are providing the absolute path of the image. > Clicks Element id:file-submit – Clicks the upload button.


1 Answers

If Common.robot is a plain text file or tab separated file having robot framework keywords, it should be imported in the Settings table. In robot framework, files with shared keywords are called resource files.

*** Settings ***
Resource      Common.robot

However, if it is a python file having shared keywords, it should be resourced as a library as

*** Settings ***
Library      Common.py

Note that in both cases the full filename has to be specified.

like image 170
Tilak Raj Singh Avatar answered Oct 05 '22 11:10

Tilak Raj Singh