repoItemInfo's exist function equivalent in adapter object

Class library usage, coding and language questions.
yassine
Posts: 11
Joined: Mon Jan 09, 2017 12:49 pm

repoItemInfo's exist function equivalent in adapter object

Post by yassine » Mon Feb 13, 2017 3:46 pm

Hello every one,

Is there an equivalent to RepoItemInfo class exist function in adapter class, what I want is to verify id an object exist in the SUT and then execute my action but using Adapter class, I tried to use both functions Valid and Visible and also use Validate class exist function wich take an adapter as parameter but all this functions lunch an exception if the element does not exist.

Thanks in advance for your replies.

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

Re: repoItemInfo's exist function equivalent in adapter object

Post by krstcs » Mon Feb 13, 2017 4:40 pm

No.

The Adapter object does not have an Exists() method, only the RepoItemInfo instance for the given Adapter does. Is there a reason why you don't want to use the RepoItemInfo.Exist() method?


Another option may be to wrap your Validate.Exists() method with your own try-catch block so that the error is not thrown to the test runner. But this requires code, and if you want to do it multiple times it becomes quite cumbersome, although you could make it a method that does it given specific inputs.
Shortcuts usually aren't...

yassine
Posts: 11
Joined: Mon Jan 09, 2017 12:49 pm

Re: repoItemInfo's exist function equivalent in adapter object

Post by yassine » Tue Feb 14, 2017 10:16 am

Thanks Krstcs for your reply, what I am trying to do is to create a custom function I call it ClickToDisappear :

Code: Select all

		
                        public static void ClickToDisappear (RepoItemInfo BtnToClick, string coordinates)
		        {
                                CLICK_OBJECT_2:
				{
					BtnToClick.FindAdapter<Unknown>().MoveTo(coordinates);
					CheckCursorStatus();
					BtnToClick.FindAdapter<Unknown>().Click(coordinates, 200);
				}
				
				CheckCursorStatus();
				if(BtnToClick.Exists(5000)){
					goto CLICK_OBJECT_2;
				}
Now I need an equivalent to this function thaiking as a parameter an Adapter, here is what I did :

Code: Select all

                        public static void ClickToDisappear (Adapter BtnToClick, string coordinates)
		        {
                               string xpath = item.GetPath().ToString();
                                CLICK_OBJECT_2:
				{
					BtnToClick.MoveTo(coordinates);
					CheckCursorStatus();
					BtnToClick.Click(coordinates, 200);
				}
				
				CheckCursorStatus();
				Element em = null;
			        if(Host.Local.TryFindSingle(xpath, 5000, out em));
					goto CLICK_OBJECT_2;
				}
is my code correct, does it do the same thing as the first function?

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

Re: repoItemInfo's exist function equivalent in adapter object

Post by odklizec » Tue Feb 14, 2017 10:52 am

Hi,

I'm somewhat lost here ;) I'm not quite sure what exactly is your problem with RepoItemInfo class and why you want to use Adapter class instead of RepoItemInfo?

In your initial post you mentioned, that if you pass an element using Adapter class and the passed element does not exists, method throws an exception. This is exactly why you should use RepoItemInfo class instead.

I would personally use code like this:

Code: Select all

public static void ClickToDisappear (RepoItemInfo btnToClick, string coordinates)
	{
		CheckCursorStatus();
		if(btnToClick.Exists(5000))
		{
			Ranorex.Unknown btnToClickAdapter = btnToClick.CreateAdapter<Unknown>(true);
			btnToClickAdapter.MoveTo(coordinates);
			CheckCursorStatus();
			btnToClickAdapter.Click(coordinates, 200);
		}				
	}
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

yassine
Posts: 11
Joined: Mon Jan 09, 2017 12:49 pm

Re: repoItemInfo's exist function equivalent in adapter object

Post by yassine » Tue Feb 14, 2017 11:59 am

Hi odklizec,

Thanks for your reply, in my case I need to use an adapter instance in my custom function,

Code: Select all

public static void ClickToDisappear (Adapter ElementToClick, string coordinates)
the goal from my function is the reclick again in case that an element did not disappear from the screen (Because in some cases the click effect in the first time do not work because of the environement is slow or whatever)

In case I was using RepoItemInfo it worked fine, but now and because we need to integrate Ranorex with an MBT solution I need to change function signature to use Adapter object.

Hope my problem was well explained :) .

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

Re: repoItemInfo's exist function equivalent in adapter object

Post by odklizec » Tue Feb 14, 2017 12:14 pm

Hi,

I'm afraid, I still don't get it ;) I still somehow don't understand, why it's so important for you to use Adapter class in custom method, instead of RepoItemInfo, which is clearly better solution?

Additionally, doing a workaround for potentially missed/not performed click is, in my opinion, not a very good idea. You should rather investigate the reason of failed clicks (either the AUT or test environment problem). You see, if your test randomly fails, it's not stable and therefore, not very usable in a long-term run, not to mention day-to-day usage.
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

yassine
Posts: 11
Joined: Mon Jan 09, 2017 12:49 pm

Re: repoItemInfo's exist function equivalent in adapter object

Post by yassine » Tue Feb 14, 2017 3:32 pm

Hi :)

In the near future we will use an MBT solution that has an integration with Ranorex and a feature to edit scripts automaticaly on the MBT Side when we edit scripts on Ranorex side.

The problem is that the integration they have is based on adapter object, and testing the features of the MBT solution using RepoItemInfo Objects didn't work, so we need to change functions definitions to use Adapter instead of RepoItemInfo.

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

Re: repoItemInfo's exist function equivalent in adapter object

Post by odklizec » Tue Feb 14, 2017 3:50 pm

OK, I now understand. In this case, I would suggest to ask the author of integration to adapt it to work with RepoItemInfo as well. As mentioned, you will most experience exceptions caused by not existing elements, passed as Adapters. And the only reasonable solution is using RepoItemInfo class.
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