How to Validate with Catch but Report as Warning

Ask general questions here.
ChrisSA
Posts: 9
Joined: Tue Jul 17, 2012 2:41 pm

How to Validate with Catch but Report as Warning

Post by ChrisSA » Tue Jul 17, 2012 3:02 pm

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
Ranorex Version: 4.0.0.20817

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to Validate with Catch but Report as Warning

Post by Support Team » Tue Jul 17, 2012 3:33 pm

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
.
Image