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

NullReferenceException for Log.WriteLine

11 Answers 167 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
dan
Top achievements
Rank 1
dan asked on 10 Jul 2016, 11:53 AM

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)
        {

 

 

11 Answers, 1 is accepted

Sort by
0
dan
Top achievements
Rank 1
answered on 10 Jul 2016, 12:06 PM

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

0
Boyan Boev
Telerik team
answered on 13 Jul 2016, 02:36 PM
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
 
0
dan
Top achievements
Rank 1
answered on 18 Jul 2016, 11:09 AM

Hi Boyan,

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

 

thx,

dan

0
Boyan Boev
Telerik team
answered on 20 Jul 2016, 12:26 PM
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
 
0
dan
Top achievements
Rank 1
answered on 20 Jul 2016, 12:43 PM

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.

0
Boyan Boev
Telerik team
answered on 25 Jul 2016, 08:11 AM
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
 
0
dan
Top achievements
Rank 1
answered on 25 Jul 2016, 06:36 PM
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
0
Boyan Boev
Telerik team
answered on 28 Jul 2016, 10:53 AM
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
 
0
dan
Top achievements
Rank 1
answered on 28 Jul 2016, 12:45 PM

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

Cheers,

dan

0
Boyan Boev
Telerik team
answered on 29 Jul 2016, 01:05 PM
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
 
0
dan
Top achievements
Rank 1
answered on 29 Jul 2016, 01:33 PM
Perfect. You guys rock!!
Tags
General Discussions
Asked by
dan
Top achievements
Rank 1
Answers by
dan
Top achievements
Rank 1
Boyan Boev
Telerik team
Share this question
or