I have been using robot framework for testing my Rest APIs?
But I have no clue if we can test asynchronous services. I started to look for robotframework-async library but still could not figure it out.
Robot Framework is able to test asynchronous services. The trick is using wait conditions before your verification.
Try:
*** Test Cases ***
Load And Verify Table Data
Click Button To Load Table
Verify First Row Details
*** Keywords ***
Click Button To Load Table
Click Element ${SOME_BUTTON}
Wait Until Element Is Enabled ${SOME_ELEMENT_TO_WAIT_FOR}
Verify First Row Details
Table Row Should Contain ${TABLE_LOCATOR} 1 ${SOME TEXT}
Or something like that. Just whatever you do, don't use Sleep keywords. You will regret it later.
Related
I have recently started to learn GUI automation with Robot Framework and I bumped into my first problem.
I am trying to make a script that will test all confirmation dialogues on the website. My current solution for this is a custom keyword with all the tests in it, and then I call the keyword for each confirmation dialogue.
Test Confirmation Dialogue ${CD1}
Test Confirmation Dialogue ${CD2}
Test Confirmation Dialogue ${CD3}
*
*
*
Is there a way to put this in some loop and avoid using the keyword once per confirmation dialogue?
Create a loop over all CD variables, and pass each to your keyword:
FOR ${cd} IN ${CD1} ${CD2} ${CD3}
Test Confirmation Dialogue ${cd}
END
I'm currently developing a couple of test cases with robotframework to compare some excel value with value inside our database.
I have to do it inside a specific test case as it is deploy on zephyr.
I am checking each value inside this test case by calling a homemade Keyword that does :
Run Keyword Should Contain ${valeurExcel1} ${valeurBDD1}
Run Keyword Should Contain ${valeurExcel2} ${valeurBDD2}
etc...
I need every single one of those "Should Contain" to be display in a separated row in the report.html
It currently only appear as one row as it is one test case.
Is there anyway to specify to robot framework that i want him to consider every "Should Contain" as a unique test case and to display it in a row on the report.html ?
(Maybe by tagging ?)
No you can't. If you want a row for each "should contain" then each of those call should be made in its own test case.
But I think the problem lies in your "I have to do it inside a specific test case as it is deploy on zephyr". Whatever you need to do before/after a test case, can be done in a "suite setup" (and "suite teardown"). So you could have this kind of architecture:
*** Settings ***
Suite Setup deploy SUT / Zephyr
Suite Teardown shutdown SUT / Zephyr
*** Test Cases ***
tc1
Run Keyword Should Contain ${valeurExcel1} ${valeurBDD1}
tc2
Run Keyword Should Contain ${valeurExcel2} ${valeurBDD2}
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.
Is there some configuration setting that I must perform to get Robot Framework (RF) to run Gherkin/BDD style test cases?
I have installed RF 2.8.3 on Windows 7 and is running OK with Selenium2Library and DatabaseLibrary. According to the user docs and other info on the web, I should be able to write and run Gherkin style tests. However, when I do this, I get errors. RF does not strip the Gherkin keywords (Given, When, Then, ...) before trying to match the keyword:
Tests.Group001 GeneralTests
==============================================================================
Scenario: No template operation selected | FAIL |
No keyword with name 'But page does not contain a no template operation selected error message' found.
------------------------------------------------------------------------------
I run the tests using a straight-forward:
pybot ../Tests
My sample test file is:
*** settings ***
Library Selenium2Library
Library DatabaseLibrary
Library kw_common
*** Test Cases ***
Scenario: No template operation selected
Given I have logged in and I have selected to perform template configuration
When I do not select a template operation
But page does not contain a no template operation selected error message
And I press the next button
Then I should not see a template operation selected error message
*** Keywords ***
I have logged in and I have selected to perform template configuration
Log Given I have logged in and I have selected to perform template configuration
I do not select a template operation
Log No template operation selected
page does not contain a no template operation selected error message
Page Should Not Contain 'ddTemplateOperation' is required.
I press the next button
Click Element xpath=//input[contains(#id,'next')]
I should not see a template operation selected error message
Page Should Contain 'ddTemplateOperation' is required.
Help would be much appreciated. Thanks.
From the official documentation http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#ignoring-given-when-then-and-but-prefixes :
Prefixes Given, When, Then and And are dropped when matching keywords
are searched
So page does not contain a no template operation selected error message keyword needs to be renamed to But page does not contain a no template operation selected error message.
I'm trying to write my first robot test; I'd like to use ride as advertized in http://developer.plone.org/reference_manuals/external/plone.app.robotframework/happy.html#install-robot-tools
I added
initialization =
import os
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + '${buildout:directory}/bin'
to my [robot] section to make it possible to run the tests clicking "Start" in ride.
It works, but the second time I run the tests I still see the content created by the first test run.
How do I tell robot-server to go back to a just-initialized state?
Easily (and you should throw me into pool for not documenting this yet in plone.app.robotframework's documentation – I thought that RIDE is too difficult to get running until it works on wxPython 2.9).
In RIDE
select Run-tab
change Execution Profile to custom script
click browse to select for bin/robot from your buildout as the Script to run tests
Click Start.
Technically bin/robot is a shortcut for bin/pybot --listener plone.app.robotframework.RobotListener (I keep repeating bin/, because it's important that plone.app.robotframework is available in sys.path). Robot Framework Listener -interface is specified in Robot Framework User Guide.
Our listener calls bin/robot-server (using XML-RPC) before every test to testSetUp-methods for the current test layer and after every test testTearDown-methods. This resets the fixture and isolates functional tests.