Page 1 of 1

How to Validate with Catch but Report as Warning

Posted: Tue Jul 17, 2012 3:02 pm
by ChrisSA
Hi All,

I'm currently evaluating the software and trying to find a solution for a problem I have encountered. I have had a quick look at the API doc but was unable to find an answer (I'm not a developer so don't know the code well).

With code below I check to see if an object is already created - if the validation fails I then create the object and continue.
I just want to give a warning if the validation fails rather than the error it gives now.

public void Setup_ODBC()
        {
        	try
        	{
        		Validate.Attribute(repo.SelectDataSource.CellXlsInfo, "Text", "xls"); //Question: How to give warning if this fails with it still running the catch
        		Report.Log(ReportLevel.Success, "XLS already exists");
        	}
        	catch
        	{
        		Report.Log(ReportLevel.Info, "CREATING XLS OBJECT");
//CREATION CODE HERE
	        	Report.Log(ReportLevel.Info, "XLS now created");
        	}
        }
Thanks for your time,
Chris

Re: How to Validate with Catch but Report as Warning

Posted: Tue Jul 17, 2012 3:33 pm
by Support Team
Hi Chris,

You can try the following code:
try{
				Validate.Exists("/form[@title='Calculator']/titlebar[@accessiblerole='TitleBar']", new Duration(5000), "Your Message", new Validate.Options(true, ReportLevel.Warn));
			}catch(Exception e){
				
				Report.Log(ReportLevel.Info, "CREATING XLS OBJECT");
				//CREATION CODE HERE
				Report.Log(ReportLevel.Info, "XLS now created");
			}
If the Validation fails you will get a Warning. You can also use the return value of the Exists method instead of the Exception.
Here is also the link to the related API site: Exists Method (path, searchTimeout, message, options)
I hope this will help you solve the problem!

Regards,
Markus
Ranorex Support Team