Assign variable to Repository Element

Ask general questions here.
erman
Posts: 15
Joined: Tue May 15, 2012 3:53 pm

Assign variable to Repository Element

Post by erman » Fri Jun 01, 2012 7:23 pm

Hi,

I have an element within the repository that is referenced many times within different C# methods within the same class. I would like to create a variable for the element stored in the repository.

An example of what I am trying to accomplish is below, although not working :(

Button myButton = myrepo.ButtonOK;
myButton.Click()



Thanks for any help.
Eric

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Assign variable to Repository Element

Post by Support Team » Tue Jun 05, 2012 5:33 pm

Hi,

You should be able to do so, are you getting an error or can you describe what is not working?
I would also suggest taking a look at the following links, there it is shown how you can access your repository via Code: Code Examples, Lesson 7: Code Modules.

Regards,
Markus
Ranorex Support Team

erman
Posts: 15
Joined: Tue May 15, 2012 3:53 pm

Re: Assign variable to Repository Element

Post by erman » Tue Jun 05, 2012 8:59 pm

Here is what I've tried:

---------------------------------------------
TruCareRegression.TruCare_Admin_Main_Repository repo = new TruCare_Admin_Main_Repository();

Ranorex.Button button_CreateQueue = repo.WebDocument_TruAdmin_Application.All_Queues.Button_CreateQueue;

button_CreateQueue.Click();
--------------------------------------------

When compiling, I'm getting:
A field initializer cannot reference the non-static field, method, or property 'TruCareRegression.Modules.Queues.mCreateQueueMandatory.repo' (CS0236) - C:\Ranorex\5.0\TruCareRegression\TruCareRegression\Modules\Queues\mCreateQueueMandatory.cs:35,43


Can you provide an example of how the above code should look? I looked through the code example but they didn't help.

Thanks,
Eric

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Assign variable to Repository Element

Post by Support Team » Wed Jun 06, 2012 11:01 am

Hi,
erman wrote:Can you provide an example of how the above code should look?
Try to use an Instance of your repository as mentioned in the link Markus provided in his last post:
public class AddCredentialEntry : ITestModule  
{  
    // Repository object to access UI Elements  
    MyFirstTestProjectRepository MyRepo = MyFirstTestProjectRepository.Instance;  
      
    /// Constructs a new instance.  
    public AddCredentialEntry()  
    {  
        // Do not delete - a parameterless constructor is required!  
    }  
      
    void ITestModule.Run()  
    {  
        Mouse.DefaultMoveTime = 300;  
        Keyboard.DefaultKeyPressTime = 100;  
        Delay.SpeedFactor = 1.0;  
          
        // Click 'Add Entry' Button MainMenu  
        MyRepo.MainForm.Edit.Click();  
        ...
Regards,
Tobias
Ranorex Team

erman
Posts: 15
Joined: Tue May 15, 2012 3:53 pm

Re: Assign variable to Repository Element

Post by erman » Wed Jun 06, 2012 2:10 pm

Hi,

My example has the repository instance already set. I wish to set a variable to a specific button element within the repository.

The problem is setting a C# variable to an element in the repository.

Eric

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Assign variable to Repository Element

Post by Support Team » Wed Jun 06, 2012 3:39 pm

Hi,

as I can see it seems like the problems comes not with setting the variable, but with trying to access the not-static variable "repo" within a static method.
Please try to find out where this access is located and fix it.

Kind regards,
Tobias
Ranorex Team