Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6000677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:43:42+00:00 2026-05-23T00:43:42+00:00

I am getting the following message whilt running my test. Message: Test method Automation.Test1.General

  • 0

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=&quot;LogIn&quot;]"/>
<add key="UserNameField" value="//*[@id=&quot;username&quot;]"/>
<add key="PWDField" value="//*[@id=&quot;pwd&quot;]"/>
<add key="Go" value="//*[@id=&quot;gobutton&quot;]"/>
<add key="UserName" value="admin"/>
<add key="PWD" value="password"/>
<!-- End of  CheckLogIn-->

<!-- Object Definitions-->

<add key="TAB" value="//*[@id=&quot;Tab&quot;]"/>

<!-- End of Object Definitios-->

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:43:42+00:00Added an answer on May 23, 2026 at 12:43 am

    Well I don’t really see a question in your post, so I suppose I will point out the obvious…

    Your error is telling you that you have a NullReferenceException being thrown somewhere in this method:

    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
        }
    }
    

    Sel is null. Nowhere in your code do you actually initialize it. You’ll need to initialize it somewhere like:

    Sel = new SomeTypeThatImplementsISelenium();
    

    Also, GetAppConfig is deprecated per the docs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am getting following error message on calling WCF service: The formatter threw an exception
I'm getting the error message when running the following code from a C# console
I am getting the following error message while running .net 3.5 applciation Your step-into
I am getting the following exception message when I try to run my newly
I'm getting the following error message in jQuery Mobile: Cannot call method 'trigger' of
I am getting following error message when using Doctrine ORM in Codeigniter. ( !
We’re getting the following error message when we click on Search Settings for a
I'm getting the following error message and I can't seem to figure out the
I am getting the following failure message when i build on the below two
I keep getting the following error message ERROR 1064 (42000): You have an error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.