!!

Welcome to Selenium Webdriver Forum

As a web user you can read and search through forum content. Once you have registered and signed you can post topics, post replies, set up watch lists, modify forum settings, and use private messaging.

Author Topic: NUnit crash problem when used with Selenium Webdriver in Visual Studio 2010 [C#]  (Read 813 times)

nhatekar

  • Selenium User
  • *
  • Posts: 2
Hi,

I am using Selenium Webdriver with NUnit to test a web application. I have set-up a class library project, and I am loading the .dll into NUnit to run the tests.

This setup is working fine, when I build the solution in VS, then load the DLL in NUnit, and click RUN test cases.

The problem starts when I go back to VS, makes some changes and build the solution again. [Which creates a new .DLL]. As soon as this is done, and I go back to Nunit, it stops working and crashes. I have re-open NUnit, load the solution DLL again and then the tests run fine.

I know that I am missing a simple thing somewhere, but I can't find what. I would appreciate if someone could help me with this.

SeleniumWebdriver Admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 927
Hi,

   Here is a sample code I have used and it works with Nunit.


Code: [Select]
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;

namespace SeleniumTests
{
    [TestFixture]
    public class Untitled
    {
        private IWebDriver driver;
        private StringBuilder verificationErrors;
        private string baseURL;

        [SetUp]
        public void SetupTest()
        {
            driver = new FirefoxDriver();
            baseURL = "http://www.google.com.au/";
            verificationErrors = new StringBuilder();
        }

        [TearDown]
        public void TeardownTest()
        {
            try
            {
                driver.Quit();
            }
            catch (Exception)
            {
                // Ignore errors if unable to close the browser
            }
            Assert.AreEqual("", verificationErrors.ToString());
        }

        [Test]
        public void TheUntitledTest()
        {
            driver.Navigate().GoToUrl(baseURL + "/");
            driver.FindElement(By.Name("q")).Clear();
            driver.FindElement(By.Name("q")).SendKeys("google webdriver");
            Thread.Sleep(10000);
            driver.PageSource.Contains("Google Webdriver");           
        }
        private bool IsElementPresent(By by)
        {
            try
            {
                driver.FindElement(by);
                return true;
            }
            catch (NoSuchElementException)
            {
                return false;
            }
        }
    }
}

Also see the screen shot to integrate nunit for debugging just in-case you have missed.

I would also suggest you have a look at this solution http://www.seleniumwiki.com/visual-studio-2010/selenium-2-webdriver-example-using-visual-studio-test-project/

Instead of creating  a class library you will create a test project. Check the screen shot.

Let me know if you have any issues. All the best.

nhatekar

  • Selenium User
  • *
  • Posts: 2
Thank you for your help. The problem with NUnit crash is resolved now. The problem was with NUnit settings for Assembly Isolation.
After selecting the option 'Run Tests in a single separate Process' it worked fine.
It was defaulted to 'Run tests directly in the NUnit process' before.

I will take a look at using the Test project in Visual studio to run the tests. I have never done it before, so I am a little skeptical.

I will get back to you with any further questions I might have.

thank you again for your help.

Selenium Webdriver


 

Related Topics

  Subject / Started by Replies Last post
24 Replies
1671 Views
Last post February 23, 2012, 07:08:59 PM
by Thiago Morais
2 Replies
550 Views
Last post February 23, 2012, 07:25:57 PM
by Athira Kannarambil
3 Replies
630 Views
Last post February 23, 2012, 08:54:01 PM
by Michael
1 Replies
490 Views
Last post March 29, 2012, 03:08:00 PM
by Shailesh Jagtap
1 Replies
708 Views
Last post May 03, 2012, 05:54:00 PM
by Krishnan Mahadevan
0 Replies
1416 Views
Last post June 19, 2012, 04:20:44 PM
by SeleniumWebdriver Admin
1 Replies
396 Views
Last post July 24, 2012, 05:57:07 PM
by rolandormrod82

Review www.seleniumwebdriver.com on alexa.com