Fail when run UserCodeModule

Ask general questions here.
HuongTT
Posts: 11
Joined: Thu Sep 15, 2016 3:55 am

Fail when run UserCodeModule

Post by HuongTT » Thu Sep 15, 2016 4:04 am

Hi, Im beginer at Ranorex.
I created UserCodeModule with sample:

Code: Select all

       public class UserCodeModule1 : ITestModule
    {
    	
    	SampleRepository repo = SampleRepository.Instance;
      
        public UserCodeModule1()
        {
            // Do not delete - a parameterless constructor is required!
        }

   
        void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;
            
            repo.MyApp.Self.Activate();
            repo.MyApp.Button終了.Press();
            repo.MyApp.Self.Close();
        }
    }
It make error:
Failed to find item 'SampleRepository.MyApp.Self'.
Please show me how to start with code module?
Thank you.

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

Re: Fail when run UserCodeModule

Post by odklizec » Fri Sep 16, 2016 8:04 am

Hi,

Without seeing your solution and your app under test, it's pretty hard to suggest what's wrong. Also, you forgot to mention Ranorex version you are using!

Are you sure the app under test is started at a time of running the code module? Additionally, make sure the xpath behind the repo.MyApp is correct! The error message means that the Ranorex cannot find any element matching the repo.MyApp xpath. Are you sure there are no dynamic attributes, which change with each start of your AUT?

BTW, is there any particular reason why you are doing this stuff in usercodemodule and not directly in recording module? I think it's better for you to use what Ranorex automatically does for you instead of messing with code modules. It greatly minimizes the risk of beginner errors ;)
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

Speedboat
Certified Professional
Certified Professional
Posts: 31
Joined: Wed Mar 25, 2015 4:44 pm
Location: Switzerland

Re: Fail when run UserCodeModule

Post by Speedboat » Fri Sep 16, 2016 3:59 pm

Hi

When I use the repository in code modules I would expect to declare the repository instance
"public static " as it is done automatically in Recording.cs files:

public static YourRepository repo = YourRepository.Instance;

may be this helps.

HuongTT
Posts: 11
Joined: Thu Sep 15, 2016 3:55 am

Re: Fail when run UserCodeModule

Post by HuongTT » Tue Sep 20, 2016 8:09 am

odklizec wrote:Hi,

Without seeing your solution and your app under test, it's pretty hard to suggest what's wrong. Also, you forgot to mention Ranorex version you are using!

Are you sure the app under test is started at a time of running the code module? Additionally, make sure the xpath behind the repo.MyApp is correct! The error message means that the Ranorex cannot find any element matching the repo.MyApp xpath. Are you sure there are no dynamic attributes, which change with each start of your AUT?

BTW, is there any particular reason why you are doing this stuff in usercodemodule and not directly in recording module? I think it's better for you to use what Ranorex automatically does for you instead of messing with code modules. It greatly minimizes the risk of beginner errors ;)
Thank you for your answer.
Im using Ranorex version 6.0.
Im new in Ranorex, then I dont know exactly what I must to prepare to run code.
Can you show me where to set xpath for MyApp? I don't see it in Guide line : lesson-7-code-modules.
When I write "repo." => Edit area will display app to choice. Is it enough?

When I read comment about ranorex and read sample code, I see it can make flexible action than only use recording module then I want to try =>but I's hard from begin.

Thank you.
HuongTT

HuongTT
Posts: 11
Joined: Thu Sep 15, 2016 3:55 am

Re: Fail when run UserCodeModule

Post by HuongTT » Tue Sep 20, 2016 8:40 am

Speedboat wrote:Hi

When I use the repository in code modules I would expect to declare the repository instance
"public static " as it is done automatically in Recording.cs files:

public static YourRepository repo = YourRepository.Instance;

may be this helps.
Thank you but it does not work on my code.

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

Re: Fail when run UserCodeModule

Post by odklizec » Tue Sep 20, 2016 8:47 am

HuongTT wrote: Thank you for your answer.
Im using Ranorex version 6.0.
Im new in Ranorex, then I dont know exactly what I must to prepare to run code.
Can you show me where to set xpath for MyApp? I don't see it in Guide line : lesson-7-code-modules.
When I write "repo." => Edit area will display app to choice. Is it enough?

When I read comment about ranorex and read sample code, I see it can make flexible action than only use recording module then I want to try =>but I's hard from begin.

Thank you.
HuongTT
Hi,

As I've mentioned, it's pretty hard to suggest something reliable without seeing your app under test and your Ranorex solution. And I think you should really start with recording, learn the Ranorex basics (from the user guide, video tutorials, Ranorex blog posts, etc.) before you start messing with custom code. Without knowledge of basics, it will be pretty hard for you to create something reliable. You see, you cannot run before you learn how to walk! ;)
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

HuongTT
Posts: 11
Joined: Thu Sep 15, 2016 3:55 am

Re: Fail when run UserCodeModule

Post by HuongTT » Tue Sep 20, 2016 9:12 am

odklizec wrote:
HuongTT wrote: Thank you for your answer.
Im using Ranorex version 6.0.
Im new in Ranorex, then I dont know exactly what I must to prepare to run code.
Can you show me where to set xpath for MyApp? I don't see it in Guide line : lesson-7-code-modules.
When I write "repo." => Edit area will display app to choice. Is it enough?

When I read comment about ranorex and read sample code, I see it can make flexible action than only use recording module then I want to try =>but I's hard from begin.

Thank you.
HuongTT
Hi,

As I've mentioned, it's pretty hard to suggest something reliable without seeing your app under test and your Ranorex solution. And I think you should really start with recording, learn the Ranorex basics (from the user guide, video tutorials, Ranorex blog posts, etc.) before you start messing with custom code. Without knowledge of basics, it will be pretty hard for you to create something reliable. You see, you cannot run before you learn how to walk! ;)
I just want to create sample code to activate calculator app of window.
I created project to recording & replay, it's work successfully, then now I want to try with code.
Thank you for your recommend.

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

Re: Fail when run UserCodeModule

Post by odklizec » Tue Sep 20, 2016 9:19 am

So the easiest way for you is to right click the recorded actions and from the appeared menu select "Convert to User Code". This way you can quickly learn how the recorded actions should look like in user code.
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