1

I have Cucumber .feature file with multiple test cases (using "Examples").
In some situation i want to skip few of the test cases and run only few of them.

Note: User should be able to select which test case to skip dynamically
For example, he can decide in first run to skip test case number 1, next time to skip number 2.

Examples: | SERIAL_NO | ID | | 1 | Create-Customer A | | 2 | Create-Customer B | | 3 | Create-Customer C | 

I managed to do that using

Assume.assumeTrue(...) 

The only issue is - code throws Exception, and i want to keep logs clear.

There is any option to avoid print the exception, and just ignore the test case ? or skip it by another solution ?

Thanks

5
  • You can use cucumber tags (Eg. @ignore) and pass this under tags as "~@ignore" in test runner class. So this will execute all the scenarios except having @ignore tags. Commented Sep 6, 2020 at 9:41
  • @DilipMeghwal, \@Ignore tag will help to skip whole scenario no ? i'm talking about skipping specific test case inside the scenario .feature file (under the Examples), also the decision if to skip or not is in runtime (by user selection), i can't just constantly skip the test case. Commented Sep 6, 2020 at 11:55
  • What you are looking for is available with qaf Commented Sep 15, 2020 at 0:08
  • @user861594, It seems like it's good for constant selection of test cases you want to skip, but as i mentioned, i need it dynamic, each time i can skip different test case by user selection Commented Sep 15, 2020 at 6:24
  • @Adir D, you also can specify test data filter at runtime refer this post and the value also can use expression! Commented Sep 15, 2020 at 16:18

2 Answers 2

2

I would split your Examples for each scenario where you want to skip tests and tag with @todo, like so:

 Scenario Outline: [test-scenario-001] Send a new form with request type Given I preload the from using "request" And I select the 'Submit' button Then the response message "hello" is returned Examples: | request | | POST | @todo Examples: | request | | GET | | PUT | | DELETE | 

Then to run the scenario for the 1st Example only, call out the tag not to be run as part of the feature:

-Dcucumber.options="--tags ~@todo" 

To run all Example scenarios, do not use the tag

Sign up to request clarification or add additional context in comments.

2 Comments

I edited my question, maybe it was not clear enough. I need to be able to skip the test cases dynamically, each time different one, by your solution it's good only if same test cases should be skipped every time (if needed).
Works fine. It's strange to resort to a generic grouping mechanism like tags for this purpose (a negated tag in this case: ~), and that there is no standard syntax for skipping things. By the way I named the tag @skip to better explain what it does and to be more generic.
1

Finally I found a simple solution, by using the same method i have mentioned Assert.assume(...), just need to clear the exception stack trace, and re-throw it.

In below code you can see the actual change is just i added the catch block:

try { Assume.assumeTrue("Some Condition..."); } catch (AssumptionViolatedException e) { // clearing stack trace, so it will keep logs clear, just print the name of exception e.setStackTrace(new StackTraceElement[] {}); throw e; } 

Now exception stack trace is not printed to log, so logs kept clean, and i just see this instead:

org.junit.AssumptionViolatedException: got: <false>, expected: is <true>

This is good enough for me.

1 Comment

What you are looking for is available with qaf

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.