How to run one test case if another specifically fails - automation

my problem is that I made two test cases which are perfectly fine and working nicely, however I need to run second one only if first one fails. How can I do that? I'm using RIDE Robotframework and working on IE, because of legacy app.

What you can do is make tests:
Test A passes.
Test A fails.
Test A fails and runs test B.
However I'd prefer you wouldn't do that. Usually tests should be logically separate. If you could you would run all of them on parallel.
If a test fails you shouldn't be concerned with testing other stuff at that point. You should fix the first test. Otherwise you will go in a rabbit hole of tests.

You can't do what you want. At least, not directly. Robot provides no way to add additional tests after the tests have started running.
However, if instead of "run second one" you say "run a special keyword", you can move the functionality to a keyword and call it in a test teardown using Run keyword if test failed
*** Keywords ***
On test teardown
run keyword if test failed
... log BUMMER! WARN
*** Test Cases ***
Passing test
[Teardown] On test teardown
log hello, world
Failing test
[Teardown] On test teardown
fail this test has failed.

You could use Pass Execution If keyword with suite variables. This is not perfect solution because Test B is still logged as passed.
*** Test Cases ***
Test A
Set Suite Variable ${a_passed} ${FALSE}
Fail This case failed
Set Suite Variable ${a_passed} ${TRUE}
Test B
Pass Execution If ${a_passed} A passed so skipping B
Log To Console Running Test B

Related

็Exit the test in Robot Framework

I want to exit test in the test case. And do not want the report to show the number of test cases (TC003) that exit test In the example below,
*** test cases ***
TC001
Run Keyword If '1'=='1' Log To Console xx
TC002
Run Keyword If '2'=='2' Log To Console xx
TC003
Run Keyword If '3'!='3' Exit Test
How do I use it? You can guide me
I don't think there's anything you can do. Once the test starts running, there's no way to remove it from the reports and logs.
It sounds like you're trying to skip a test under certain circumstances. If so, it will be able to mark a test as skipped (versus pass/fail) in robot framework 4.0, though it will still show up in the logs and reports.
If you really don't want it in the reports, you can write a script that removes the tests from the output.xml file and then regenerates the html logs and reports using rebot.

How to Skip the passed test cases in Cucumber-QAF setup

I have a project where I am running 100 scenarios every day. After the run has complete, through listeners I am updating the pass/fail in an Excel sheet. I want to hear about a solution where, if I am running the test suite again, the passed test cases should be skipped and only failed test cases should run. I dont want to use retry.I tried to use skipException in beforeInvocation listener method but the test case is still executing the passed test case. How can I skip the passed test cases and execute only the failed one through listeners ?
Every time before the start of the scenario, it should go to the listener and check the excel sheet whether the scenario is passed or fail. If passed then the scenario should be skipped.
Any help will be greatly appreciated.
Update: I am able to do it through listeners, with skipException, but in my report it is showing test as failed and not as skipped
When you run bdd tests, qaf generates configuration file with name testng-failed-qas.xml under reports dir. You should use that config file to run only failed scenarios.

How to handle failures in Test Suite in selenium webdriver

Suppose I have 10 test cases in my Test suite and when I execute the Test suite I get an error for test case no.7.
Now is there any way that I can restart my execution from test case no.7 after correcting the changes?
I'm using TestNG.
Do we have recovery scenarios in Selenium?
TestNG generates .xml configuration with failed tests http://testng.org/doc/documentation-main.html#rerunning
Or you can use org.testng.IRetryAnalyzer which runs failed tests again and you have more control over it.
Example here http://seleniumeasy.com/testng-tutorials/execute-only-failed-test-cases-using-iretryanalyzer.
Yes you can do that if you are using Eclipse IDE. Click on the arrow just before test class name, it will show you all the methods(test cases) of that test class. Right click on the one which you want to run. It will run that specific test only.

Fitnesse: How to stop one test run when executing a suite

I am using Fitnesse 20130530 to execute a test suite that contains multiple tests. Most of my tests use script tables with SLIM to drive Selenium. I use a Stop Test Exception to stop the execution of a test when one of the method calls raises an exception. Unfortunately, this also stops the execution of the whole suite. Is there a way to just stop the current test and then continue execution with the next test in the suite?
Not in FitNesse itself, but you can build it into your fixtures.
When I had a similar problem I was able to solve it using what we called "fail fast" mode. This was a static variable that could be set to true under certain conditions (typically by an element not found exception or similar).
Our main driver was structured such that we could pass through one spot that could check for that value before calling the browserDriver. This would then skip the broswerDriver calls until the test ended.
The next text would clear the flag and start up again.
You would need to manage the whole process, but it can work.

Selenium Test Runner and variables problem

In my selenium test suite (html), I define a first test case to initialize variable called in the next test case.
Sample :
In first script :
store|//div[#id="myfield"]|myvar
In my second script :
type|${myvar}|myvalue
But when I start test runner (from maven), it returns an error telling that ${myvar} is not found
The value contained in the stored var is not used.
Any suggestion ?
Thans a lot
Maybe you could use cookies to store variable?
createCookie is in selenium and to read it you might use javascrpt(getEval)
As far as I know you cannot reference variables declared in a different test when running HTML suites.
What you need is Test and/or Suite "Setup" and "Teardown" functionality.
Test setup and teardown happen before and after each test. Suite setup and teardown only happen once, before and after the suite is run.
As you are using Maven, I assume that your development is in Java, so you could use JUnit
http://www.junit.org/
This has both test and suite setup and teardown:
Test Setup
http://kentbeck.github.com/junit/javadoc/latest/org/junit/Before.html
Test Teardown
http://kentbeck.github.com/junit/javadoc/latest/org/junit/After.html
Suite Setup
http://kentbeck.github.com/junit/javadoc/latest/org/junit/BeforeClass.html
Suite Teardown
http://kentbeck.github.com/junit/javadoc/latest/org/junit/AfterClass.html
I've created separate tests in Selenium IDE and then batched them in a test suite
After that ... when I ran them, the ${variable_name} stored in test 1 works fine in test 2.
Damien
The current version of selenium test runner doesn't pass variables from test to test like the IDE does. There is a javascript work around, check out Nick G's post on http://jira.openqa.org/browse/SEL-605