How to add Info to custom keyword Log - robotframework

In Robot Framework, when you create a custom keyword using the *** Keyword *** section of .robot file, is there a way to print an INFO message in the log file? I've tried using BuiltIn.Log keyword, but it creates a new keyword section where the INFO is written.
I want to get INFO in custom keyword this way:
Info in Keyword execution
But currently, my only option is: Info inside BuiltIn.Log definition
Is there a way to add INFO directly to my custom keyword without using Python API?

Did you try Log to console Typing text ${User} into text field 'username' like this?

To my knowledge what you are attempting, is unfortunately not doable. This way of embedding messages can be done by the robot.logger or Python's logging api - More info in the Robot Framework User Guide
However in addition to using the Log keyword, you may alleviate the need by first adding a documentation string on your keywords - the first line is always shown in the Documentation section of the keyword. Additionally by enabling Trace on the log file you'll get at least the Arguments and Return values shown on each keyword.
The Documentation is added with the [Documentation] tag similar to
Custom Keyword
[Documentation] This string is shown completely until I leave at least
... One empty row.
...
... This is shown only in the library documentation file.
And logging modes are changed with a launch option -L or --loglevel, to enable Trace mode, simply add the option when launching your robot.
robot -t TestName -s SuiteName -L TRACE .\Path\to\Tests

Related

display options for subcommands using PicoCLI

I am using PicoCLI v4.0.0-beta-1b. I am using different subcommands linked from a parent command. The parent command's optional parameters get displayed when I launch the CLI but not for the subcommands. The subcommands only appears underneath commands (but with no options).
How does one go about to ensure that the options for subcommands appear in the CLI as well?
Options:
-a, --autocomplete Generate sample autocomplete
-h, --help Display this help message.
-v, --verbose Verbose mode. Helpful for troubleshooting.
-V, --version Show version info and exit.
Commands:
abc
def
By default, picocli only shows an overview of a command's subcommands, and no details. This follows the conventions of other command suites like git. The idea is that end users can always get details for another subcommand by asking for help for that specific subcommand, like git commit --help, or git help commit.
While this is a useful default, if that's not what you want, picocli usage help is highly customizable.
The picocli usage message has the following sections:
header heading
header
synopsis heading
synopsis
description heading
description
positional parameter list heading
positional parameter list
option list heading
option list
command list heading
command list
exit code list heading (since 4.0)
exit code list (since 4.0)
footer heading
footer
Each section has its own IHelpSectionRenderer, and you can change the usage help by removing, reordering or replacing these help section renderers.
An example to get you started is here:
https://github.com/remkop/picocli/blob/master/picocli-examples/src/main/java/picocli/examples/customhelp/ShowAll.java
The above example has a custom IHelpSectionRenderer for the command list, to show the full hierarchy of commands, subcommands, and sub-subcommands, etc. You may want to do something similar but show the options of the subcommands instead.
You will need to familiarize yourself with some details of the picocli Help API, like TextTable, Layout, IOptionRenderer, etc.

How to change reports or output saving location in robot framework from RIDE

When I run test cases from RIDE the reports are saved in the below path.
C:\Windows\Temp\RIDExf4xla.d
I want save reports in specific path. Can I do this from RIDE? Is there any setting to change the reports location?
Can anyone please suggest the way to do it.
Thanks
Look at the --outputdir command within the Robot Framework Documentation:
Here is what I use:
--outputdir C:/Robot/AutomationLogs/etc/etc --timestampoutputs
You use this one liner on the "Arguments" Field, right on the top of RIDE within the run tab.
From Wamans comment you can add formats to the end of the argument, to also change the dir name dynamically. See the 2nd answer within that SO question. This should be enough for you to get what you're asking for.
There is no way to set this within a UI.
Just set it by pasting that argument option within the "Arguments" Field at the top.
use below code in command line
C:\Tests\> robot -d C:\Test_results Test.robot

Robot Framework HTML Report Customisation

I need to customize the HTML report generated at the end of test execution.
Few things I require are:
Remove the table - Statistics by Tags as I am not using any tags
Add the version number for the SUT in the summary section of the report.
What solutions are there for this? I tried to change the robot code and also tried to work on the output.xml. But nothing worked.
There is no facility provided by robot to customize the report and log files, as far as adding or removing sections is concerned. You have two options:
write your own report generator that converts output.xml into a format you like, or
create a fork of the robot framework source code and make the modifications there.
For the case of putting the version number for the SUT in the summary section of the report, you can add that with the --metadata command line option:
pybot --meta "SUT version: 1.2.3" ...
That will add the version to the summary section. You can also use the Documentation setting or the --doc command line option to put information that will appear in the report summary.
If you aren't using tags, you should! Those are one of the best features of the framework. You can create tags during a test run, so you could have your tests define a "sut version" tag and set it to the version of the system being tested.

