Well I think you should take a step back and learn C# and unit testing first. This will give you the background you need to understand how it fits together.
So currently you are recording the steps in the IDE and exporting them. This is a good idea to get things up and running but in the long term it is doomed for failure! You are absolutely right, in that coding these tests should be done manually, using the native C# WebDriver API. Why? Not everything can be converted directly from the IDE to the C# API, more 'advanced' things will need to be done using the C# API anyway and the code the IDE spits out isn't great, you need to use your own logic and structure to have reliable, logical, readible and extensible tests that can be used for the future!
As for NUnit in particular, it is commonly used for unit testing. Very very briefly, unit testing is testing a particular class in complete isolation. So let's say I have an AdvertGenerator and it's purpose is to give me adverts (added in the database) that can be displayed on my website, but it is also supposed to allow me to give each 'advert' a weight.
For instance, if I have an advert with a higher "weight" than another, the AdvertGenerator should be more likely to give me that advert to display on the website, or at least it should be return that one more often!.
So I put this functionality into my website and it works, great. How do I tell it will always work and that if I break it, how will I know at the earliest notice? Unit testing.
Using something like NUnit, I can set up a test whereby I give the AdvertGenerator a few random dummy adverts that I create in memory, give them each a different 'weight' and then ensure it returns the correct ones, in order. That is unit testing. I'm giving my class a particular set of scenarios, and I'm asking it to do some work with them, then I'm checking what happened. I'm verifying my functionality is still working. So let's say I break it, I don't know how, but I change something. my unit tests will tell me it's broken. You can then combine these tests with a continuous integration solution, and have them run every night so that you can a constant reminder of what is working in your system.
NUnit comes to play with Selenium for mainly the reason it can be used to run tests. You don't have to use NUnit, you can use XUnit, MSTest (built into Visual Studio). It is mainly because NUnit is free and very very extensible. For instance what if you wanted to have a custom attribute to allows you to 'ignore' certain tests for certain browsers. I have no idea on earth how you'd achieve this with MSTest, but with NUnit, it will allow you to hook into each individual test run and allow you to manipulate it on the fly. So you can have this custom attribute, have it check on each run what browser is being run, if it's one in the 'ignore list' for that test, you can ignore that test programatically.
NUnit is also very good to allow you to hook into other continuous integration solutions, like I talked about earlier. So you've already seen you can have unit tests run every night to verify the underlying logic to your website is working, what about having tests to verify your UI on your website is also working OK? For instance I can verify that my advert is returned by my AdvertGenerator in the order I expect, but how can I verify the actual advert is shown on the page? That is where Selenium comes in, I can create a test for that, use NUnit to run it, use TeamCity or Jenkins (Continuous Integration software) and have it run every night. That is every night, I'm checking both my logic and my UI are working!
In terms of your proxy problem, you'll need get a little down and dirty with the C# API. This is where the IDE falls behind, you'll have to do this manually in code.
The code for it would be something like (you'll need to look into the documentation for the 'Proxy' class to set your correct settings, I just set some test data below):
var proxySettings = new Proxy { HttpProxy = "test" };
var firefoxProfile = new FirefoxProfile();
firefoxProfile.SetProxyPreferences(proxySettings);
var driver = new FirefoxDriver(firefoxProfile);
Below are the docs to the C# API for Selenium, read it, use it :)
On Wednesday, 13 March 2013 09:42:08 UTC, Tarun Gupta wrote:
Thanks for your reply. I have followed all your steps but right now I am not able to run the test because whenever the test launches a new Firefox window, its proxy settings are are changed and because of that it is not able to open the website. Is there a way to pause the test so that I can change the settings?
Also I have two more questions:
1. In this example we recorded the test using Selenium's IDE and then exported it into C# code. Do we usually create scripts this way or do we write tests in C# itself.
2. NUnit is still not clear to me. Can anyone explain why we need NUnit, we can directly run the tests using Selenium's IDE also?