How to skip test cases execution in test suite

6,902 views
Skip to first unread message

techi...@gmail.com

unread,
Oct 6, 2014, 12:21:07 PM10/6/14
to robotframe...@googlegroups.com
Hello All,

I have a test suite with 4 test cases , is there anyway if 1_test_case failed to skip rest of the test cases ( 2 , 3, 4)  in test suite.

1_test_case
2_test_case
3_test_case
4_test_case

Appreciate your inputs.

thanks

Bryan Oakley

unread,
Oct 6, 2014, 1:08:20 PM10/6/14
to techi...@gmail.com, robotframework-users
No, once a suite has started, all test cases will be run based on the command line arguments. You can't skip test cases at runtime. 

What you can do instead is set up dependencies between tests which will cause a test to fail (or pass) immediately if some other test fails, without executing any additional keywords. I've explained  how to do this in the following stackoverflow answer: http://stackoverflow.com/a/25079032/7432


--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Tatu Aalto

unread,
Oct 6, 2014, 1:29:05 PM10/6/14
to oak...@bardo.clearlight.com, techi...@gmail.com, robotframework-users
Ugh

What a nice solution, have remember that.

-Taty

techi...@gmail.com

unread,
Oct 7, 2014, 3:33:07 PM10/7/14
to robotframe...@googlegroups.com, oak...@bardo.clearlight.com, techi...@gmail.com
Thanks for your inputs. I am using Robot frame work 2.8.1 java based version.   TestListener is listener class where i have   public void endTest( String name, Map attributes ) throws IOException, ScriptException  method define. How can i do this in java ?  I want to drive dependency based on flag from properties file.  

if flag is on it will consider dependency otherwise ignore .



<java classname="org.robotframework.RobotFramework" classpathref="runtime.classpath"
fork="true" maxmemory="1024M">
<arg value="--outputdir"/>
<arg value="../output/${suite.name}"/>
<arg value="--variable"/>
<arg value="TEST_ENV:${env.file}"/>
<arg value="--variable"/>
<arg value="RAND:${rand}"/>
<arg value="--variable"/>
<arg value="DATA_SET:${data.set}"/>
<arg value="--listener"/>
<arg value="TestListener"/>
<arg value="--runfailed"/>
<arg value="../output-${run.time}/${suite.name}/output.xml"/>
<arg value="@{testsuite}"/>
</java>












On Monday, October 6, 2014 1:29:05 PM UTC-4, Tatu Aalto wrote:
Ugh

What a nice solution, have remember that.

-Taty
On 6.10.2014 20:08, Bryan Oakley wrote:
No, once a suite has started, all test cases will be run based on the command line arguments. You can't skip test cases at runtime. 

What you can do instead is set up dependencies between tests which will cause a test to fail (or pass) immediately if some other test fails, without executing any additional keywords. I've explained  how to do this in the following stackoverflow answer: http://stackoverflow.com/a/25079032/7432

On Mon, Oct 6, 2014 at 11:21 AM, <techi...@gmail.com> wrote:
Hello All,

I have a test suite with 4 test cases , is there anyway if 1_test_case failed to skip rest of the test cases ( 2 , 3, 4)  in test suite.

1_test_case
2_test_case
3_test_case
4_test_case

Appreciate your inputs.

thanks
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

techi...@gmail.com

unread,
Oct 14, 2014, 5:08:11 PM10/14/14
to robotframe...@googlegroups.com
Hello All,


I see following listener class methods in RF 

After every test case completion endTest method will be called. Here i want to check the status of test case if it in failed status i want to stop the execution of remaining test case in test suite, how can i do that.

Appreciate your valuable inputs.




public interface RobotListenerInterface {
public static final int ROBOT_LISTENER_API_VERSION = 2;
void startSuite(String name, java.util.Map attributes);
void endSuite(String name, java.util.Map attributes);
void startTest(String name, java.util.Map attributes);
void endTest(String name, java.util.Map attributes);
void startKeyword(String name, java.util.Map attributes);
void endKeyword(String name, java.util.Map attributes);
void logMessage(java.util.Map message);
void message(java.util.Map message);
void outputFile(String path);
void logFile(String path);
void reportFile(String path);
void summaryFile(String path);
void debugFile(String path);
void close() throws IOException;
}

Bryan Oakley

unread,
Oct 14, 2014, 5:21:38 PM10/14/14
to techi...@gmail.com, robotframework-users
You can't. Once a test execution has started, you can't cause any of the tests to be skipped. You can't do it from keywords and you can't do it from listeners. It's unfortunate, because if you could do it from a listener it would be pretty easy to write an interactive debugger.  As I wrote in my earlier message, you can write a keyword that checks the status and causes a test to pass or fail, but you can't cause it or any other test to be skipped. 

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.

