I use Ruby with Selenium to do test automation on a web application that has a MySQL DB behind it. I need a good way to load data into the DB from a Ruby script. So far in my research I have found using an export of the DB tables in CSV files and then loading the files back into the DB before running a test that requires the data. To connect to the DB I have found the gems mysql2 and net/ssh/gateway.

Does this approach make sense or is there a better way?

1 Answer 1


That sounds basically right. The only change I might make is instead of loading up to a CSV, you can just take a mysqldump and load the DB from the dump at the beginning of the script.

  • What's the advantage of your approach in comparison to the approach in question?
    – dzieciou
    Commented Nov 15, 2012 at 7:45
  • As far as the machine is concerned, I don't think much. That's the reason I used 'might'. I think this is a good thread to read some opinions - stackoverflow.com/questions/467452/… Commented Nov 15, 2012 at 18:10
  • Actually just remembered the reason I wrote that - in a case where you want to start with a clean database, you can have a script delete all tables from the DB and then use the mysqldump to create the schema and insert the data. Commented Nov 15, 2012 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.