# Selenium - tips for avoiding a hundred fixture files

**URL:** <https://www.ruby-forum.com/t/selenium-tips-for-avoiding-a-hundred-fixture-files/167873>\
**Category:** Rails\
**Created:** [May 13, 2009, 3:23pm UTC](https://www.ruby-forum.com/t/selenium-tips-for-avoiding-a-hundred-fixture-files/167873 "2009-05-13T15:23:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [May 13, 2009, 3:23pm UTC](https://www.ruby-forum.com/t/selenium-tips-for-avoiding-a-hundred-fixture-files/167873/1 "2009-05-13T15:23:24Z")

</div>

I’ve just started using Selenium with Rspec and it’s working well so  
far. However, i’m testing it against my local development version of  
the site (ie running in mongrel). What i really need to do is run it in  
a test environment, so i can do destructive actions repeatedly.

Using fixtures seems like one obvious way to go - since it’s a form of  
integration testing i don’t want to start mocking and stubbing things,  
that’s just going to cause more confusion and problems than it solves.  
So, i could fixture everything up the wazoo.

The problem is, though, that we have a big site with loads of different  
tables, and lots of different interrelated models. Setting up all the  
fixtures is going to be a pain in the ass. So, i thought of a few ways  
to go:

1. Make a stripped down version of our db, by basically deleting lots of  
records and all their associations out. Then

a) Generate fixtures, or some data (maybe even just an sql file) that  
is loaded into the db before every test. This is going to be very slow  
as the data will be reloaded _a lot_.

b) Run every test (or group of tests) in a transaction, so the changes  
are always undone after every test. This should be a lot quicker than  
1a.

1. Generate a lot of fixtures somehow using some kind of system that  
basically makes it easier to have a lot of associated models.

2. Something else i’m too ignorant to think of.

Does anyone have any advice/guidance/urls/etc regarding this?

thanks  
max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [May 13, 2009, 4:18pm UTC](https://www.ruby-forum.com/t/selenium-tips-for-avoiding-a-hundred-fixture-files/167873/2 "2009-05-13T16:18:51Z")

</div>

Max W. wrote:

> I’ve just started using Selenium with Rspec and it’s working well so  
> far. However, i’m testing it against my local development version of  
> the site (ie running in mongrel). What i really need to do is run it in  
> a test environment, so i can do destructive actions repeatedly.

Investigate Webrat (and ots Selenium bindings if you need them).  
Cucumber may also be nice here.

> Using fixtures seems like one obvious way to go

The obvious is not always the best. 🙂

[…]

> a) Generate fixtures, or some data (maybe even just an sql file) that  
> is loaded into the db before every test. This is going to be very slow  
> as the data will be reloaded _a lot_.

Remember, Rspec already clears the test database before each test.

What you have here is a good use case for factories, I think. Install  
Machinist or Factory Girl and just tell it what you need for each  
particular test. It will take care of the dependencies.  
[…]

> 1. Generate a lot of fixtures somehow using some kind of system that  
> basically makes it easier to have a lot of associated models.

This is sort of what factories do. There’s a Railscast on the subject.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [May 13, 2009, 4:27pm UTC](https://www.ruby-forum.com/t/selenium-tips-for-avoiding-a-hundred-fixture-files/167873/3 "2009-05-13T16:27:30Z")

</div>

On May 13, 9:18 am, Marnen Laibow-Koser \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> Remember, Rspec already clears the test database before each test.
> 
> What you have here is a good use case for factories, I think. Install  
> Machinist or Factory Girl and just tell it what you need for each  
> particular test. It will take care of the dependencies.  
> […]
> 
> > 1. Generate a lot of fixtures somehow using some kind of system that  
> > basically makes it easier to have a lot of associated models.
> 
> This is sort of what factories do. There’s a Railscast on the subject.

Check out this Railscast that uses two gems populator and faker to  
create a rake that loads a database with fake data:

> **[\#126 Populating a Database - RailsCasts](http://railscasts.com/episodes/126-populating-a-database)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [May 14, 2009, 1:35pm UTC](https://www.ruby-forum.com/t/selenium-tips-for-avoiding-a-hundred-fixture-files/167873/4 "2009-05-14T13:35:11Z")

</div>

That looks really useful as well, thanks WJ!

cheers  
max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [May 13, 2009, 4:37pm UTC](https://www.ruby-forum.com/t/selenium-tips-for-avoiding-a-hundred-fixture-files/167873/5 "2009-05-13T16:37:18Z")

</div>

Thanks a lot Marnen.

Someone else has recommended machinist to me, and it gets a mention in  
the screencast too. I’ll check it out.

Can you think of anything i need to bear in mind when doing integration  
testing (well, acceptance testing really since it’s simulating a user)  
like selenium?

for example, are there any things that i should still mock out? or is  
it best to create a ton of real objects of every kind using the factory?
