I am getting the following message whilt running my test.
Message:
Test method Automation.Test1.General threw exception: System.NullReferenceException: Object reference not set to an instance of an object.
Automation.Library.CheckLogIn() in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\Automation\Automation\Library.cs: line 152
Automation.Test1.General() in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\Automation\Automation\Test1.cs: line 72
Library.cs (superclass)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Selenium;
using System.IO;
using System.Reflection;
using System.Net;
using System.Configuration;
namespace Automation
{
[TestClass]
public class Library
{
public ISelenium Sel;
// Open browser
public void OpenBrowser(out ISelenium selenium, out StringBuilder verificationErrors)
{
selenium = new DefaultSelenium(GetAppConfig("TestMachine"), 4444, GetAppConfig("Browser"), GetAppConfig("URL"));
selenium.Start();
selenium.Open(GetAppConfig("URL"));
verificationErrors = new StringBuilder();
}
// Returns the value of the passed key from App.config
public string GetAppConfig(string key)
{
return ConfigurationManager.AppSettings[key].ToString();
}
// Check for Login
public void CheckLogIn()
{
if (Sel.IsElementPresent(GetAppConfig("SignOn")))
{
Sel.Type(GetAppConfig("UserNameField"), GetAppConfig("UserName"));
Sel.Type(GetAppConfig("PWDField"), GetAppConfig("PWD"));
Sel.Click(GetAppConfig("Go"));
}
else
{
// do nothing
}
}
}
}
Test1.cs (sub class)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Selenium;
using System.IO;
using System.Reflection;
using System.Net;
using System.Configuration;
namespace Automation
{
[TestClass]
public class Test1
{
public ISelenium Sel;
public StringBuilder Err;
Boolean bNextFlag = false;
Library Lib = new Library();
// Constructor
public Test1()
{
// Launch browser with application URL
Lib.OpenBrowser(out Sel, out Err);
Sel.WindowMaximize();
Lib.CheckLogIn();
}
[TestMethod]
public void General()
{
// Verify Tab
if (Sel.IsElementPresent(Lib.GetAppConfig("TAB")))
{
Sel.Click(Lib.GetAppConfig("TAB"));
bNextFlag = true;
}
else
{
// do something
}
}
}
}
app.config.xml
<?xml version="1.0" encoding="utf-8" ?>
<add key="TestMachine" value="localhost"/>
<add key="Browser" value="*iexplore"/>
<add key="URL" value="http://localhost//Default.aspx"/>
<!-- CheckLogIn-->
<add key="SignOn" value="//*[@id="LogIn"]"/>
<add key="UserNameField" value="//*[@id="username"]"/>
<add key="PWDField" value="//*[@id="pwd"]"/>
<add key="Go" value="//*[@id="gobutton"]"/>
<add key="UserName" value="admin"/>
<add key="PWD" value="password"/>
<!-- End of CheckLogIn-->
<!-- Object Definitions-->
<add key="TAB" value="//*[@id="Tab"]"/>
<!-- End of Object Definitios-->