Skip to content
Advertisement

How do I stop selenium automation if 20% or 1st 20 test cases test methods are failed?

I have 100 test cases, if 20% or first 20 test cases all fail how can I stop the execution ? Already have testng ITestResult where should I break the build?

JavaScript

Where can I break this suite if Result, “FAIL is over 20 ? DO i require to create new class or can I add in same below?

JavaScript

Advertisement

Answer

You can implement ISuiteListener and in onFinish method you’ll have access to ISuite and ISuiteResult

Then you can do

JavaScript

size() will give you number of failed test for that suite. Once you know that number you can implement to stop execution using strategies in this

If your test cases are in different suites then in each call to onFinish method you can count number of failed test cases per suite and based on that stop execution.

One other alternative is to implement ITestListener . In onTestFailure method you have access to ITestResult

You can count how many times onTestFailure method is called and based on that stop execution. I think implementing ITestListener is more suitable and easy in your case.

Here , I edited to explain how you’d implement listener

JavaScript

You can read more about testng listeners here .

For your EDIT above (if you want to go that way). Though I still think you should implement listener, which is more cleaner. It will be called only when the test fails.

But do the same thing as I did in onTestFailure method , add a counter and increase it in else if .

JavaScript

then in your method

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement