'Object reference' error when using string methods
Posted: Tue Feb 19, 2013 9:49 pm
Hi, the test I am writing uses a While loop to query the state of a label on the webpage. If the InnerText of the label contains a particular string, the While loop exits. The trouble is, I'm getting an 'Object reference' error whenever I try to invoke the appropriate string method. Here is the code in question:
bool boolFailure = false;
string tempString = null;
while (!tempString.Contains("Processing has completed"))
{
tempString = repo.ExecuteSavedInstructions.ExecXML_status.InnerText;
if (tempString.Contains("Errors"))
{
Report.Failure("The following error occurred. " +tempString);
boolFailure = true;
break;
}
Thread.Sleep(500);
}
}
When I try to run the test, I get the following error:
Object reference not set to an instance of an object.
Show/Hide Stacktrace
at Test_Discovery.Recording1.Validate_DiscSuccess() in c:\HP RX tests\Test_Discovery\Test_Discovery\Recording1.UserCode.cs:line 44 at Test_Discovery.Recording1.Ranorex.Core.Testing.ITestModule.Run() in c:\HP RX tests\Test_Discovery\Test_Discovery\Recording1.cs:line 81 at Ranorex.Core.Testing.TestSuiteModule.RunInternal(DataContext parentDataContext)
Please note that line 44 equates to the line with the While statement. Also note that I've tried using other string methods (e.g. string.EndsWith), and the same error occurs. It's extremely important that I be able to use these methods. please advise. Thanks!
bool boolFailure = false;
string tempString = null;
while (!tempString.Contains("Processing has completed"))
{
tempString = repo.ExecuteSavedInstructions.ExecXML_status.InnerText;
if (tempString.Contains("Errors"))
{
Report.Failure("The following error occurred. " +tempString);
boolFailure = true;
break;
}
Thread.Sleep(500);
}
}
When I try to run the test, I get the following error:
Object reference not set to an instance of an object.
Show/Hide Stacktrace
at Test_Discovery.Recording1.Validate_DiscSuccess() in c:\HP RX tests\Test_Discovery\Test_Discovery\Recording1.UserCode.cs:line 44 at Test_Discovery.Recording1.Ranorex.Core.Testing.ITestModule.Run() in c:\HP RX tests\Test_Discovery\Test_Discovery\Recording1.cs:line 81 at Ranorex.Core.Testing.TestSuiteModule.RunInternal(DataContext parentDataContext)
Please note that line 44 equates to the line with the While statement. Also note that I've tried using other string methods (e.g. string.EndsWith), and the same error occurs. It's extremely important that I be able to use these methods. please advise. Thanks!