NullReferenceException for Log.WriteLine

12 posts, 0 answers
  1. dan
    dan avatar
    27 posts
    Member since:
    Jun 2016

    Posted 10 Jul Link to this post

    Hi,

     

    In my project I have two tests, one for 'Accounts' and another for 'Advanced Find'

    The 'Accounts' test has a coded step..

        public void SelectAccountTypeByName(String typeName, Browser xframe)
            {

     

     

  2. dan
    dan avatar
    27 posts
    Member since:
    Jun 2016

    Posted 10 Jul Link to this post

    My apologies, I accidentally posted before I was finished. I will try again ..

     

    Hi,

     

    In my project I have two tests, one for 'Accounts' and another for 'Advanced Find'

    The 'Accounts' test has a coded step..

        public void SelectAccountTypeByName(String typeName, Browser xframe)
            {
    some code
    Log.Writeline("hello world");

    }

    When my 'Accounts' test executes this coded step, it executes successfully.

    However, if in the 'Advanced Find' test I attempt to use this coded step as follows..

    Accounts xaccount = new Accounts();
            xaccount.SelectAccountTypeByName("random", Account_contentIFrame0);

    The 'Log.WriteLine("hello world")' results in..

    System.NullReferenceException: Object reference not set to an instance of an object.
       at ArtOfTest.WebAii.Design.BaseWebAiiTest.get_Log()
       at TestProject2.Accounts.SelectAccountTypeByName(String typeName, Browser xframe) in f:\New folder\Test Studio Projects\TestProject2\Accounts\Accounts.tstest.cs:line 148
       at TestProject2.Advanced_Find.Select_Type_Random1() in f:\New folder\Test Studio Projects\TestProject2\Advanced Find\Advanced Find.tstest.cs:line 201

    If I comment out the Log.WriteLine, the coded step executes fine.

    Your help would be appreciated.

    thanks,
    dan

  3. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 13 Jul Link to this post

    Hello Dan,

    Is the Log.WriteLine in a coded step (in the second test)?

    Is there a chance you can send us your project so we can review it?

    Hope to hear from you soon.

    Regards,
    Boyan Boev
    Telerik by Progress
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  4. dan
    dan avatar
    27 posts
    Member since:
    Jun 2016

    Posted 18 Jul in reply to Boyan Boev Link to this post

    Hi Boyan,

    Yes, it is in a coded step. I've attached the project.

     

    thx,

    dan

  5. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 20 Jul Link to this post

    Hi Dan,

    I assume that the issue is that Log.WriteLine method accept only sting so you should change your code as follows:
    Log.WriteLine("Select option: " +newIndexx.ToString()+ " of "+AccounttypeISelect.Options.Count.ToString());

    However I cannot confirm this since I cannot execute your test.

    The other options is that some of the variables you want to WriteLine does not exists in the current context.

    Hope that helps.

    Regards,
    Boyan Boev
    Telerik by Progress
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  6. dan
    dan avatar
    27 posts
    Member since:
    Jun 2016

    Posted 20 Jul in reply to Boyan Boev Link to this post

    Hi Boyan,

    Thanks for your suggestion, but the problem is not with the variables I'm attempting to log. I get the exception when using just Log.WriteLine("Hello world").

    As I noted before, if the coded step includes 'Log.Writeline("hello world")', then the  'Accounts' test executes the coded step successfully. But, if in the 'Advanced Find' test I attempt to use this coded step as follows..

    Accounts xaccount = new Accounts();
            xaccount.SelectAccountTypeByName("random", Account_contentIFrame0);

    The presence of  'Log.WriteLine("hello world")' results in the exception. If I comment it out, then xaccount.SelectAccountTypeByName("random", Account_contentIFrame0) also executes successfully.

  7. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 25 Jul Link to this post

    Hello Dan,

    I am not able to reproduce this issue. I am able to start every test from the project you've sent me.

    See this video for a demonstration.

    Could you please creating a new test and copy all the steps from the previous one to the new one?

    Please record a short video demonstrating the exact issue.

    Thank you!

    Regards,
    Boyan Boev
    Telerik by Progress
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  8. dan
    dan avatar
    27 posts
    Member since:
    Jun 2016

    Posted 25 Jul in reply to Boyan Boev Link to this post

    Hi Boyan,
    I’ve attached a simplified project that demos the issue.

    You’ll notice WebTest1 passes, but WebTest2 fails on Log.WriteLine(“hello world”) ...

    Failure Information: ~~~~~~~~~~~~~~~Exception thrown executing coded step: 'New Coded Step'.InnerException:System.NullReferenceException: Object reference not set to an instance of an object.   at ArtOfTest.WebAii.Design.BaseWebAiiTest.get_Log()   at LogWrteLineIssue_Demo.WebTest1.enterSearchText(Browser xbrowser) in c:\Users\odacrd\Documents\Test Studio Projects\LogWrteLineIssue_Demo\WebTest1.tstest.cs:line 54   at LogWrteLineIssue_Demo.WebTest2.WebTest2_CodedStep() in c:\Users\odacrd\Documents\Test Studio Projects\LogWrteLineIssue_Demo\WebTest2.tstest.cs:line 53

    Once you comment out the Log.WriteLine(“hello world”) in WebTest1.tstest.cs:line 54, then both WebTest1 and WebTest2 pass.

    Thanks,
    dan
  9. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 28 Jul Link to this post

    Hi Dan,

    Now I understand what is going on exactly.

    Unfortunately you cannot crate instances of other tests and call it like this. There is no Manager initialized e.t.c.

    You can create a standalone code file where you can implement your own methods and call them in any test you want.

    I have modified the project you have sent me with a such file for a demonstration.

    Hope that helps.

    Regards,
    Boyan Boev
    Telerik by Progress
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  10. dan
    dan avatar
    27 posts
    Member since:
    Jun 2016

    Posted 28 Jul in reply to Boyan Boev Link to this post

    Excellent! Thanks Boyan. I'll give that a try.

    Cheers,

    dan

  11. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 29 Jul Link to this post

    Hello Dan,

    You are most welcome.

    Please give that a try and let me know the results.

    Regards,
    Boyan Boev
    Telerik by Progress
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  12. dan
    dan avatar
    27 posts
    Member since:
    Jun 2016

    Posted 29 Jul in reply to Boyan Boev Link to this post

    Perfect. You guys rock!!
Back to Top