see the code below.
Selenium automation tests can be run as a Console Application, Selenium Service, and NUnit Framework. Since NUnit is used by developers for unit testing, QA engineers can also develop and run Selenium tests with NUnit. Here are the steps for using Nunit with Selenium tests. This example uses Selenium Web Driver and NUnit for Windows.
1. Launch Visual Studio 2010 and create a new class library project and name it as descriptive as possible. In most cases, include test application and component name in the project name.
2. Add the nunit.framework.dll to the reference.
3. Add Selenium .Net Web Driver dlls to the reference.
4. Add the following code to your class library project and compile it.
Recently many web applications are using Ajax technology to render information on the web page. When using Selenium Web Driver to automate test cases, Web Driver should wait until the active Ajax calls in the system complete. The WaitForAjaxCallsToComplete() method below will dynamically wait until there is no active Ajax calls in the system. Depending on your application, you can set the timeout in the App.Config or just give a hardcoded timeout.
public void WaitForAjaxCallsToComplete()
var wait = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(int.Parse(ConfigurationManager.AppSettings["TimeOut"].ToString())));
for (int i = 0; i < 30; i++)
Console.WriteLine("No Ajax call is detected");
In some cases, automation engineers need to write test results to a specific cell in an Excel spreadsheet. The code snippet below is for your reference.
//this method will write test result to a specific cell in Excel spreadsheet
public static void WriteToExcelFile(string fpath, string fname, string resutlToWrite, int cellrow, int cellcolumn)
When automating test cases, sometimes you need to read a specific cell value of an Excel spreadsheet for data driven testing. Below is the code snippet for your references.
Click the link below to test Mortgage Calculator application with Selenium. This application is designed with .Net code.
public class DropDownMenuTest
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
public void SetupTest()
driver = new FirefoxDriver();
baseURL = "http://seleniummaster.com";
verificationErrors = new StringBuilder();
Drop Down Menu Test in Java
This screenshot below teaches you how to test drop down menu on the web with Selenium IDE. The steps you need to follow:
(1) Mouse over on the root of the menu (purpose is to open the menu items underneath)
(2) Click the menu item one at a time
(3) Assert the menu item link page
(4) Go back and wait
(5) Mouse over on the root of the menu again
(6) Click another menu item
(7) Asset the menu item link page
This method below applies to Selenium .Net
When you test web applications, sometimes you need to wait an active AJAX process is completed. You can achieve a WaitForAjax method with few lines of code as listed below.
In this method, when you call the WaitForAjax method, you can define maximum timeout time for the AJAX to be completed. For example, if the active AJAX should be completed within 40 seconds, you can call the method : WaitForAjax(40);
This method below tells you how much actual time the AJAX synchronization took by looking at the message on the console.
public void WaitForAjax(int timeoutInSeconds)