Private keywords visible in listbox

Bug reports.
Christoph
Posts: 23
Joined: Wed Jul 11, 2012 6:22 am
Location: Liechtenstein

Private keywords visible in listbox

Post by Christoph » Thu Oct 10, 2013 9:06 am

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
Keyword Error
KeywordError.png (92.03 KiB) Viewed 1356 times
Christoph

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

Re: Private keywords visible in listbox

Post by krstcs » Thu Oct 10, 2013 1:19 pm

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.
Shortcuts usually aren't...

Christoph
Posts: 23
Joined: Wed Jul 11, 2012 6:22 am
Location: Liechtenstein

Re: Private keywords visible in listbox

Post by Christoph » Thu Oct 10, 2013 2:04 pm

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

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

Re: Private keywords visible in listbox

Post by krstcs » Thu Oct 10, 2013 2:20 pm

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.
Shortcuts usually aren't...

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

Re: Private keywords visible in listbox

Post by Support Team » Fri Oct 11, 2013 12:47 pm

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