Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can TransactionScope rollback be used with Selenium or Watin?

I am trying to do some automated web testing of my ASP.NET application. I was hoping to use the AutoRollback attribute from Xunit.net extensions to undo any database changes that were made during the test. AutoRollback uses TransactionScope to start a transaction before the test and roll it back afterwards.

When I try to hit my web application during a transaction, it always times out. It seems like this should work, any ideas? Here is my test:

[Fact]
[AutoRollback]
public void Entity_should_be_in_list()
{
    Entity e = new Entity
    {
        Name = "Test",
    };
    dataContext.Entities.InsertOnSubmit(e);
    dataContext.SubmitChanges();

    selenium.Open("http://localhost/MyApp");
    Assert.True(selenium.IsTextPresent("Test"));
}
like image 596
Robin Clowers Avatar asked Jun 16 '09 22:06

Robin Clowers


1 Answers

Your ASP.NET application has a separate database context and it has no idea that you want it to join transaction started by Xunit.net. Apparently, the database locks some resources when transaction starts; web application waits patiently for some time and eventually gives up.

I think your best bet is to start from empty database and use SQL script to create schema and populate lookup tables (your database is under source control, right?). Another approach is to backup database before running the tests and then restore it once they finish.

like image 123
Pavel Chuchuva Avatar answered Sep 24 '22 15:09

Pavel Chuchuva