techi...@gmail.com

unread,
Oct 14, 2014, 6:06:48 PM10/14/14
to robotframe...@googlegroups.com
Got you,

Is there any forceful way of calling suite teardown if one test case failed to achieve this , just my thought.





On Monday, October 6, 2014 12:21:07 PM UTC-4, techi...@gmail.com wrote:

Jerry Schneider

unread,
Oct 14, 2014, 6:16:10 PM10/14/14
to robotframe...@googlegroups.com
An ugly way might be to have a teardown that creates a file with FAILED in it and all other testsuites have a setup keyword to check what is in contents of file.  If not contain PASS then FAIL suite for setup failure

jer
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

-- 
Linux registered user #475536
Ubuntu registered user #28583

techi...@gmail.com

unread,
Oct 14, 2014, 7:20:35 PM10/14/14
to robotframe...@googlegroups.com

Before start of each test case  startTest method attributes will populate with PREV_TEST_STATUS, PREV_TEST_NAME values , i was able to capture  PREV_TEST_STATUS but how can i stop the test case execution in startTest method?

startTest(String name, java.util.Map attributes);



On Monday, October 6, 2014 12:21:07 PM UTC-4, techi...@gmail.com wrote:

techi...@gmail.com

unread,
Oct 14, 2014, 10:17:21 PM10/14/14
to robotframe...@googlegroups.com
I had done the below code change , but it is not stopping the current test case, any guess?


 public void startTest( String name, Map attributes ) throws IOException, ScriptException
 {
 if(PREV_TEST_STATUS.equals("FAIL")){
 
 PythonInterpreter interp = new PythonInterpreter();
interp.exec("from robot.libraries.BuiltIn import BuiltIn");
interp.exec("BuiltIn().fatal_error(\"PREV_TEST_STATUS failed:\")"); //If previous test case failed fail the current test case
 
 }
 
 }





On Monday, October 6, 2014 12:21:07 PM UTC-4, techi...@gmail.com wrote:

techi...@gmail.com

unread,
Oct 15, 2014, 10:53:09 AM10/15/14
to robotframe...@googlegroups.com
Team , Any inputs/suggestions  please


On Monday, October 6, 2014 12:21:07 PM UTC-4, techi...@gmail.com wrote:

Kevin O.

unread,
Oct 15, 2014, 12:29:11 PM10/15/14
to robotframe...@googlegroups.com
Listeners are for listening, and you a trying to alter the test execution.
Your code could easily be re-written in a user keyword that is set as the test setup. You can set the default setup so that every test in the suite uses the setup.

Kevin O.

unread,
Oct 15, 2014, 2:07:50 PM10/15/14
to robotframe...@googlegroups.com
That sounded kind of rude.
Fatal Error works by raising and exception, so it causes your listener to raise an exception, which RF will log, but it will not effect the test. The Fail keyword works the same way.

techi...@gmail.com

unread,
Oct 15, 2014, 5:38:13 PM10/15/14
to robotframe...@googlegroups.com
Thanks Kevin for your valuable inputs.

Your code could easily be re-written in a user keyword that is set as the test setup. You can set the default setup so that every test in the suite uses the setup.

How can i do  test setup ? how does that test set up knows previous test result?  Can you give some pointer, i will try to implement it





On Monday, October 6, 2014 12:21:07 PM UTC-4, techi...@gmail.com wrote:

Bryan Oakley

unread,
Oct 15, 2014, 6:01:06 PM10/15/14
to techi...@gmail.com, robotframework-users
Early in this thread I gave an example of a keyword library that does almost exactly this. That code requires that you say what test you are dependent on, but it could easily be modified to remember only the most recent test case status (though explicitly saying which test case you depend on seems more robust).


--

Kevin O.

unread,
Oct 15, 2014, 9:12:56 PM10/15/14
to robotframe...@googlegroups.com
Using a library as a listener like Bryan linked is very powerful. Keep in mind it requires RF >= 2.8.5.
*** Settings ***
Test Setup        Fail If Previous Test Failed

*** Test Cases ***
Test 1
    Fail    this test failed

Test 2
    Log    hello world

*** Keywords ***
Fail If Previous Test Failed
    Run Keyword If    '${PREV_TEST_STATUS}'=='FAIL'    Fail    Skipping test because '${PREV_TEST_NAME}' failed.

Starting test: Fail.Test 1
20141015 20:06:49.635 :  FAIL : this test failed
Ending test:   Fail.Test 1

Starting test: Fail.Test 2
20141015 20:06:49.640 :  FAIL : Skipping test because 'Test 1' failedd.
Ending test:   Fail.Test 2

Reply all
Reply to author
Forward
0 new messages