Page 1 of 1

A little help with an unclear error message

Posted: Mon Feb 22, 2010 11:06 pm
by afrosteve
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)
	
	    try:
	        #start test
	  		#StartDerivix.Start()
	  		
	  		#basic trade from TickerWindow
			#TickerWindowTradeTicket.Start()
			
			TradeTicketValidate.Start()			
	        
	    except ImageNotFoundException, e:
	        Report.Error(e.ToString())
	        Report.LogData(ReportLevel.Error, "Image not found", e.Feature)
	        Report.LogData(ReportLevel.Error, "Searched image", e.Image)
	        error = -1
	    except RanorexException, e:
	        Report.Error(e.ToString())
	        Report.Screenshot()
	        error = -1
	    except ThreadAbortException:
	        Report.Warn("AbortKey has been pressed")
	        Thread.ResetAbort()
	    except Exception, e:
	        Report.Error("Unexpected exception occured: " + e.ToString())
	        error = -1

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

Any help is appreciated!

Steve

[edited to meet the posting standards a bit better]

Re: A little help with an unclear error message

Posted: Tue Feb 23, 2010 9:40 am
by Support Team
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,
Christian
Ranorex Team

Re: A little help with an unclear error message

Posted: Tue Feb 23, 2010 4:34 pm
by afrosteve
I was unaware of the 'Run' in 'main menu->python->Run'. That will help a lot.

Thank you Christian. Much appreciated.