How to run userCodeModule and print variable value in consle

Ask general questions here.
kumprave5
Posts: 33
Joined: Wed Jul 18, 2018 9:55 pm

How to run userCodeModule and print variable value in consle

Post by kumprave5 » Wed Jul 18, 2018 10:11 pm

I have two questions:

1. I have a UserCodeModule which contains 10-15 lines of code but when i click on run, it always update whole thing (488 lines) of code with pop up heading "waiting for code generation to complete" and it takes almost 8-10 seconds to complete. I just want to compile those 15 lines not everything. How do i do that?

2. There are two ways to print the message:
a. in report
b. in console
Now, my question is how to print in console and how to locate the console window?
I have tried System.Diagnostics.Debug.Write("This is my output") but nothing is printing in console. (I just want to print some variable values and wanna see if it is coming correctly so for that i can't print in report that's why i want to print my value sin console.)

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

Re: How to run userCodeModule and print variable value in consle

Post by odklizec » Thu Jul 19, 2018 2:26 pm

Hi,

As for 1), I'm afraid, there is no way to compile just the changed lines. BTW, which version of Ranorex do you use? The most recent 8.2 is somewhat faster, when it comes to loading/building solutions. If you are using something older, try to upgrade to 8.2.

As for 2), are you sure the debugger is attached when you trying to run your test? You see, the debugger is by default disabled so you must explicitly enable it. Then the System.Diagnostics.Debug.Write should work as expected ;)
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

kumprave5
Posts: 33
Joined: Wed Jul 18, 2018 9:55 pm

Re: How to run userCodeModule and print variable value in consle

Post by kumprave5 » Thu Jul 19, 2018 2:56 pm

Thank you for the response.
1. I am using version 7. So, do you mean if I change anything even a single of code and hit run, it will create a new built?
2. I enabled the debugger and hit "Run with Debugger", but it bottom under the output view "it automatically switches to the built mode and generate a built and nothing printing in console. I really dont know why it is why it automatically switches to built mode and why not printing anything. Please suggest something or else if you have any example please let me know. Thank you

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

Re: How to run userCodeModule and print variable value in consle

Post by odklizec » Thu Jul 19, 2018 3:24 pm

As for 1), yes, each test run creates new build. But as mentioned, things are noticeably faster in 8.2. Just give it a try (even in trial mode).

As for 2), System.Diagnostic.Debug.Write (I would suggest to use WriteLine instead) sends the output string to Output window.
If you want to write something to console window, use Console.WriteLine instead...
DebugOutput.png
DebugOutput.png (61.69 KiB) Viewed 275 times
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

kumprave5
Posts: 33
Joined: Wed Jul 18, 2018 9:55 pm

Re: How to run userCodeModule and print variable value in consle

Post by kumprave5 » Thu Jul 19, 2018 4:16 pm

1. Output is coming now, but the values the values are coming two times. Please look at the screenshot, I am printing value "1"only one but it is printing twice. Any specific reason?

2. How did you get the console window. I am using Console.Write("This is console output"); but nothing console window is not opening.
Attachments
Twice.PNG
Twice.PNG (24.36 KiB) Viewed 273 times

kumprave5
Posts: 33
Joined: Wed Jul 18, 2018 9:55 pm

Re: How to run userCodeModule and print variable value in consle

Post by kumprave5 » Mon Jul 23, 2018 1:57 pm

Please reply to above question.

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

Re: How to run userCodeModule and print variable value in consle

Post by odklizec » Mon Jul 23, 2018 2:37 pm

Hi,

I'm not sure about 1). Could you please upload your project? BTW, I believe you are using an old version of Ranorex? Try your project with most recent 8.2.

As for 2), you must build your app as "Console application" to be able to see the console window...
ConsoleApp.png
ConsoleApp.png (16.14 KiB) Viewed 249 times
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

kumprave5
Posts: 33
Joined: Wed Jul 18, 2018 9:55 pm

Re: How to run userCodeModule and print variable value in consle

Post by kumprave5 » Mon Jul 23, 2018 9:43 pm

Hi
Thank you so much for the prompt response.

1. Yes, I am using older version 7.0.1. I understand that you are trying to help me and i really appreciate that, however, due to my organization strict security policy I am unable to share the project in any mode. I have created the dummy code and attached the screenshot with this message. I hope this will provide you more clarity on my question. (Please look for blue underlines)

2. I turned on "Console Application" as output type. However, console window opens and closes automatically on completion of execution. Is there any setting that I need to change to remain it open. I just tried Console.Read() or any other way possible?
Attachments
DoubleOutput.PNG
DoubleOutput.PNG (37.28 KiB) Viewed 243 times

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

Re: How to run userCodeModule and print variable value in consle

Post by odklizec » Tue Jul 24, 2018 8:52 am

Hi,

In my case (Ranorex 8.2), the same code returns just one line in output window. So I guess it's somehow related to your old Ranorex version? As mentioned, Ranorex 7.0.1 is way too old and no longer supported. You should really consider upgrading to 8.2, otherwise, it's like hunting a long time dead animal :D

As for the console window, as far as I know, there is no option to keep the console window open after finishing the test. But I may be wrong? What would be this good for? This is why you should use Output window, eventually Ranorex report file.
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