We are pleased to supply a lot of information and a dozen of free
hands-on tutorials. All the available tutorials are surrounded with
screenshots and downloadable code samples. This blog is created and will
be maintained by Quontra Solutions. Quontra solutions Trainers have
many years of experience in automated testing. Quontra Solutions is
particularly interested in web technology and new programming languages.
We are always trying to find a way to transfer knowledge to Students
who are interested in the automated testing of software.
A variety of topics will be covered on this blog. Starting with recording tests with Selenium IDE and locating web elements and furthermore the use of design patterns and performance measurement to create a robust testing framework.
Selenium Tutorial using C# and NUnit
In this tutorial we are going to learn how to create your first test script using the language that most commonly used, c#. Since most languages are semantically the same, if you do not use c# it shouldn’t be too difficult to translate the tutorial into your language of choice. You have to download Nunit and at least Visual Studio Express c# edition to complete this tutorial. They are free to download and use.
A variety of topics will be covered on this blog. Starting with recording tests with Selenium IDE and locating web elements and furthermore the use of design patterns and performance measurement to create a robust testing framework.
Selenium Tutorial using C# and NUnit
In this tutorial we are going to learn how to create your first test script using the language that most commonly used, c#. Since most languages are semantically the same, if you do not use c# it shouldn’t be too difficult to translate the tutorial into your language of choice. You have to download Nunit and at least Visual Studio Express c# edition to complete this tutorial. They are free to download and use.
- Follow steps 1-4 of Selenium Remote Control HTML Suite Tutorial. This will get the Selenium Remote Control Running.
- In Visual Studio let’s create a new project. You will have to create a new class library by going New> New Solution> Class Library and call it TheAutomatedTester
- Add a reference to the NUnit Framework by rightclicking on the solution and clicking add reference. Click on the browse tab and navigate to <%nunithome%>\bin and select nunit.framework.dll . This allows you now to create your first NUnit test.
- Now in the *.cs file put the code below into it. The code below will call Selenium Remote and say that it needs an instance on Firefox Chrome.
- [TestFixture]
- public class TheAutomatedTester
- {
- private ISelenium selenium;
- private StringBuilder verificationErrors;
- [SetUp]
- public void SetupTest()
- {
- selenium = new DefaultSelenium(“localhost”, 4444, “*chrome”, “http://localhost”);
- selenium.Start();
- verificationErrors = new StringBuilder();
- }
- Now Lets create a test:
- [Test]
- public void AutomatedTester_Test()
- {
- selenium.Open(“/index.htm”);
- selenium.Click(“buttonName”);
- selenium.WaitForPageToLoad(“30000″);
- }
- Once your test has run you will need to clean up Selenium object. The best way to do this is to create a teardown function in your test. It should look like something like the code below.
- [TearDown]
- public void TeardownTest()
- {
- try
- {
- selenium.Stop();
- }
- catch (Exception)
- {// Ignore errors if unable to close the browser
- }
- Assert.AreEqual(“”, verificationErrors.ToString());
- }
- Now compile the code into a DLL and Open it with NUnit. When you click the Run button in NUnit it will run your Selenium Test.