Page 1 of 1

Private keywords visible in listbox

Posted: Thu Oct 10, 2013 9:06 am
by Christoph
Hi,

I'm runing Ranorex 4.1.1. on Windows Server 2008 R2 Standard.

I'm using the second approach (Keyword-Driven Framework using the Actions Table) from this blog http://www.ranorex.com/blog/keyword-dri ... -framework to create keywords.

I created following keyword class, which contains my actual keywords as well as helper methods which are marked as private.
public class KeywordTestClass
	{
		public KeywordTestClass()
		{
		}
		
		public void MyFunctionOne()
		{
			_MyHelperOne();
		}
		
		public void MyFunctionTwo()
		{
			_MyHelperTwo();
		}
		
		private void _MyHelperOne()
		{
			// do something
		}
		
		private void _MyHelperTwo()
		{
			// do something
		}
	}
I then create a recording and in the "userCode" class of the recording I inherit my keyword class.
public partial class UseKeyWords:KeywordTestClass
   {
        /// <summary>
        /// This method gets called right after the recording has been started.
        /// It can be used to execute recording specific initialization code.
        /// </summary>
        private void Init()
        {
            // Your recording specific initialization code goes here.
        }

    }
In the recording I add user code with "Add New Action" --> "User Code"
In the listbox that offers the methods available all methods appear, the public as well as the private ones (see Screenshot). This is a bug, since the private methods should not be visible and should not be allowed to select. If I select one it will raise a compiler error. (see screenshot)
KeywordError.png
Christoph

Re: Private keywords visible in listbox

Posted: Thu Oct 10, 2013 1:19 pm
by krstcs
I believe you are misunderstanding a basic principle of object-oriented coding.

Inheriting classes will have access to ALL methods of the parent, including private methods.

Your "UseKeyWords" class inherits from "KeywordTestClass", therefore UseKeyWords IS a type of KeywordTestClass and will have all the structures of the parent plus whatever you add to it.

Re: Private keywords visible in listbox

Posted: Thu Oct 10, 2013 2:04 pm
by Christoph
I don't believe your statement is correct. According to msdn:

http://msdn.microsoft.com/en-us/library ... 00%29.aspx
The private keyword is a member access modifier. Private access is the least permissive access level. Private members are accessible only within the body of the class or the struct in which they are declared.

http://msdn.microsoft.com/en-us/library ... 00%29.aspx
The protected keyword is a member access modifier. A protected member is accessible within its class and by derived class instances.

Also, if your statement was correct, my project would compile when selecting a private member, but the compiler complains with an protection level error, as seen in the screenshot.

Christoph

Re: Private keywords visible in listbox

Posted: Thu Oct 10, 2013 2:20 pm
by krstcs
You are correct, I was thinking of protected. :D


So, my guess would be that Ranorex is populating the rxrec file (xml) with all methods from the derived class, when it should not be. That is why your rxrec (Recording Module) can see them.

If you create a user code method, you can see that the private methods are not visible from the inheriting class.

Re: Private keywords visible in listbox

Posted: Fri Oct 11, 2013 12:47 pm
by Support Team
Hello,

Thank for your reporting this issue.
The list should not show these private methods.

I have added it to our internal bug-tracking system.
We will provide a fix for it as soon as possible.

Thank you for your understanding.

Regards,
Markus (T)