System.NullReferenceException

24 posts, 0 answers
  1. Kiran
    Kiran avatar
    5 posts
    Member since:
    Jun 2014

    Posted 12 Jul 2014 Link to this post

    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



  2. Kiran
    Kiran avatar
    5 posts
    Member since:
    Jun 2014

    Posted 13 Jul 2014 in reply to Kiran Link to this post

    Eagarly waiting for any one to reply.
  3. Chunks
    Chunks avatar
    17 posts
    Member since:
    Nov 2011

    Posted 14 Jul 2014 in reply to Kiran Link to this post

    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!
  4. Chunks
    Chunks avatar
    17 posts
    Member since:
    Nov 2011

    Posted 14 Jul 2014 in reply to Chunks Link to this post

    umm , ignore my previous comment , the problem is you haven't initialized the test case object.
  5. Kiran
    Kiran avatar
    5 posts
    Member since:
    Jun 2014

    Posted 14 Jul 2014 in reply to Kiran Link to this post

    Thank you very much for your prompt response. It worked like a Charm :)
  6. Kiran
    Kiran avatar
    5 posts
    Member since:
    Jun 2014

    Posted 14 Jul 2014 Link to this post

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



  7. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 16 Jul 2014 Link to this post

    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
     
  8. Kiran
    Kiran avatar
    5 posts
    Member since:
    Jun 2014

    Posted 16 Jul 2014 in reply to Cody Link to this post

    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
  9. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 17 Jul 2014 Link to this post

    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
     
  10. srikanth
    srikanth avatar
    19 posts
    Member since:
    Feb 2015

    Posted 26 Mar 2015 in reply to Cody Link to this post

    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 
  11. srikanth
    srikanth avatar
    19 posts
    Member since:
    Feb 2015

    Posted 26 Mar 2015 in reply to Cody Link to this post

    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
  12. srikanth
    srikanth avatar
    19 posts
    Member since:
    Feb 2015

    Posted 26 Mar 2015 in reply to Cody Link to this post

    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
  13. srikanth
    srikanth avatar
    19 posts
    Member since:
    Feb 2015

    Posted 27 Mar 2015 Link to this post

    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 



  14. srikanth
    srikanth avatar
    19 posts
    Member since:
    Feb 2015

    Posted 30 Mar 2015 Link to this post

    anyone please help me for my query.
  15. Chunks
    Chunks avatar
    17 posts
    Member since:
    Nov 2011

    Posted 30 Mar 2015 Link to this post

    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
  16. srikanth
    srikanth avatar
    19 posts
    Member since:
    Feb 2015

    Posted 02 Apr 2015 in reply to Chunks Link to this post

    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.
  17. srikanth
    srikanth avatar
    19 posts
    Member since:
    Feb 2015

    Posted 02 Apr 2015 Link to this post

    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.
  18. Ivaylo
    Admin
    Ivaylo avatar
    750 posts

    Posted 07 Apr 2015 Link to this post

    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
     
  19. srikanth
    srikanth avatar
    19 posts
    Member since:
    Feb 2015

    Posted 08 Apr 2015 in reply to Ivaylo Link to this post

     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 

  20. Ivaylo
    Admin
    Ivaylo avatar
    750 posts

    Posted 10 Apr 2015 Link to this post

    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
     
  21. srikanth
    srikanth avatar
    19 posts
    Member since:
    Feb 2015

    Posted 10 Apr 2015 in reply to Ivaylo Link to this post

    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

  22. srikanth
    srikanth avatar
    19 posts
    Member since:
    Feb 2015

    Posted 10 Apr 2015 Link to this post

    Hi,

    sorry I forgot to attach

    The sample project for above mentioned is

  23. srikanth
    srikanth avatar
    19 posts
    Member since:
    Feb 2015

    Posted 10 Apr 2015 Link to this post

    My sample project

     

  24. Ivaylo
    Admin
    Ivaylo avatar
    750 posts

    Posted 14 Apr 2015 Link to this post

    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
     
Back to Top