Page 1 of 1

How to run userCodeModule and print variable value in consle

Posted: Wed Jul 18, 2018 10:11 pm
by kumprave5
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.)

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

Posted: Thu Jul 19, 2018 2:26 pm
by odklizec
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 ;)

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

Posted: Thu Jul 19, 2018 2:56 pm
by kumprave5
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

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

Posted: Thu Jul 19, 2018 3:24 pm
by odklizec
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

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

Posted: Thu Jul 19, 2018 4:16 pm
by kumprave5
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.

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

Posted: Mon Jul 23, 2018 1:57 pm
by kumprave5
Please reply to above question.

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

Posted: Mon Jul 23, 2018 2:37 pm
by odklizec
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

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

Posted: Mon Jul 23, 2018 9:43 pm
by kumprave5
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?

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

Posted: Tue Jul 24, 2018 8:52 am
by odklizec
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.