This is a migrated thread and some comments may be shown as answers.

System.NullReferenceException

23 Answers 354 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kiran
Top achievements
Rank 1
Kiran asked on 13 Jul 2014, 03:28 AM
Hello experts,

I'm trying my first sample test for google.com. I was able to record and playback tests from Test Sturio. However, we wanted to build our own framework. So started looking at the telrik API. I was completely struck with the below issue and was not able to proceed further

{           
            Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
            ActiveBrowser.NavigateTo("http://www.google.com"); //Was able to open the browser
            Console.WriteLine("Title of the page :" + ActiveBrowser.PageTitle); // Able to get the title of the browser
             
            // HtmlInputText textBox = ActiveBrowser.Find.ById<HtmlInputText>("gbqfq");
            Find.ByExpression<HtmlInputText>("id=?_gbqfq"); //This is where I'm getting the System.NullReferenceException  : Object reference not set to an instance of object

}

I'm struck at this point. Need your urgent help as I need to give a POC demo.

Regards,
Kiran



23 Answers, 1 is accepted

Sort by
0
Kiran
Top achievements
Rank 1
answered on 13 Jul 2014, 10:59 AM
Eagarly waiting for any one to reply.
0
Chunks
Top achievements
Rank 1
answered on 14 Jul 2014, 05:12 PM
Hey Kiran,

Are you trying to grab the input control of google search and type? After taking a quick look it seems the @id you are using is incorrect. I haven't run the code myself though.

Hope this helps!
0
Chunks
Top achievements
Rank 1
answered on 14 Jul 2014, 05:29 PM
umm , ignore my previous comment , the problem is you haven't initialized the test case object.
0
Kiran
Top achievements
Rank 1
answered on 15 Jul 2014, 01:04 AM
Thank you very much for your prompt response. It worked like a Charm :)
0
Kiran
Top achievements
Rank 1
answered on 15 Jul 2014, 03:53 AM
Hi ,

I had created the test by Creating a separte class for TextBox so that I can use the textbox object across the run. The problem here is it throws the null reference exception when i make a reference to Textbox class which is outside the actual Test Class. Seems the Reference for Find is getting null if called out site the BaseTestclass. However if I user the  Find.ByName in BaseTestClass, it works fine
Can you please help me with this issue. I'm attaching the source code.
BaseTestClass

