Running Selenium Web-Driver tests using TestNG - Browser is not killed upon failed tests

88 views
Skip to first unread message

Lior Kinsbruner

unread,
Jul 9, 2015, 12:34:41 PM7/9/15
to testng...@googlegroups.com
Hey,
I am running an entire class of testNG tests which invoke a browser upon each instance of a test method. Browser is closed when tests pass but when they fail browser remains invoke ALTHOUGH I added an @AfterTest method to check if browser is not null to kill it...

I am using AssertJunit(exp,actual) for verifying test pass/fail criteria...

Should I wrap the assertion with try-catch-finally??

Thanks,
Lior

--
Lior Kinsbruner
Email: lior...@gmail.com
Phone: +972-54-7990307

Krishnan Mahadevan

unread,
Jul 10, 2015, 2:10:16 AM7/10/15
to testng...@googlegroups.com
The @AfterXXX configuration methods would be called irrespective of whether the test methods run properly or not.
Here's a sample for the same

import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;

public class ConfigurationSample {
@Test
public void testMethod() {
Assert.assertTrue(false);
}

@AfterTest
public void afterTest() {
Reporter.log("afterTest() was called", true);
}
}

Output :
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.test.testng.ConfigurationSample
Configuring TestNG with: TestNG652Configurator
afterTest() was called
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.254 sec <<< FAILURE! - in com.test.testng.ConfigurationSample
testMethod(com.test.testng.ConfigurationSample)  Time elapsed: 0.011 sec  <<< FAILURE!
java.lang.AssertionError: expected [true] but found [false]
        at org.testng.Assert.fail(Assert.java:94)
        at org.testng.Assert.failNotEquals(Assert.java:494)
        at org.testng.Assert.assertTrue(Assert.java:42)
        at org.testng.Assert.assertTrue(Assert.java:52)
        at com.test.testng.ConfigurationSample.testMethod(ConfigurationSample.java:11)




Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

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

Reply all
Reply to author
Forward
0 new messages