Pass error code from powershell to ranorex

Ask general questions here.
sujan.gurung
Posts: 4
Joined: Thu Jul 28, 2016 5:43 am

Pass error code from powershell to ranorex

Post by sujan.gurung » Thu Jul 28, 2016 6:03 am

Hi,

We using powershell scripts quite a bit in our test cases. However, my ranorex tests looks pass even though the script did not pass. Basically I want to fail the ranorex tests if powershell scripts throws some error.

Is there anyway to pass the error code to ranorex and fail the ranorex tests as a result? Using a code module is not an option at this point :(

Thanks.

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

Re: Pass error code from powershell to ranorex

Post by odklizec » Thu Jul 28, 2016 8:57 am

Hi,

Why can't you use a code module/user code? I mean, I'm afraid there is no way to achieve what you want without a bit of coding. You will most probably have to write some code to start the PS script from code, obtain and evaluate its return value and do whatever you want based of the returned value. This all is not doable with just recorded actions.
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

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Pass error code from powershell to ranorex

Post by krstcs » Thu Jul 28, 2016 3:43 pm

As Pavel asked, why would you not want, or be unable, to use user code?

I would recommend that you stop using PowerShell and use .NET code, as PS is just a wrapper around .NET and you can do anything that PS does in .NET in your Ranorex user code.

Also, PS does not return a value that can be used to determine whether the PS script passed or failed. It only returns a value indicating that the PS host process exited without error, which is not the same as a PS script failure.
Shortcuts usually aren't...

sujan.gurung
Posts: 4
Joined: Thu Jul 28, 2016 5:43 am

Re: Pass error code from powershell to ranorex

Post by sujan.gurung » Fri Jul 29, 2016 4:10 am

Thank you all for your response. I know ranorex can leverage .NET framework and that it would be an ideal solution to use code modules for these sort of tasks.

Problem is that we have a variety of team members and not everyone is capable of coding, hence we are tyring to use recording module so everyone can maintain them.

So are you saying, ranorex recoding module cannot catch an exit code from powershell script? So is it a big NO? or may be?

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

Re: Pass error code from powershell to ranorex

Post by odklizec » Fri Jul 29, 2016 7:46 am

I'm afraid, you are out of luck with achieving what you want just with recording modules.

A small advice... If you are going to use Ranorex just with Recording modules, you will be pretty limited and the Ranorex value will be significantly degraded. If there are team members in your team who can't or don't want to code, assign them to some other tasks, like preparing reference data, prepare basic repository structure (coders will still have to optimize it with variables, advanced xpaths and regexes) and other basics stuff. No matter how good Ranorex is, there are still things that cannot be done without coding skills.
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

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Pass error code from powershell to ranorex

Post by krstcs » Fri Jul 29, 2016 2:56 pm

I agree with Pavel. If you really want the full power of Ranorex, you will have to learn to use code.

Regardless of what the sales material says, there is only so much that you can do with strict record/play-back and pure recording module actions. (This is true for ANY automation system, not just Ranorex.)

And, no, as I said, there is no way to get a value from PS that tells you whether or not the PS Script worked. The PS process only returns a value indicating that the PS process exited without error, it has nothing to do with the script being run.
Shortcuts usually aren't...

fester13579
Posts: 30
Joined: Thu Feb 13, 2014 10:29 pm

Re: Pass error code from powershell to ranorex

Post by fester13579 » Tue Aug 23, 2016 3:48 pm

Another approach is to look for the validation of a success message rather than looking for a failure.

Something I often do is when using an external script like powershell or AutoIT is to throw up a msgbox saying "Passed - Waiting on ranorex to click me". I then use a WAITFOR with a very long timeout so that if the powershell in your example does not display the success message, ranorex will timeout then fail.




Hope this helps...

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Pass error code from powershell to ranorex

Post by krstcs » Tue Aug 23, 2016 4:15 pm

Fester, that is a brilliant work-around! I wish I had thought of that!

Nice one!
Shortcuts usually aren't...