Skipping keyword execution in Robot Framework - automation

We are using robot Framework for automation. We have a scenario where we want to skip execution of some keywords based on an argument provided or a tag. These keywords are part of suite setup of test cases and in some scenarios, like for development environment, we want to skip execution of just these keyword.
Currently we pass in a global variable and use the RETURN FROM KEYWORD IF logic.
Could this be done with tags or is there any other better approach?

You can use Run keyword if to conditionally run your keyword
Run keyword if $environment=="dev" the keyword
You can then set the variable on the command. For example:
robot --variable environment:dev tests

Related

Robot Framework - capture screenshot when any keyword fails (not only selenium keywords)

I'm making automated tests cases with mix of selenium and builtin keywords in Robot Framework.
I have made the:
Register Keyword To Run On Failure Screenshot On Failure
which overwrites the default behavior to create selenium-screenshot-index.png (I needed other names). Everything works fine if the keyword failing is part of the selenium library. If not (let's say custom or builtin one) the screenshot is not taken.
Is there a way, to register the keyword to run on any failure in any keyword?
Well, depending on your actual goal solution could be quite simple or require a little bit of python programming.
Simple solution. I would say that taking one screenshot in test teardown if test case failed is enough in most of the cases.
Writing custom listener interface that would grab instance of library (Selenium, OS) and depending on keyword status would take action.

Execution order of test cases in Cucumber

Below is the structure how my Feature Files are divide. I have created Folders based on the functionalities and then added the scenarios inside them.
Now, I have to tag few test cases among them as Smoke Test cases and get them executed.
The point here is I need a specific order for that as in eg
Add Asset
Run Test
Schedule Test
Delete Asset
Since I will add something first and then work on it and delete it at the end
I know by default Cucumber executes test cases alphabetically but that would not solve my problem.
How can I achieve that?
I am using Java
Cucumber features/scenarios are run in Alphabetical order by feature file name.
However, if you specifically specify features, they should be run in the order as declared. For example:
#Cucumber.Options(features={"automatedTestingServices.feature", "smoketest.feature"})
You can achieve by setting priority or dependency, supported in QAF which is TestNg implementation for BDD. Setting priority with scenarion should do the needful for example:
with QAF scenario in DeleteAssets.feature may look like below:
#priority:100
#or you can set dependencies like below
##dependsOnGroups:['create','schedule']
#delete #otherGroup
Scenario: Delete existing Asset
Given ...
Note: gherkin syntax doesn't supports meta-data so you need to use either qaf bdd or bdd2 syntax and appropriate factory to run tests.
Yes, you can set a priority in cucumber scenarios. but not for the whole scenarios we can do that. inside methods we have declared in step definition file, can achieve that. Just put a keyword "Order" in the step definition file over the method based on the order of the method it will run as priority.
Click here for reference

Using Selenium commands within a command?

I'm using Selenium IDE and would like to know if it is possible to use a Selenium command, within a Selenium command.
For example to use verifyElementPresent('someelement') within a storeEval command to store true/false.
I know this could be using JS, but using Selenium IDE's built in commands would be very time-saving!
If I understand correct, you want to create Selenium Nested function. The answer is No, it cann't.
For the SeleniumIDE reference, you will see that there are 3 parts of command (command, target, value). it also no function to store the command result, if you see the HTML code when you create the Selenium test script, you will see that it totally seperated the command to three sections.
I cannot find the document that selenium said it doesn't support to create the nested function. However, it will be get more complexity when you going to test something but the test script itself already complex. I would suggest you to store something you needs in user-extension.js, otherwise, done it by test script in your programming language you want.
Selenium have command storeElementPresent(locator, variable)
See http://release.seleniumhq.org/selenium-core/0.8.0/reference.html

Does there exist an established standard for testing command line arguments?

I am developing a command line utility that has a LOT of flags. A typical command looks like this:
mycommand --foo=A --bar=B --jar=C --gnar=D --binks=E
In most cases, a 'success' message is printed but I still want to verify against other sources like an external database to ensure actual success.
I'm starting to create integration tests and I am unsure of the best way to do this. My main concerns are:
There are many many flag combinations, how do I know which combinations to test? If you do the math for the 10+ flags that can be used together...
Is it necessary to test permutations of flags?
How to build a framework capable of automating the tests and then verifying results.
How to keep track of a large number of flags and providing an order so it is easy to tell what combinations have been implemented and what has not.
The thought of manually writing out individual cases and verifying results in a unit-test like format is daunting.
Does anyone know of a pattern that can be used to automate this type of test? Perhaps even software that attempts to solve this problem? How did people working on GNU commandline tools test their software?
I think this is very specific to your application.
First, how do you determine the success of the execution of you application? Is it a result code? Is it something printed to the console?
For question 2, it depends how you parse those flags in your application. Most of the time, order of flags isn't important, but there are cases where it is. I hope you don't need to test for permutations of flags, because it would add a lot of cases to test.
In a general case, you should analyse what is the impact of each flag. It is possible that a flag doesn't interfere with the others, and then it just need to be tested once. This is also the case for flags that are meant to be used alone (--help or --version, for example). You also need to analyse what values you should test for each flag. Usually, you want to try each kind of possible valid value, and each kind of possible invalid values.
I think a simple bash script could be written to perform the tests, or any scripting language, like Python. Using nested loops, you could try, for each flag, possibles values, including tests for invalid values and the case where the flag isn't set. I will produce a multidimensional matrix of results, that should be analysed to see if results are conform to what expected.
When I write apps (in scripting languages), I have a function that parses a command line string. I source the file that I'm developing and unit test that function directly rather than involving the shell.

multiple test cases for selenium RC

How can you create multiple test cases for selenium RC using eclipse?
Evaluate a test framework, such as TestNG or JUnit. Based on these frameworks, you can build data driven tests, or a number of scripts, executed sequentially (or in parallel) using Ant.
You can try implementing a Data Provider into your tests and having the test methods be executed for the different values in it.
For example, you can have a CSV file with the different test parameters for each case and execute "each line".
I would recommend the latest Junit version and the latest Selenium 2 Version.
Those two together make it pretty easy to get going.
TestNG has better support for all test automation requirements. Try it.
Find more on how to do this here http://aboutselenium.blogspot.com/2011/10/building-automation-framework-with-ant.html