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
Assign variable to Repository Element
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Assign variable to Repository Element
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
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
Re: Assign variable to Repository Element
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
---------------------------------------------
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
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Assign variable to Repository Element
Hi,
Tobias
Ranorex Team
Try to use an Instance of your repository as mentioned in the link Markus provided in his last post:erman wrote:Can you provide an example of how the above code should look?
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
Re: Assign variable to Repository Element
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
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
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Assign variable to Repository Element
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
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