Generate Robot Framework documentation for test cases - robotframework

Is there a way to generate Robot Framework documentation for test cases?
I can successfully generate documentation for Keywords and Libraries, using libdoc, but when I try to do the same for .robot files that contain only test cases, I get the errors below.
Test case file:
*** Settings ***
Documentation Suite documentation to appear on top of the html doc.
Resource ../Root.robot
Suite Setup Create Data
Suite Teardown Delete Data
Test Setup Go To Homepage
Test Teardown Close All Browsers
*** Test Cases ***
Test A
[Documentation] The test case documentation.
Do Something
Errors when using libdoc on this file:
Try --help for usage information.
[ ERROR ] Error in file '/<path>Test.robot': Non-existing setting 'Test Setup'.
[ ERROR ] Error in file '/<path>Test.robot': Non-existing setting 'Test Teardown'.
[ ERROR ] Error in file '/<path>Test.robot': Non-existing setting 'Suite Setup'.
[ ERROR ] Error in file '/<path>Test.robot': Non-existing setting 'Suite Teardown'.
Resource file '/<path>Test.robot' contains a test case table which is not allowed.
Is it because the setups and teardowns are not supported in libdoc?

Should use TestDoc and not LibDoc for test case documentation.
Both tools here:
http://robotframework.org/robotframework/#built-in-tools

Related

Local image import in nextjs with jest (react-testing-library) failed

