Unable to select the item/element from the contex menu

Class library usage, coding and language questions.
ramanaramidi
Posts: 28
Joined: Wed Feb 26, 2020 6:51 am

Unable to select the item/element from the contex menu

Post by ramanaramidi » Mon Apr 20, 2020 4:29 pm

Hi,

I am trying to automate KeyPass windows application through automation api. My automation script is able to right click on the row but unable to select the item (Edit/View Entry ...)

Here is the code I have written

Code: Select all

 Ranorex.Form MainForm1 = "/form[@controlname='MainForm']";
            MainForm1.FindSingle<Ranorex.ListItem>("/form[@controlname='MainForm']/container[@controlname='m_splitHorizontal']//table[@controlname='m_lvEntries']/list[@accessiblerole='List']/listitem[@accessiblename>'Windows Laptop Credential']").Click(System.Windows.Forms.MouseButtons.Right, 100);
            MainForm1.FindSingle<Ranorex.ContextMenu>("/form[@controlname='MainForm']/contextmenu/menuitem[@accessiblename='Edit/View Entry...']").Click();

Could you please help?
Thank you in advance.


Regards,
Ramana.
Attachments
Element_Selection_ContexMenu.jpg
Element_Selection_ContexMenu.jpg (87.6 KiB) Viewed 234 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6188
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Unable to select the item/element from the contex menu

Post by odklizec » Mon Apr 20, 2020 5:26 pm

Hi,

The xpath you are looking for is incorrect. The context menu does not belong to keepass "Form". It should look like this:

Code: Select all

/contextmenu//menuitem[@accessiblename='Edit/View Entry...']
eventually...

Code: Select all

/contextmenu[@processname='KeePass']//menuitem[@accessiblename='Edit/View Entry...']
or

Code: Select all

/contextmenu[@processname='KeePass' and @controlname='m_ctxPwList']//menuitem[@accessiblename='Edit/View Entry...']
And even then you should not search the context menu via MainForm1.FindSingle but via search Host.Local.FindSingle.

BTW, is there a reason why you are trying to do such simple task via API? I mean, honestly, it would be much easier, less complicated and much more efficient, from long-term perspective, to use Ranorex repository and recording modules. You see, coding every user action in code, will only increase your chances for unwelcome bugs, not to mention that the xpaths hardcoded in code are hell to maintain!

Seriously, try to rely on standard Ranorex tools, like Repository and predefined user actions, which are reliable and debugged over the years of Ranorex development. I use a lot of custom code in my projects, but only and solely for the things, which would be too complicated to do with recording actions (like form validations or reading/evaluating/writing files). And even then, 99.9% of my code uses repository and not hardcoded xpaths. There is really no excuse for using hardcoded xpaths in code (except of certain rare cases) ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

ramanaramidi
Posts: 28
Joined: Wed Feb 26, 2020 6:51 am

Re: Unable to select the item/element from the contex menu

Post by ramanaramidi » Mon Apr 20, 2020 7:21 pm

Hi Pavel,

Thanks for your quick response.

Actually, our requirement is to integrate ranorex solution with SpecFlow and BDD framework. We need to implement test automation for desktop application with BDD framework. So, we need to write coding instead of using the ranorex repository and recording modules.
So, I am trying with sample demo application.

Could you please clarify on the below?

Can we still use ranorex repository and recording modules if we integrate ranorex solution with Specflow? As of now I am not at all using the files and folders (eg: KeePassTestSuite.rxtst, KeePassTestSuiteRepository.rxrep) created by ranorex when a new desktop solution/project is created.

Also can you please share me the links on how to use the ranorex repository and predefined user actions for automation?
Also it would be great if you can share me the links on how to automate desktop application?


Thank you once again for your advise.

Regards,
Ramana.

User avatar
Stub
Posts: 373
Joined: Fri Jul 15, 2016 1:35 pm

Re: Unable to select the item/element from the contex menu

Post by Stub » Tue Apr 21, 2020 9:45 am

