Code module skip fail

Class library usage, coding and language questions.
Dannyets
Posts: 1
Joined: Wed May 20, 2015 11:49 am

Code module skip fail

Post by Dannyets » Wed May 20, 2015 12:01 pm

Hello, i am trying to make a validation function and give it a Ranorex Repository item as a variable :

Code: Select all

		/// <summary>
		/// Validate existance of a given Ranorex Path
		/// </summary>
		/// <param name="path">Ranorex path of a ranorex repository item.</param>
		/// <returns>true if path exists, false otherwise.</returns>
		public static bool Ranorex_Validate(Ranorex.Core.RxPath path)
		{
			//Write to log
			//LogWriter.Log("_Entered Ranorex_Validate()."); //Write to log
			
			//Set Flag to false
			ExistFlag = false;
			
			//Validate path
			try
			{
				ExistFlag = Ranorex.Validate.Exists(path,3000,"Couldn't find {0} path.",false);
				if(ExistFlag)
				{
					//LogWriter.Log("Validate succeeded, return true."); //Write to log
					//LogWriter.Log("_Exiting Ranorex_Validate()."); //Write to log
					return true; //Path exists.
				}
					
			}
			catch (Exception ex)
			{
				LogWriter.Log("Exception occured: " + ex.Message); //Write to log
			}
			
			LogWriter.Log("Validation path variable set to: " + path.ToString()); //Write to log
			LogWriter.Log("Validate failed, return false."); //Write to log
			return false;
		}
When i am using this function inside one of my code modules, for example :

Code: Select all

if(General.Library.General.Ranorex_Validate(repo.WINWORD.Info_Protect_Document_Options.MarkAsFinal.GetPath()))
            {
            	MessageBox.Show("Pass");
            }
            else
            	MessageBox.Show("Fail");
if the repository item could not be found, ranorex will stop the code module and throw an exception. (because it couldn't find the item and therefore couldn't pass the item's path and wouldn't get inside the function).

what can i do to make ranorex skip the fail and let me handle it\get the item's path (which will be dynamic in case of a change in the repository)?

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Code module skip fail

Post by krstcs » Wed May 20, 2015 3:30 pm

First, I would ask why you are trying to reinvent what Ranorex already does? RanoreXPath can be made dynamic very easily by including variables, and those variables' values can be changed at runtime using a data-driven approach, so there is no need for doing what you are doing. I suggest that you should read the user guide, it will help a lot with understanding how Ranorex works: http://www.ranorex.com/support/user-guide-20.html. Pay particular attention to the section on data-driven testing.



Second, Ranorex validations throw exceptions when they find a failure. This exception needs to be caught and handled in user-code if you don't want Ranorex to handle it as it normally does.

Alternatively, if you just use the action table in the recording module, you can do the Validation and set the validation options such that Ranorex does not fail if the validation fails. It will still show the failure in the report, but the test will continue running as if it didn't fail.
Shortcuts usually aren't...