[Test]
        public void testGoogleSearch()
        {
            Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
            ActiveBrowser.NavigateTo("http://www.google.com");
            //System.Threading.Thread.Sleep(3000);
            Console.WriteLine(ActiveBrowser.ViewSourceString);
            TextBox textBox = new TextBox();
            textBox.type("name=q", "Hello World");
}
TexBox Class
class TextBox : BaseTest
    {
        HtmlInputText searchTextBox = null;
        private HtmlInputText GetTextBox(String objectLocator)        {
            //objectlator shall be like id=login will be passed from external resouce like xml

            String[] values = objectLocator.Split('=');
            Console.WriteLine(values[0]);
            
            //Initialize(false, new TestContextWriteLine(Console.Out.WriteLine));
           // Find.ByName<HtmlInputText>("q").Text = "Hello World";
            switch (values[0])
            {
                case "id":
                    searchTextBox = Find.ById<HtmlInputText>(objectLocator);
                    break;
                case "name":
                    searchTextBox = Find.ByName<HtmlInputText>("q");
                    break;
                case "tagindex":
                    searchTextBox = Find.ByXPath<HtmlInputText>(values[0]);
                    break;
                case "xpath":
                    break;
               
                default:
                    searchTextBox = Find.ByName<HtmlInputText>(values[0]);
                    break;
            }
            return searchTextBox;
        }

        public void type(String ObjectLocator,String input)
        {
            GetTextBox(ObjectLocator).Text = input;
        }



0
Cody
Telerik team
answered on 16 Jul 2014, 10:39 PM
Hello Kiran,

The project you included won't compile. It relies on "BaseTest" which was not included. I need to know what this is/does.

Regards,
Cody
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Kiran
Top achievements
Rank 1
answered on 17 Jul 2014, 01:02 AM
Hello Cody,

In the project I wanted  to open a google.com and simply type some text in seacrch box.

In the code I have created 2 classes . one is SampleGoogleTest.cs which extends BaseTest Class. From this class , I was trying to launch browser, and was making a call to another Class TextBox.cs which would return me an instance of TextBox. I had created this TextBox class to make it reusable in many other TestClasses. I'm able to launch the google.com, fetch the page source and I'm getting the Null reference exception when I make a call to the TextBox class. I rechecked the project that I had attached previously, It got compiled and the Null reference exception is thrown at run time

Please let me know if you need more information. 

Regards,
Kiran
0
Cody
Telerik team
answered on 17 Jul 2014, 06:46 PM
Hello Kiran,

As you can see in this short video there is no BaseTest class in the project I received. I cannot continue until I receive a copy of it.


Regards,
Cody
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
srikanth
Top achievements
Rank 1
answered on 26 Mar 2015, 12:57 PM
Hi ,

'm trying my first sample test for google.com. I was able to record and playback tests from Test Studio. However, we wanted to build our own framework. So started looking at the telrik API. I've installed Telerik testing framework software and creted the new project and new Nunit webtest (.cs) I was completely struck with the below issue and was not able to proceed further

{           
            Manager.LaunchNewBrowser(BrowserType.Chrome);
            ActiveBrowser.NavigateTo("http://www.google.com"); //Was able to open the browser and navigated to google page
           
             Find.ById<HtmlInputText>("s").Text = "telerik";  //This is where I'm getting the System.NullReferenceException  : Object reference not set to an instance of object

}
I'm struck at this point. but I found that to initialise the test case object is missing  but I did'nt understand where to initialise the object and how. Can you please be specific in solving my problem. Thanks alot in advance

Regards,
K.Sreekanth 
0
srikanth
Top achievements
Rank 1
answered on 26 Mar 2015, 01:06 PM
Hello,

I'm trying my first sample test for google.com. I was able to record and playback tests from Test Studio. However, we wanted to build our own framework. So started looking at the telrik API. I've installed telerik testing framework and created the new project and new Nunit webtest(.cs) file where I have written the following code in it . I was completely struck with the below issue and was not able to proceed further

public void MyTest : BaseTest
{
 [setup/Teardown]
[Test]
public void sample()
{           
            Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
            ActiveBrowser.NavigateTo("http://www.google.com"); //Was able to open the browser and navigate to google page
          Find.ById<HtmlInputText>("s").Text = "telerik";  //This is where I'm getting the System.NullReferenceException  : Object reference not set to an instance of object

}
}

I'm struck at this point. Need your urgent help. I found a solution that initialising the test case is not done but I didnt understand where and how to do it so can you please be specific to solve my problem as Im new to telerik testing framework.Thanks alot in advance

Regards,
K.sreekanth
0
srikanth
Top achievements
Rank 1
answered on 26 Mar 2015, 01:06 PM
Hello,

I'm trying my first sample test for google.com. I was able to record and playback tests from Test Studio. However, we wanted to build our own framework. So started looking at the telrik API. I've installed telerik testing framework and created the new project and new Nunit webtest(.cs) file where I have written the following code in it . I was completely struck with the below issue and was not able to proceed further

public void MyTest : BaseTest
{
 [setup/Teardown]
[Test]
public void sample()
{           
            Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
            ActiveBrowser.NavigateTo("http://www.google.com"); //Was able to open the browser and navigate to google page
          Find.ById<HtmlInputText>("s").Text = "telerik";  //This is where I'm getting the System.NullReferenceException  : Object reference not set to an instance of object

}
}

I'm struck at this point. Need your urgent help. I found a solution that initialising the test case is not done but I didnt understand where and how to do it so can you please be specific to solve my problem as Im new to telerik testing framework.Thanks alot in advance

Regards,
K.sreekanth
0
srikanth
Top achievements
Rank 1
answered on 27 Mar 2015, 09:36 AM
Please I'm eagerly waiting for your reply 
 

  I also tried with below type of code 
 //Element mybtn = myManager.ActiveBrowser.Find.ById("gb_70");
            
           Element mybtn = myManager.ActiveBrowser.Find.ByContent("Sign in");
            if (mybtn!=null)
            {
                Console.WriteLine("not null");
                 myManager.ActiveBrowser.Actions.Click(mybtn);
            }
            else
            {
                 Console.WriteLine("null");
            } 


but it always return null only 



0
srikanth
Top achievements
Rank 1
answered on 30 Mar 2015, 05:55 AM
anyone please help me for my query.
0
Chunks
Top achievements
Rank 1
answered on 30 Mar 2015, 10:43 PM
I would try this :

var mybtn = Manager.Current.ActiveBrowser.Find.ByContent<HtmlAnchor>("Sign in");
// Or  :  var btn2 = Manager.Current.ActiveBrowser.Find.ById<HtmlAnchor>("gb_70");
mybtn.Click();

Luck,
Chunks
0
srikanth
Top achievements
Rank 1
answered on 02 Apr 2015, 09:42 AM
Hi,
 
   BadLuck the issue still persists , actually I'm trying to implement the tests with Telerik testing framework in Visual studio community 2013 but when ever Im trying to locate the element it returns null value

    but I'm successfully executing the above mentioned sample tests when I'm working on trial version of VS2012 with telerik testing framework on Virtual machine

    Is Telerik testing framework completely supports Visual studios community 2013(FREE Edition) because the sample tests working fine on Trial version of vs12 (the same installation I followed for telerik testing framwork and jcode in both environments except the Visual studios)

Thanks in advance , eagerly waiting for reply
 

sreekanth.
0
srikanth
Top achievements
Rank 1
answered on 02 Apr 2015, 10:39 AM
I've also observed this  (Note: Test Studio supports Visual Studio 2013 starting with version 2014.1.410 )in Telerik documentation (http://docs.telerik.com/teststudio/getting-started/installation/system-requirements) where I'm using community VS13 with version 12.0.31101 (Is this reason for why I'm not able to run the test successful in TTF) Please let me know.

Thanks,
sreekanth.
0
Ivaylo
Telerik team
answered on 07 Apr 2015, 07:59 AM
Hello,

Please make sure you are using the latest version of Test Studio with Visual Studio 2013.

Regards,
Ivaylo
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
srikanth
Top achievements
Rank 1
answered on 08 Apr 2015, 05:44 AM

 Hi,

I'm using Telerik Teststudio version 2015.1.3.19.0 and VS Community 2013 version 12.0.31101 the issue was still persists returns null rference exception while searching for element and  its work fine with VS12 on VM 

0
Ivaylo
Telerik team
answered on 10 Apr 2015, 06:07 AM
Hello,

We will need a sample project which reproduces the behavior so we can investigate further.

Please attach the project with detailed repro steps.

Regards,
Ivaylo
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
srikanth
Top achievements
Rank 1
answered on 10 Apr 2015, 07:08 AM

Thank you for your reply,

 

 below is the zip contains my  sample test (Mytest1) created with Nunit suite file and I'm executing this with 'Unit Test Window' and I'm getting the   'Null reference exception : object reference not set to an instance of an object'  at Locating the element (returns null) in VS community 2013 .Please verify and let me know 

Thanks,

Sreekanth

0
srikanth
Top achievements
Rank 1
answered on 10 Apr 2015, 07:10 AM

Hi,

sorry I forgot to attach

The sample project for above mentioned is

0
srikanth
Top achievements
Rank 1
answered on 10 Apr 2015, 08:48 AM

My sample project

 

0
Ivaylo
Telerik team
answered on 14 Apr 2015, 03:56 PM
Hello Kiran,

The test you have provided passes when executed in Visual Studio and NUnit as well.

Please refer to the screenshot attached.

Regards,
Ivaylo
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Kiran
Top achievements
Rank 1
Answers by
Kiran
Top achievements
Rank 1
Chunks
Top achievements
Rank 1
Cody
Telerik team
srikanth
Top achievements
Rank 1
Ivaylo
Telerik team
Share this question
or