A little help with an unclear error message

Class library usage, coding and language questions.
Posts: 17
Joined: Mon Feb 22, 2010 10:59 pm

A little help with an unclear error message

Post by afrosteve » Mon Feb 22, 2010 11:06 pm

I'm trying to run a Ranorex project using Python and I'm getting this exception. There's no stack trace unfortunately, so I'm a little lost as to what's going on. If someone has come across this error before I'd appreciate some pointers.

Here's the exception:

Code: Select all

Microsoft.Scripting.Runtime.UnboundNameException: name 'error' is not defined
   at DLRCachedCode.Program
   at Microsoft.Scripting.ScriptCode.InvokeTarget
   at Microsoft.Scripting.ScriptCode.Run
   at IronPython.Runtime.PythonContext.CreateModule
   at IronPython.Runtime.ModuleLoader.load_module
   at Microsoft.Scripting.Actions.MatchCaller.Call3
   at Microsoft.Scripting.Actions.CallSite<Microsoft.Func<Microsoft.Scripting.Actions.CallSite,Microsoft.Scripting.Runtime.CodeContext,System.Object,System.Object[],System.Object>>.UpdateAndExecute
   at Microsoft.Scripting.Actions.UpdateDelegates.Update3
   at IronPython.Runtime.PythonContext.Call
   at IronPython.Runtime.Importer.FindAndLoadModuleFromImporter
   at IronPython.Runtime.Importer.TryLoadMetaPathModule
   at IronPython.Runtime.Importer.ImportTopAbsolute
   at IronPython.Runtime.Importer.ImportModule
   at IronPython.Runtime.Builtin.__import__
   at Microsoft.Scripting.Actions.MatchCaller.Call7
   at Microsoft.Scripting.Actions.CallSite<Microsoft.Func<Microsoft.Scripting.Actions.CallSite,Microsoft.Scripting.Runtime.CodeContext,System.Object,System.String,Microsoft.Scripting.IAttributesCollection,Microsoft.Scripting.IAttributesCollection,IronPython.Runtime.PythonTuple,System.Int32,System.Object>>.UpdateAndExecute
   at Microsoft.Scripting.Actions.UpdateDelegates.Update7
   at IronPython.Runtime.Importer.Import
   at IronPython.Runtime.Operations.PythonOps.InitializeModule
   at PythonMain.Main
Here's the code that I think is causing it. It's mostly the Ranorex generated code with a few things added. If the problem is really that 'error' is undefined, I'm not sure how that's happening.

Code: Select all

 [language=python]class Program(object):
	def Main(args):
	    Keyboard.AbortKey = System.Windows.Forms.Keys.Pause
	    error = 0
	    logFileName = "DemoTrade.rxlog"
	    Report.Setup(ReportLevel.Info, logFileName, True)
	        #start test
	  		#basic trade from TickerWindow
	    except ImageNotFoundException, e:
	        Report.LogData(ReportLevel.Error, "Image not found", e.Feature)
	        Report.LogData(ReportLevel.Error, "Searched image", e.Image)
	        error = -1
	    except RanorexException, e:
	        error = -1
	    except ThreadAbortException:
	        Report.Warn("AbortKey has been pressed")
	    except Exception, e:
	        Report.Error("Unexpected exception occured: " + e.ToString())
	        error = -1

	Main = staticmethod(Main)
Program.Main(None) [/language] 
I'm currently running Ranorex version on Windows XP with Service Pack 3.

Any help is appreciated!


[edited to meet the posting standards a bit better]

User avatar
Support Team
Site Admin
Site Admin
Posts: 12169
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA

Re: A little help with an unclear error message

Post by Support Team » Tue Feb 23, 2010 9:40 am

Hi afrosteve!
It seems you use the "error" variable in a place where this variable is not defined. I don`t think that the error is occurring in the posted code. It`s the same code as in the 'Ranorex Python Test Automation' project template. Could you please check your issue in more detail. Also consider if you use the 'Run' in 'main menu->python->Run' (calls the interpreter) you can debug your program.

Best regards,
Ranorex Team

Posts: 17
Joined: Mon Feb 22, 2010 10:59 pm

Re: A little help with an unclear error message

Post by afrosteve » Tue Feb 23, 2010 4:34 pm

I was unaware of the 'Run' in 'main menu->python->Run'. That will help a lot.

Thank you Christian. Much appreciated.