I'm getting the below error while writing the test case against my home page, which contains the landing image.
FAIL src/test/unit/pages/home.test.tsx
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/Users/xys/Documents/work/working/project-code/client/src/asset/images/landing/landing.png:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){�PNG
SyntaxError: Invalid or unexpected token
> 1 | import LandingImage from '~/asset/images/landing/landing.png';
| ^
2 |
3 | const Images = {
4 | LandingImage
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1796:14)
at Object.<anonymous> (src/asset/index.tsx:1:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.012 s
Ran all test suites related to changed files.
I have tried the below-suggested solution in jest.config.js file but unable to resolve this.
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/client/src/tests/unit/fileMock.js",
Also, I tried all the solutions suggested in the below site.
Importing images breaks jest test
If you try to import an image (binary file), please try this within your package.json file:
"jest": {
"moduleNameMapper": {
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/client/src/tests/unit/fileMock.js",
}
}
get more information in jest docs here: https://jestjs.io/docs/code-transformation

Access Metadata set from cmd line in RobotFramework

In case of setting Metadata for top-level test suites with the --metadata command line option (as described here) I don't see any working variants of accessing Metadata items (via &{SUITE METADATA} automatic variable, as mentioned here) within the Test Suite.
Namely, when running
pybot --metadata prettyMetaName:someMetaValue ...
trying to get key prettyMetaName in the test suite setup with &{SUITE METADATA}[prettyMetaName], I get this error:
Parent suite setup failed:
Dictionary variable '&{SUITE METADATA}' has no key 'prettyMetaName'.
More detailed part of the test:
*** Keywords ***
Custom Setup
Log &{SUITE METADATA}[prettyMetaName] level=WARN
*** Settings ***
Suite Setup Custom Setup
But if I try to get metadata via python library Listener API, I'm getting the valid result.
On the other hand, in case of explicit declaring Metadata in the Settings section, everything works as expected.
I'm using Robot 3.0.4.
I think you need an __init__.robot file in the root folder of your robot project with the following content.
*** Settings ***
Suite Setup Store Top Suite Metadata
*** Keywords ***
Store Top Suite Metadata
Set Suite Variable ${TOP SUITE METADATA} ${SUITE METADATA} children=True
Then you can use the ${TOP SUITE METADATA} variable everywhere else to get access to the metadata set by command line arguments.

How to use Variable and UserKeyword from test case level, which created at project level

How to use Variable and UserKeyword from test case level, which created at project level.
I have a robot framework project like:
Project
Suite1
TC_001
TC_002
Suite2
TC_003
TC_004
I have create Variable and UserKeyword at project level and I want to use those Variable and UserKeyword from test case level. My question is, how to use them at test case level?
From the Robot Framework User Guide there are two sections you may want to go through in more detail:
Variables
Resource and variable files
Both of these describe how to import variables and external keywords from external files. In essence a resource file is a regular robot file but without the test cases. It only contains keywords and has the regular settings and variable sections. It can be imported in your test suite file through the Resource common.robot construct:
*** Settings ***
Resource common.robot
Resource feature_1.robot
Resource feature_2.robot
*** Variables ***
${HOST} localhost:7272
*** Keywords ***
Open Login Page
Do something
You'll have to import the file created in the "Project" directory, and afterwards you'll have access to the variables and keywords defined in it.
If the file there is called "The_project_file.robot", in "Suite_1.robot":
*** Settings ***
Resource ../The_project_file.robot
*** Test Case ***
TC_001
Log ${variable defined in The_project_file}
${value}= Keyword Defined In The Project File

robot framework: test case cannot load keyword in resource file that import in the test suite's parent test suite folder

Hi, I am using robot framework to automate testing of a website, and the image above is the structure of test in the RIDE:
Test: a test suite folder, and I import resource file here, which is in the "init.robot" under the folder
Sub1: a sub test suite, import nothing
test: a test case
My problem is: in the test case "test", robot cannot recognize the keyword that imported in the "Test" test suite folder, because there will be more sub test suites, like sub2, sub3, how can I import resource in one place? I don't want to import the resource file in every test suite, is there a way to do that?
You can chain an imports. Below is an example of such a chain and reuse. In this example we have a single resources.robot that imports all of the different sub*.robot files. This is the only file that imports these.
Then there are two testcases*.robot files that proceed to import resources.robot and are able to access the content of the sub*.robot keywords.
resources.robot
*** Settings ***
Resource ../resources/sub1.robot
Resource ../resources/sub2.robot
Resource ../resources/sub1.robot
testcases1.robot
*** Settings ***
Resource ../resources/resources.robot
*** Test Cases ***
TC
No Operation
testcases2.robot
*** Settings ***
Resource ../resources/resources.robot
*** Test Cases ***
TC
No Operation
As discussed in the comments, that any keyword imported in the __init__.robot file is not available beyond that file. This is clearly described in the Robot Framework User Guide section on Initialization files.
That said, if the effort of including the master resource file in each suite file undesirable, then an alternative approach is to load the resource file using a listener at the start of each Suite. The documentation on Listeners can be found here: Docs
A new example:
AddResourceListener.py
from robot.libraries.BuiltIn import BuiltIn
class AddResourceListener(object):
ROBOT_LISTENER_API_VERSION = 2
def __init__(self):
pass
def start_suite(self, name, attributes):
BuiltIn().import_resource('${EXECDIR}/resource.robot')
resource.robot
*** Keywords ***
Resource Keyword
Log "Keyword Executed from Resource File"
TestCase.robot
*** Test Cases ***
TC
Resource Keyword
Then run your regular robot command with the additional argument --listener AddResourceListener.py and you'll be able to use the keyword regardless if it's imported or not.

Test setup inheritance in Robot Framework

I'm trying to create a test setup hierarchy in robot framework.
I have a sub-suite, that defines its own Test Setup - but this overrides the parent suite's Test Setup.
I want both Test setups to run - one after the other, first the Parent Test Setup (that is defined in init.txt) and after that the Test setup that is defined using the * Settings * section.
You can achieve this kind of behavior at least with a bit of a hack way, by using set global variable, run keywords and an external resource file. This however requires you to define the test setup setting with a variable.
Example below:
Contents of __init__.txt:
*** Settings ***
Resource Resource.txt
Suite setup Set test setup variable
Test setup Test setup keyword
*** Keywords ***
Set test setup variable
Set global variable ${test setup variable} Test setup keyword
Contents of Resource.txt:
*** Keywords ***
Test setup keyword
Log Test setup from top level
Contents of Test_suite.txt:
*** Settings ***
Resource Resource.txt
Test setup Run keywords ${test setup variable} Test setup from test suite
*** Test cases ***
Test test setups
Log this should run two log keywords.
*** Keywords ***
Test setup from test suite
Log Test setup from test suite
I think this is the closest you can get.

Resources