I have to add a specific condition in my test case
Ex. There are two products prod1 and prod2
There are many test cases in a project, few test cases are applicable to both the products and few are specific to the product.
In one of my test case I need to add below condition
If producttype==prod1
Skip all the test cases in the particular file
if producttyppe==prod2
Execute all the test cases in the test suite
Is there any other way, other than tags.
Since there are 1000s of test cases and some test cases needs to be executed to the specific product and some test cases works fine for both product
As @HelioGuilherme66 suggested using tags is the best option (it’s what tags are for)
Simply add a tag prod1 to all the tests that apply to prod1 and likewise prod2 to tests that apply to prod2
Tests that only apply to prod1 will only have a prod1 tag
Tests that only apply to prod2 will only have a prod2 tag
Tests that only apply to both prod1 and prod2 will have both prod1 and prod2 tags
I understand it’ll take a while to add the tags to all your existing test cases so i’ll also suggest you consider future proofing the task a little and and take note of the current version of both products and the version number as part of the product tag so that as you go forward you can select test cases specific to a version you are testing as I demonstrated in this post
If you really don’t want to use tags (I don’t really understand why?) I guess you could do it by Simple pattern matching on the test names, the robot files or the folder the tests are stored in. Here’s some examples:
test names - prefix (suffix?) the test name with P1 for prod1, P2 for prod2 and P1P2 for tests that apply to both prod1 and prod2, then run test with --test *P1* or --test *P2*
robot file - place all the tests that are specific to prod1 in prod1.robot, likewise tests that are specific to prod2 in prod2.robot and finally tests that apply to both in prod1_and_prod2.robot, then you run the test as robot *prod1*.robot or robot *prod2*.robot
folder - similar to with file name, you can use a prod1 folder for the tests that are specific to prod1, prod2 folder for the tests that are specific to prod2 and prod1_and_prod2 folder for the tests that apply to both, then you run the test as robot *prod1*/*.robot or robot *prod2*/*.robot
Another option if you really want to control which app the test runs for with the if statement you could use the following: