I have a task from a colleague, and I'm a bit skeptical about it. Essentially, I have a frontend testing framework that uses Cucumber, Java, Selenium, and JUnit.
My colleague is trying to convince me that we can use a database to set up the required test prerequisites. For example, before running these tests, I need a specific state, but it seems implausible to me that a database can execute steps to create this state. I could be wrong because I'm relatively new to automated testing.
Can someone provide me with some advice on whether this is possible or worth pursuing?
Edit: Output of this prerequisite is specific file which needs to be created before next step started.
These sorts of tests are possible, but end up being quite time consuming to create and maintain over time with changes to the application
A few gotchas:
You need to ensure that changes made in one test don't "bleed" into another (eg tests pass when run A,B but fail when run B,A). It's always best to create test records during test setup rather than mutate existing "shared" records that are used by other tests. Any "shared" records required by multiple tests (eg clients/accounts etc) should remain static/immutable.
It's quite likely you won't be able to use a database transaction and rollback in this scenario since the UI and the test harness (cucumber) will have their own database connections
If making changes directly on the db (eg via JDBC) you need to be sure to drop any caches the UI might have (browser cache / serverside cache). Perhaps a test only rest endpoint where you POST a json for the test data would be better than direct JDBC in cucumber?
Selenium testing can be hard to get right. Be sure to give any controls (text fields, buttons etc) html ID's so you can select by id. Relying on selectors such as /div[2]/div[3]/button[4]
makes your tests fragile as they will break with simple UI changes in the future.
This type of testing can be quite flakey for various reasons. You might find these tests are failing for days/weeks at a time because none of your teammates have time to fix some silly selenium/javascript wait condition which isn't working as expected
You might find the cost of maintaining these sorts of tests are not worth the hassle. Perhaps a handful of "hello world" tests of your UI (eg simple assertion for each page that it loads and shows some data) will give you some sanity tests that aren't too expensive to maintain