Refactoring a test case to stop logging an error

I have a Robot Framework keyword that looks like this:
_Open Search Form If Not Open
${status} ${error} Run Keyword And Ignore Error Page Should Contain Element ${PATIENT SEARCH FORM}
Run Keyword If '${status}'=='FAIL' Click Element ${PATIENT SEARCH BUTTON}
It's intended to only be run if ${PATIENT SEARCH FORM} isn't open. However, whenever pybot detects that Page Should Contain Element is false, it logs this as an error in the test log. The test cases that use this keyword pass, and you need to dig into the log to see the failure, but it's still there. It's not intended to be a failure, though, and I don't want it logged as such.
The real pain is this: I am using Selenium2Library for my tests, and one of its default import options is run_on_failure=Capture Page Screenshot. I like this functionality, but whenever Page Should Contain Element fails and writes a 'FAIL' message to the test log, this functionality fires. Then the screenshots that are created clutter up my log folder and give a false impression that a test has failed when it hasn't.
What I would like is to either refactor this keyword to not log a failure, or somehow disable Selenium2Library's screenshot functionality for just this keyword. I used Run Keyword And Ignore Error to try to get pybot to ignore the error and not write it to the log, but I must be misinterpreting the meaning of "ignore" here. A part of the problem is my use of Page Should Contain Element. I'm using a verify keyword, but really, I'm asking "Does the page contain this element?" and not verifying that it does or does not. I haven't found anything in Selenium2Library that would just return the status of a page element without trying to make an assertion on top of it. But what I'm essentially trying to do is write a conditional statement.
Then the screenshots that are created clutter up my log folder and give a false impression that a test has failed when it hasn't.
Here is my code to save the screenshots only failed tests
*** Settings ***
Library Selenium2Library run_on_failure=Nothing
Test Teardown Test Teardown
*** Test Cases ***
Simple test
${status} ${error} Run Keyword And Ignore Error Page Should Contain Element ${PATIENT SEARCH FORM}
Run Keyword If '${status}'=='FAIL' Click Element ${PATIENT SEARCH BUTTON}
Pass Execution
*** Keywords ***
Test Teardown
Run Keyword If Test Failed Selenium2Library.Capture Page Screenshot
I believe what you are expecting will not be possible. The keyword will still be logged and shown as FAIL in your log.html even though your test is passed. To control the screenshot, you can use #Dmitriy Zverev solution.
Here's my solution:
_Open Search Form If Not Open
${previous kw}= Register Keyword To Run On Failure None
${status} ${error} Run Keyword And Ignore Error Page Should Contain Element ${PATIENT SEARCH FORM}
Register Keyword To Run On Failure ${previous kw}
Run Keyword If '${status}'=='FAIL' Click Element ${PATIENT SEARCH BUTTON}
I used Register Keyword To Run On Failure to disable screenshot capture temporarily.

assertTextPresent equivalent in phpunit

I'm trying to test for the presence of a string somewhere in a long webpage. Using PHPUnit's assertRegExp if the string is not found it prints out the entire page and then finishes with matches PCRE pattern "/xxxxxx/". According to the documentation I should be able to specify a message a third that will be printed out if the test fails. That message is printed, followed by the full page source. What I'd like to do is just print the message. Using Selenium in my previous apps I used assertTextPresent and it would just print out confirmation that the text was/was not found, without filling my screen.
I have tried wrapping the assertRegExp in a try-catch but it didn't change anything.
You could try assertContains() instead of assertRegexp().
PHPUnit is responsible for printing out the failed text, and this differs from one assert method to another. It just might work.
If it does not, open an issue at PHPUnit's issue tracker about PHPUnit printing too much out.
I am using the getBodyText() method to get all page content and than I use assertTextPresent() to check the presence of pattern.
$this->assertTextPresent($this->getBodyText(), 'text to find');
The solution has been positivly tested with latest phpunit 4.7.
I use assertTrue(stripos($haystack, $needle) !== false, 'Failed assertion message');

Resources