Null Reference Exception when trying to use the HTTP proxy

3 posts, 1 answers
  1. Daniel
    Daniel avatar
    1 posts
    Member since:
    Jul 2011

    Posted 23 Apr 2012 Link to this post

    I am trying to use the HTTP proxy with the code in the block below.  The Set web proxy set is run as step 1 of the test to initialize the settings and relaunch the browser.  When I get to the AddBeforeResponseListener I am getting a null reference exception( Object reference not set to an instance of an object..)  I am clearly missing an initialization step somewhere but I am not sure where.  

    I am use the TS plugin version 2012.1.420.0 with VS2010 on a win7 64 bit box.

    [CodedStep(@"Set WebProxy")]
            public void TradeList_CodedStep4()
            {
                ActiveBrowser.Close();
                Manager.Settings.Web.UseHttpProxy = true;
                Manager.LaunchNewBrowser();
            }
     
            [CodedStep(@"Click 'ContentPlaceHolderRwDldFilesCLbGenerateBulkReportLink'")]
            public void TradeList_CodedStep3()
            {
                ResponseListenerInfo li = new ResponseListenerInfo(GetFileFromHeaderInfo);
                Manager.Http.AddBeforeResponseListener(li);
     
                // Click 'ContentPlaceHolderRwDldFilesCLbGenerateBulkReportLink'
                Pages.TamaracIncCom7.ContentPlaceHolderRwDldFilesCLbGenerateBulkReportLink.Click(false);
     
                Manager.Http.RemoveBeforeResponseListener(li);
     
                //string getPostBack = (string)GetExtractedValue("BulkReportJavaScript");
                //string parsedPostBack = getPostBack.Substring(11);
     
                //var response = Actions.InvokeScript(parsedPostBack);
                           
            }
     
            private void GetFileFromHeaderInfo(object sender, HttpResponseEventArgs e)
            {
                System.Collections.Specialized.NameValueCollection headers = e.Response.Headers;
                 
            }
  2. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 26 Apr 2012 Link to this post

    Hello Daniel,

    The issue is that your setting to turn on the HttpProxy is not being respected, and there's nowhere to turn it on through the UI for Quick Execution. (It exists for Test Lists, however). There's an existing feature request for this and you can vote for it here

    In the meantime, here's a work-around:

    1. Disable the first coded step in the TradeList test.
    2. Create a new parent test and add a coded step that does the following:

    [CodedStep(@"New Coded Step")]
    public void ProxyParent_CodedStep()
    {
        Settings settings = new Settings();
        settings.Web.UseHttpProxy = true;
     
        ResultSummary results = RunHelper.Test(@"C:\Users\rinaldi\Documents\Visual Studio 2010\Projects\TestProject3\TestProject3\Tests\ProxyStuff.tstest", settings, @"C:\Users\rinaldi\Documents\Visual Studio 2010\Projects\TestProject3\TestProject3\bin\Debug\TestProject3.dll");
    }


    Kind regards,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Daniel
    Daniel avatar
    1 posts
    Member since:
    Jul 2011

    Posted 26 Apr 2012 Link to this post

    I can get this to work through in visual studio by adding a test settings file to the project and enabling it there.  It still does not work with test execute but I can at least debug it and get the information I need to build the test.  The link about the test lists shows that as well.
Back to Top