When creating a negative automation test script, should this be separated from my positive script, or can I also include the negative scenario in my script. I am using protractor for this. Thanks
In my opinion you should not mix positive and negative paths because every test has to be independent and give a clear result.
Suppose that you create 100 scripts both positive and negative and all tests with negative paths fail, in theory you'll never know if they would fail even with positive ones until you fix your code. My suggestion is having a reasonable granularity of the test suite but focus mainly on maintenability of the suite itself e.g. balancing the amount of automated and manual tests.
The trade-off is between script length and diagnostic value:
- Script length: one script with everything in it may be shorter (and should never be longer) than a positive script plus a negative script, because multiple scripts will duplicate setup steps. Because it has fewer steps, the everything script will probably be faster to execute than multiple scripts.
- Diagnostic value: diagnosing bugs is a narrowing-down process; you try different variations on a test until you find the shortest possible variation that reproduces the bug. The script with everything is probably not the shortest possible variation, and so it has less diagnostic value than the positive-only or negative-only script.
None of us can tell you how to make that trade-off. If you have lots of developers and only one tester, you may choose to optimize for script length. If you have enough testers, and it tends to take a long time for a developer to narrow down a bug to its cause, you may choose to optimize for diagnostic value.
Most likely, you have both problems, i.e. not enough testers and too long to narrow down the bugs, and so you will have to make the trade-off using your own judgement.