I have to extend/fix a large online form written by other developer. There is a lot of code, mixing PHP and JS. It's kind of write-only style of coding and I want to redo it completely, but currently I can't.
It works like this:
- It is a wizard-style form with 12 steps - let's call them phases to not confuse with steps of the tests.
- User has to fill at least ~100 fields to finish.
- Some fields are grouped by 3-5. Those groups can be dynamically added and removed with JS.
- Validation is done after submitting each phase. If some errors occured, user is notified immediately and cannot go further until he/she fixes all errors.
- Submitted data is temporarily stored in the session between phases. No permanent storage.
- User cannot skip phases, only sequentially go back and forth to already completed phases.
It is ridiculous to test this thing manually, so I wrote a test using Behat with Mink and Selenium2.
I have only 1 test now, which completes all 12 phases of the form. To go to specific point in the process of filling the form, I created a step definition wich just makes webdriver wait 1 hour (laugh at me). When I need to test some specific phase, I just add this step where I want Selenium to stop - this leaves browser window open so I can do whatever I want manually without having to fill all previous fields.
It saves a ton of time, but feels stupid. I have reasons to do that:
- Has to be done ASAP.
- I cannot test each separate step in the form.
- I cannot reuse parts of the filling process without having to write quite a lot of PHP code. Now my test is just ~120 lines written in Gherkin language.
Simplified version of my question is: how should I test this?
I can think of several ways:
- Modify the code to allow skipping phases. This can be done safely by detecting environment parameters withing the application and deciding whether client (webdriver or user) can or cannot skip phases, so skipping is not allowed in a production environment.
- Just write more tests with a lot of copy-pasting and be a bigger monkey.
Write step definitions to complete specific phases separately. So, I could just write
When I complete phase 1 And complete phase 2 And complete phase 3 ...
in the tests.
So, the full version of my question is: which way is preferable and what (dis)advantages each way has? Maybe there are other ways, like designing an application in a completely different way so there are no such problems.