Although I found similar problems none could provide a sufficient answer to my problem.
I came across an older VBScript that is used for communication and synchronization with Outlook. Somebody (not me) gets a strange error when running the script:
Script:
"Some path"
Line: 286
Character: 9
Error: Invalid process or invalid argument
Code: 800A0005
Source: Runtime Error in VBScript
Now what I want to know is WHY that error occurs. Just a general interpretation of the error. But first here is the relevant code:
Set refnum = open_outputfile(outputfileverz & outputfilename_short)
If (errcode = 0) Then
If (check_textfile(refnum)) Then
refnum.WriteLine (strOutput)
errcode = close_outputfile(outputfileverz & outputfilename_short, outputfilename_short, refnum)
If (errcode = 0) Then
If (logging) Then 'mit Protokollierung
If (check_textfile(logrefnum)) Then
logrefnum.WriteLine ("--- " & Now() & " ---" & crlf & outputfilename_short & ":" & crlf & strOutput)
If (gBAbort) Then
logrefnum.WriteLine (errtext(33)) ' Abbruch durch den Benutzer
End if
End If
End If
Else
ok = false
End If
Else
'errdetails = outputfileverz & outputfilename_short wurde schon in open_outputfile erstellt
ok = False
End If
End If
Line 286 is:
refnum.WriteLine (strOutput)
There are of course two other functions involved (open_outputfile/check_textfile) but they only return a document reference and check if it is a valid reference respectively.
Now I tried to reproduce the error and there is a problem: No matter what I do I don't get this error. I've tried empty references, empty strings, wrote all kind of variable types but I always get other errors.
Can anybody tell me how or why this happens?
Related
I am working on Selenium ALM integration.
I have scripts which are developed in ruby and I want to trigger the test execution selenium scripts from HP ALM and write test execution result back to HP ALM.
Please help me on this.
I think your best option would be to
create a test of type VAPI-XP-TEST (you need to mention this at test creation as it cannot be changed later)
Then, you need to provide the script language (VBScript is as good option)
Then, you need to provide the test type which is your case is
probably console application test, other options being : COM/DCOM
server test, Java Class Test, Web Service (Soap), Test.
Then, leave the 'Application Executable File' empty
The above sequence will create the initial script
Below an example of a test script (ALM side) created with the above method in which I added the code to launch (see CODE ADDED below) an external program (ruby.exe)
' vbscript [VBScript]
' Created by Application Lifecycle Management
' 4/20/2018 16:34:54
' ====================================================
' ----------------------------------------------------
' Main Test Function
' Debug - Boolean. Equals to false if running in [Test Mode] : reporting to Application Lifecycle Management
' CurrentTestSet - [OTA COM Library].TestSet.
' CurrentTSTest - [OTA COM Library].TSTest.
' CurrentRun - [OTA COM Library].Run.
' ----------------------------------------------------
Sub Test_Main(Debug, CurrentTestSet, CurrentTSTest, CurrentRun)
' *** VBScript Limitation ! ***
' "On Error Resume Next" statement suppresses run-time script errors.
' To handle run-time error in a right way, you need to put "If Err.Number <> 0 Then"
' after each line of code that can cause such a run-time error.
On Error Resume Next
' clear output window
TDOutput.Clear
' TODO: put your code here
' === CODE ADDED START ===
strCommandLine = "C:\\<pathtoyour ruby interpreter>\\bin\\ruby.exe c:\\test.rb" & CurrentTSTest.name
Set wshShell = CreateObject("WScript.Shell")
iReturn = wshShell.Run(strCommandLine, 1, True)
if iReturn = -1 then
CurrentRun.Status = "Failed"
CurrentTSTest.Status = "Failed"
else
CurrentRun.Status = "Passed"
CurrentTSTest.Status = "Passed"
end if
' === CODE ADDED END ===
If Not Debug Then
End If
' handle run-time errors
If Err.Number <> 0 Then
TDOutput.Print "Run-time error [" & Err.Number & "] : " & Err.Description
' update execution status in "Test" mode
If Not Debug Then
CurrentRun.Status = "Failed"
CurrentTSTest.Status = "Failed"
End If
End If
End Sub
The above is an example for VBScript where your actual selenium script is c:\test.rb (see in code above)
Then, you need to create a test instance in the test lab and select this test for running
example of test.rb
puts "running the script #{ARGV[0]}"
# put your test code here
# in the end exit -1 => failure or 0 success
exit -1
#exit 0
You can use the same test.rb or different ones according to your needs.
I've tested the above setup and it works for me (ALM 12.53)
Good Luck :)
I have a weird problem with QTP 11. The following piece of code worked so far, but suddenly stopped working and throws Object does not support this property or method.: 'objPage.Link' for the line with 'if link exist'
Set objBrowser = Browser("creationtime:=" & Desktop.ChildObjects(oDesc).Count - 1 & "")
Set objPage = objBrowser.Page("title:=.*")
If objPage.Link("class:=menu_link_tab_.*", "html id:=.*DesktopTab").Exist(3) Then
msgbox "ok"
End If
Can anyone tell me what is wrong and/or how to do it right?
EDIT: I solved this but still have no idea what happened. I just cut this part from QTP script and pasted it into Notepad and then copied it from Notepad to QTP. Everything works fine. I did not change anything... Any ideas what the hell happened are welcomed.
ANOTHER EDIT: The problem reappears randomly. With no changes to anything I can just run the test 10 times to have it fail randomly with the 'Object does not support this property or method' message
I have a startBrowser function where I set the objPage and objBrowser :
Function startBrowser(vURL)
Dim oDesc
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate vURL
Window("hwnd:=" & IE.HWND).Maximize
Set oDesc = Description.Create
oDesc( "micclass" ).Value = "Browser"
If Desktop.ChildObjects(oDesc).Count > 0 Then
Set objBrowser = Browser("creationtime:=" & Desktop.ChildObjects(oDesc).Count - 1 & "")
End If
Set objPage = objBrowser.Page("title:=.*")
End Function
I have added lots of msgboxes with GetROProperty to verify whether the objects are ok. They seem to be.
Now my function to click the link looks like this :
Function clickMainMenuLink(vIdentifier)
Set objLink = objPage.Link("class:=menu_link_tab_.*", "html id:=.*" & vIdentifier, "index:=0")
If objLink.Exist(timeOut) Then
objLink.Click
Else
reporter.ReportEvent micFail, "Click the " & vIdentifier & " menu link", "Cannot find the " & vIdentifier & " menu link"
ExitTestIteration
End If
End Function
So at the moment my test just opens the browser and clicks a link as I try to debug the thing, but it still fails or passes randomly. The run error indicates line with 'Set objLink'. Any ideas for further debugging? I'm on QTP11 and IE8 if it matters.
From your error does not support this property or method: objPage.Link it would appear that the problem isn't with the .Exist part of line but the .Link part (you can verify this by separating the line into two lines and see which fails
set objLink = objPage.Link("class:=menu_link_tab_.*", "html id:=.*DesktopTab")
If objLink.Exist(3) Then
From your comment it seems that you're creating objPage in a different location from where you're using it, I suggest making sure that the object arrives OK.
Thanks Motti, your reasoning was right. The problem was with the objPage part. Despite the fact that I could read every property of objPage in a function QTP sometimes just did not see this objPage as a Page object. I guess it has something to do with not declaring type explicitly, but that's just a guess. As a dirty workaround I set up the objBrowser and objPage in every function now and it works 100%.
In Access 2007, I have a form to add a new contact to a table:
RecSet.AddNew
RecSet![Code_Personal] = Me.txtCodePersonal.Value
RecSet![FName] = Me.TxtFName.Value
RecSet![LName] = Me.txtLName.Value
RecSet![Tel Natel] = Me.txtNatTel.Value
RecSet![Tel Home] = Me.txtHomeTel.Value
RecSet![Email] = Me.txtEmail.Value
RecSet.Update
This has worked so far, and the contact has successfully been aded. But I'm having two problems:
I want to display a messagebox to tell the user the contact was successfully added
If the contact was not successfully added because
A contact with this name already exists
A different issue
Then display a message box "Contact already exists" or "error occured" respectively.
My idea of doing this is:
If recSet.Update = true Then
MsgBox "Paolo Bernasconi was successfully added"
Else if RecSet![FName] & RecSet![LName] 'already exist in table
MsgBox "Contact already exists"
Else
MsgBox "An unknown error occured"
I know this code is wrong, and obviously doesn't work, but it's just to give you an idea of what I'm trying to achieve. Thanks for all your help in advance.
Add an error handler to your procedure.
On Error GoTo ErrorHandler
Then display the "success" notice to user immediately after updating the recordset.
RecSet.Update
MsgBox RecSet![FName] & " " & RecSet![FName] & _
" was successfully added"
If the update attempt fails, flow control passes to the ErrorHandler section.
ErrorHandler:
MsgBox "Oops!"
Undoubtedly you want something more refined than an "Oops!" message. A slick approach is to use a Select Case block to customize the response based on error number.
Determine whether the contact exists already before attempting to add it.
strCriteria = "Fname = '" & RecSet![FName] & "' AND LName = '" & _
RecSet![LName] & "'"
Debug.Print strCriteria
If DCount("*", "YourTable", strCriteria) > 0 Then
' do not attempt to add it again
MsgBox "Contact already exists"
Else
RecSet.AddNew
' and so forth
End If
Check the Debug.Print output in case I made a mistake when building strCriteria.
The intention here is to avoid the duplication error condition ... by only attempting to add a contact which doesn't exist. So that error should not happen, and any other errors will be dealt with by the error handler.
I have a vbscript that creates a registry entry on a Windows Server 2003 machine. This script has been working fine for about a year now, but recently it just stopped working. I am thinking that a windows update must have changed something, maybe a security setting, whereby this script is no longer permitted to execute. The script uses the following function to create an entry in HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ for new ODBC connections:
Function CreateRegKey (sComputer, hTree, sKey)
Dim oRegistry
Dim lResult
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//" & sComputer & "/root/default:StdRegProv")
lResult = oRegistry.CreateKey(hTree, sKey)
If (lResult = 0) And (Err.Number = 0) Then
CreateRegKey = 0
Else
CreateRegKey = 1
msgbox("Create Key " & sKey & " Failed")
End If
Set oRegistry = Nothing
End Function
This function is called as follows:
Const HKEY_LOCAL_MACHINE = &H80000002
sPath = "SOFTWARE\ODBC\ODBC.INI\" & DataSourceName
'Create ODBC entry
If (0 = CreateRegKey(sComputer, HKEY_LOCAL_MACHINE, sPath)) Then
....
Else
....
End If
Does anyone know of a windows update that could have caused this script to suddenly stop working? The script stops on the following line:
lResult = oRegistry.CreateKey(hTree, sKey)
It does not give an error or anything. It just stops on that line.
Anyone got an idea what is going wrong here and how I could fix it? Thanks.
EDIT: I now get the error number returned by CreateKey. It returns the following:
Err.Number: -2147023533
Err.Description: Cannot start a new logon session with an ID that is already in use
Does anyone know what is causing this and how to work around it? Thanks.
The description for the error code -2147023533 (0x80070553) is:
Cannot start a new logon session with an ID that is already in use.
A search for this code and description reveals:
hotfix KB2283089 for fixing the error,
an assumption that the error is caused by KB979683,
a suggestion to reinstall service packs in order to fix the error.
Give these a try and see if it helps.
Is it possible to get the line number, where the script threw an error?
Example:
try
set a to "abc" + "123"
on error line number num
display dialog "Error on line number " & num
end try
i don't think so try statements look like this
try
set a to "abc" + "123"
on error errMsg
display dialog "ERROR: " & errMsg
end try
but you could look at script debugger which will show you what line your error occurred on
another alternative is to get textmate which goes for $52 when it errors it gives you the line number and is also useful for writing code in many languages
Actually the on error syntax include the error number also (but no line number):
try
set a to "abc" + "123"
on error errorMessage number errorNumber
log ("errorMessage: " & errorMessage & ", errorNumber: " & errorNumber)
end try
You can use semaphores to mark your progress:
try
... your code here ...
set lineNumber to "17"
... more code here
set lineNumber to "18"
... more code here
on error errorMessage number errorNumber
log ("(line #" & lineNumber & ") errorMessage: " & errorMessage & ", errorNumber: " & errorNumber)
end try
And I'll 2nd mcgrailm's recommendation for Script Debugger!
Satimage's Smile is of great help when it comes to debugging an applescript.
And it's free.
Plus it's French (hehe).
Definitely a great tool !
Late to the party here, but in respect to Script Debugger, here is a perhaps useful response from Mark Alldritt:
Yes, turn on Break On Exceptions. This cause the debugger to break at the point where an exception is thrown. The debugger also shows the sate of all known variable at the time the exception is thrown. You can then step into the 'on error' block.
Cheers
-Mark
On 2013-01-24, at 8:43 AM, Dan wrote:
When a script throws an error in a Try block, is there any reasonable way to display the line where the error occurred?