These are discussed in the Ranorex documentation.

ramanaramidi
Posts: 28
Joined: Wed Feb 26, 2020 6:51 am

Re: Unable to select the item/element from the contex menu

Post by ramanaramidi » Tue Apr 21, 2020 11:11 am

Hi,

I tried with the below code to select the element from context menu but unable to select the element.

Code: Select all

 
Host.Local.FindSingle<Ranorex.ListItem>("/form[@controlname='MainForm']/container[@controlname='m_splitHorizontal']//table[@controlname='m_lvEntries']/list[@accessiblerole='List']/listitem[@accessiblename>'Windows Laptop Credential']").Click(System.Windows.Forms.MouseButtons.Right, 100);

Host.Local.FindSingle<Ranorex.ContextMenu>("/contextmenu[@processname='KeePass' and @controlname='m_ctxPwList']//menuitem[@accessiblename='Edit/View Entry...']").Click();
Kindly suggest..


Regards,
Ramana.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6188
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Unable to select the item/element from the contex menu

Post by odklizec » Tue Apr 21, 2020 11:56 am

Hi,

Try to change Ranorex.ContextMenu to Ranorex.MenuItem. The xpath you are providing to Find method is not searching for ContextMenu but MenuItem!

As for the SpecFlow and BDD, I can't help you with that. I'm not using either Specflow or BDD in general. To be quite honest, I personally think that BDD approach overcomplicates simple things and is not as useful as it may sound from marketing papers. Creating a FUNCTIONAL test cases from text written in native language? Oh common...someone please show me a WORKING example of such approach! :D I would like to see a test case, created directly from native language, which would fill and validate simple list of buttons, labels or select boxes!

These things are easy to do with Ranorex test suite, test cases, smart folders, recording modules and recording actions. And if you need something more complicated, it's relative easy to add some user code for that. But doing entire tests with BDD approach means, that you will have to write a load of (potentially fragile) code and bend Ranorex tools to work with BDD approach. I think it's a great waste of time and energy :D But don't take me wrong! I would love too see and learn that BDD is actually useful and that it makes the life of test automation engineer and testers in general easier!
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

ramanaramidi
Posts: 28
Joined: Wed Feb 26, 2020 6:51 am

Re: Unable to select the item/element from the contex menu

Post by ramanaramidi » Tue Apr 21, 2020 2:52 pm

Hi Paval,

Thanks for your reply.
I tried with 'Ranorex.MenuItem' but no luck.

Code: Select all

Host.Local.FindSingle<Ranorex.MenuItem>("/contextmenu//menuitem[@accessiblename='Edit/View Entry...']").Click();
Thank you once again for your detailed explanation.

But our project requirement is to proceed with BDD & SpecFlow using Ranorex. So we need to go with that.
I too understand that we are not going to use all the features of ranorex.

Regards,
Ramana.

ramanaramidi
Posts: 28
Joined: Wed Feb 26, 2020 6:51 am

Re: Unable to select the item/element from the contex menu

Post by ramanaramidi » Wed Apr 22, 2020 1:25 pm

Hi,

Could you please help me on resolving the above issue? I am also attaching the snapshot for your reference.


Regards,
Ramana.
Attachments
KeePass_Snapshot.rxsnp
(78.15 KiB) Downloaded 4 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6188
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Unable to select the item/element from the contex menu

Post by odklizec » Wed Apr 22, 2020 2:00 pm

Hi,

I think you have to add a short delay to FindSingle, like this ...
Host.Local.FindSingle<Ranorex.MenuItem>("/contextmenu//menuitem[@accessiblename='Edit/View Entry...']",5000).Click();
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

ramanaramidi
Posts: 28
Joined: Wed Feb 26, 2020 6:51 am

Re: Unable to select the item/element from the contex menu

Post by ramanaramidi » Wed Apr 22, 2020 3:32 pm

Hi Pavel,

It's working fine after introducing the delay. Thank you so much.

Regards,
Ramana.