Declare an Item as a new variable

Best practices, code snippets for common functionality, examples, and guidelines.
bta
Posts: 5
Joined: Thu Sep 01, 2016 9:26 am

Declare an Item as a new variable

Post by bta » Thu Sep 01, 2016 11:10 am

Hi,
I have the following problem:

I our SUT there are a window that contains three tables (with diférents path).
In a code module, I would use one of these three tables (switch a condition) :
Ranorex.Table tableau = null;
			
			switch (_numero_de_tableau)
			{
				case "1" :
					 tableau = repo.Superviseur_Logistique.MainGrid.Tableau_Cde_Frs_et_OF;
				case "2" :
					 tableau = repo.Superviseur_Logistique.MainGrid.Tableau_Stock;
				case "3" :
					 tableau = repo.Superviseur_Logistique.MainGrid.Tableau_Cde_Client_et_OF;
			} 
                         tableau.Cell_var_txt_ChildIndex.Click();
at the execution of the code, I got the following error :

Impossible de convertir implicitement le type 'GestionCommerciale.GestionCommercialeRepositoryFolders.Tableau_Cde_Frs_et_OFFolder' en 'Ranorex.Table' (CS0029)

Impossible de convertir implicitement le type 'GestionCommerciale.GestionCommercialeRepositoryFolders.Tableau_StockFolder' en 'Ranorex.Table' (CS0029) -

Impossible de convertir implicitement le type 'GestionCommerciale.GestionCommercialeRepositoryFolders.Tableau_Cde_Client_et_OFFolder' en 'Ranorex.Table' (CS0029) -


Thank you in advance for your help

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

Re: Declare an Item as a new variable

Post by RobinHood42 » Fri Sep 02, 2016 9:33 am

Hello bta,

The exception is thrown whenever you try to assign an object with a wrong data type. Your repository items aren't of type "Ranorex.Table" and cannot implicitly casted and assigned to your object: "Ranorex.Table tableau"

Please check the data type of your repo items.

Hope this helps.

Cheers,
Robin

bta
Posts: 5
Joined: Thu Sep 01, 2016 9:26 am

Re: Declare an Item as a new variable

Post by bta » Fri Sep 02, 2016 10:32 am

Thank you RobinHood42 for your reply

You are right !! indeed basically they were tables, but I forgot that I converted them to "Rooted Folder" in order to add items (rows, cells,...). So that's why their type is no longer "Ranorex.Table".

I don't Know if there is a general type of "Rooted Folder" (like "Ranorex.Folder" or "Ranorex.RootedFolder",...)

Any ideas please?

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

Re: Declare an Item as a new variable

Post by RobinHood42 » Fri Sep 02, 2016 1:16 pm

Hi,

this should not cause any issues. Please use Ranorex Spy to track the elements once again, please check out their "PreferredCapability". Spy -> Advanced Tab -> General
ElementPreferredCapability.png
If you still have issues finding the correct adapter type, please upload a screenshot or Ranorex snapshot of the specific element.

Cheers,
Robin
You do not have the required permissions to view the files attached to this post.

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

Re: Declare an Item as a new variable

Post by krstcs » Fri Sep 02, 2016 2:53 pm

For rooted folders, you need to use the "Self" property.


RanorexTable table = myRootedFolder.Self;
Shortcuts usually aren't...

bta
Posts: 5
Joined: Thu Sep 01, 2016 9:26 am

Re: Declare an Item as a new variable

Post by bta » Fri Sep 02, 2016 4:03 pm

Hi Robert,

Thanks again for your help.

When I check the item with Ranorex Spy, it is indeed a table, as you see in the screenshot as you see bellow :
Capture.PNG
[/size]
But it does not work when I declared the variable with like Ranorex.Tableas
I don't know if the cause of the issue is the fact of converting the table to rooted folder ! :?:

(you will also find attached the Snapshot of one table)


Greeting,
Bilel
You do not have the required permissions to view the files attached to this post.

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

Re: Declare an Item as a new variable

Post by krstcs » Fri Sep 02, 2016 4:18 pm

Please read my post above your last one.
Shortcuts usually aren't...

bta
Posts: 5
Joined: Thu Sep 01, 2016 9:26 am

Re: Declare an Item as a new variable

Post by bta » Mon Sep 05, 2016 9:31 am

Hi krstcs
Thank you for your reply.

Your suggestion (the self property) solved my first problem (implicitly convert the type "RootedFolder" to "Ranorex.Table").
But the problem now is that by declaring the variable as "Ranorex.Table" (while it is "RootedFolder"), it is not possible to access to the children Items in my Repository as you will see in the code, and the Errors, below :

Ranorex.Table tableau = repo.Superviseur_Logistique.MainGrid.Tableau_Cde_Frs_et_OF.Self;
			switch (_numero_de_tableau)
			{
				case "1" :
					tableau = repo.Superviseur_Logistique.MainGrid.Tableau_Cde_Frs_et_OF.Self;
				case "2" :
					tableau = repo.Superviseur_Logistique.MainGrid.Tableau_Stock.Self;
				case "3" :
					tableau = repo.Superviseur_Logistique.MainGrid.Tableau_Cde_Client_et_OF.Self;
			}
     repo.ChildIndex = tableau.Entete_du_tableau.HeaderText.Element.Parent.Parent.Parent.ChildIndex.ToString();
				Validate.IsTrue(tableau.Lignes_du_tableau.Cellule_var_ChildIndex.Text == donnee[2]);


ERRORS :

'Ranorex.Table' ne contient pas une définition pour 'Entete_du_tableau' et aucune méthode d'extension 'Entete_du_tableau' acceptant un premier argument de type 'Ranorex.Table' n'a été trouvée (une directive using ou une référence d'assembly est-elle manquante ?)

'Ranorex.Table' ne contient pas une définition pour 'Lignes_du_tableau' et aucune méthode d'extension 'Lignes_du_tableau' acceptant un premier argument de type 'Ranorex.Table' n'a été trouvée (une directive using ou une référence d'assembly est-elle manquante ?)



Greeting,

Bilel

bta
Posts: 5
Joined: Thu Sep 01, 2016 9:26 am

Re: Declare an Item as a new variable

Post by bta » Tue Sep 06, 2016 11:00 am

I don't know if I was clear in my question ...
Let me explain :
As you will see bellow, In my repository, I have three tables converted to "ROOTED FOLDER" :
Capture.PNG
In a code module I want to use one of these three tables, switch a condition.
So for that, I would declare at the beginning a general variable of type "ROOTED FOLDER".Then, depending on the condition, I would like to be able to use this variable (Folder), as well as items in this folder :
Capture1.PNG
Do not hesitate if you have any suggestions

Thank you for advance for your help
You do not have the required permissions to view the files attached to this post.