Selenium Ruby script and HP ALM integration - ruby

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 :)

Related

why does LogonHostedExchangeMailbox get stuck with no error message?

We are using Redemption Library to access our e-mails. Scripts are automated on server and triggered by Task Scheduler at regular intervals. After server reboots we usually experience the problem with Session.Logon, since the user needs to log on again.
To avoid this problem, we are trying now to use LogonHostedExchangeMailbox Session method. Due to unknown reason the script gets stuck at this command. Could anyone advise what the reason might be? Here is the sample:
set Session = CreateObject("Redemption.RDOSession")
InboxName = "xxx#domain.com"
Session.LogonHostedExchangeMailbox InboxName,InboxName, "pwd" 'the script gets stuck here and does not throw any errors.
set oFolder = Session.GetFolderFromPath("\\"&InboxName&"\Inbox")
set items = oFolder.items
i = items.count
do until i = 0
if items.count > 0 then
set Mail = Items.Item(i)
wscript.echo Mail.Subject
'wscript.echo Mail.Body
end if
i = i - 1
loop
Session.Logoff
Thanks.

IDL compilation doesnt return failure status

I dont have much experience with IDL but i need to fix a bug where in the compilation failure status needs to be returned to the calling script.
cat << ENDCAT > something.pro
PRINT, "Start"
PRINT, "Compiling functions needing early compile"
#do_early_func
PRINT, "Compiling remaining functions"
#do_other_func
PRINT, "Running: resolve_all"
resolve_all
EXIT
ENDCAT
setenv IDL_STARTUP something.pro
$IDL_DIR/bin/idl
The above content exists in a script called make_program which is called by another script called the build_script
The problem i am facing is that even if 'resolve_all' results in a compilation failure, the make_program always returns a true to the build_script making it think the compilation succeeded when it actually didnt. How can i return the failure status back to the calling script?
The EXIT routine has a STATUS keyword that can return the exit status of the script. So something like:
exit, status=status_code
To determine if RESOLVE_ALL completed correctly, you may need to do a CATCH block. The easiest way is probably to wrap RESOLVE_ALL in your own routine that has an ERROR keyword that returns whether the RESOLVE_ALL succeeded.
I'm not sure where I picked this up but you'll need two routines:
function validate_syntax_helper, routineName
compile_opt strictarr, hidden
catch, error
if (error ne 0) then return, 0
resolve_routine, routineName, /either, /compile_full_file
return, 1
end
and
function validate_syntax, routineName
compile_opt strictarr, hidden
oldquiet = !quiet
!quiet = 1
catch, error
if (error ne 0) then return, 0
; Get current directory
cd, current=pwd
o = obj_new('IDL_IDLBridge')
o->execute, '#' + pref_get('IDL_STARTUP')
; Change to current directory
o->execute, 'cd, ''' + pwd + ''''
; Validate syntax
cmd = 'result = validate_syntax_helper(''' + routineName + ''')'
o->execute, cmd
result = o->getVar('result')
obj_destroy, o
!quiet = oldquiet
return, result
end
You then call validate_syntax, which returns 1 when it can compile and 0 when it can't. I don't think this can be used from the IDL virtual machine since it uses execute, but maybe that doesn't matter to you. You'll have to manually run this on all your routines to be compiled instead of running resolve_all.

VBscript error 800A0005

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?

Getting Error as 'User defined type not defined' in the code

Greetings for the day,
Hi, I am a beginner using vb 6.0. I am using the following code and getting 'user defined type not defined'.the code is below.the line where i get error is highlighted.Kindly help.should i add some references or components?if so,what it would be. your timely and kindly help will be much more helpful for me
Public Sub LoadDocument()
Dim xDoc As MSXML2.DOMDocument
Set xDoc = New MSXML2.DOMDocument
xDoc.async = False
xDoc.validateOnParse = False
If xDoc.Load("C:\Users\284582\Desktop\XML1.xml") Then
DisplayNode xDoc.ChildNodes, 0
End If
End Sub
' Error on this line'
Public Sub DisplayNode(ByRef Nodes As MSXML.IXMLDOMNodeList, _
ByVal Indent As Integer)
Dim xNode As MSXML.IXMLDOMNode
Indent = Indent + 2
For Each xNode In Nodes
If xNode.NodeType = NODE_TEXT Then
Debug.Print Space$(Indent) & xNode.ParentNode.nodeName & _
":" & xNode.NodeValue
End If
If xNode.HasChildNodes Then
DisplayNode xNode.ChildNodes, Indent
End If
Next xNode
End sub
It's MSXML2.IXMLDOMNodeList, not MSXML.IXMLDOMNodeList.
The library may be missing from your references. Try this.
Manually adding MSXML2
1. Open MS Access.
2. Database Tools ribbon
3. Visual Basic ribbon item (icon)
4. Double-click on any module to open it.
5. Tools menu
6. References…
7. Find Microsoft XML, v6.0. is in the list
a. If in list but not checked, check it and click [OK].
b. If not in the list:
i. click [Browse…] and add "c:\windows\system32\msxml6.dll"
8. [OK] your way back to the Visual Basic window.
9. Close the Visual Basic Window. You should be good to go.
Programmatically adding MSXML2
Add the following sub and function. Run the sub. Edit the sub to include a path if necessary.
Check for broken references in the library
Adapted from Add references programatically
Sub CheckXmlLibrary()
' This refers to your VBA project.
Dim chkRef As Reference, RetVal As Integer ' A reference.
Dim foundWord As Boolean, foundExcel As Boolean, foundXml As Boolean
foundWord = False
foundExcel = False
foundXml = False
' Check through the selected references in the References dialog box.
For Each chkRef In References
' If the reference is broken, send the name to the Immediate Window.
If chkRef.IsBroken Then
Debug.Print chkRef.Name
End If
'copy and repeat the next 2 if statements as needed for additional libraries.
If InStr(UCase(chkRef.FullPath), UCase("msxml6.dll")) <> 0 Then
foundXml = True
End If
Next
If (foundXml = False) Then
'References.AddFromFile ("C:\Windows\System32\msxml6.dll") <-- For other than XML, modify this line and comment out line below.
RetVal = AddMsXmlLibrary
If RetVal = 0 Then MsgBox "Failed to load XML Library (msxml6.dll). XML upload/download will not work."
End If
End Sub
Add XML reference to the library
Developed by Chris Advena. Thanks to http://allenbrowne.com/ser-38.html for the insight.
Public Function AddMsXmlLibrary(Optional PathFileExtStr As String = "C:\Windows\System32\msxml6.dll") As Integer
On Error GoTo FoundError
AddMsXmlLibrary = 1
References.AddFromFile (PathFileExtStr)
AllDone:
Exit Function
FoundError:
On Error Resume Next
AddMsXmlLibrary = 0
On Error GoTo 0
End Function

VBS remove printe -- on error resume next

When I run the script below I get an error that the first printer does not exist. This is true, the first printer is not connected, so the output gives me this:
"c:\temp\rmprintlong.vbs(4, 1) WSHNetwork.RemoveNetworkDrive: This network connection does not exist." and then the script dies...this is the issue: the script dies!!!
I still need it to remove the second printer in this script! If it doesn't find one of the printers in the script, I still need it to resume with the next remove printer command!
Here is the code I am using:
Set WshNetwork = WScript.CreateObject("WScript.Network")
PrinterPath = "\\p1\(SW)_HP_LaserJet_8150_Series_PCL"
WshNetwork.RemovePrinterConnection PrinterPath, true, true
PrinterPath = "\\p1\(NE)_HP_LaserJet_5M"
WshNetwork.RemovePrinterConnection PrinterPath, true, true
Wscript.Quit(1)
Do I simply add "On Error Resume Next" under the first line of the code..?
That depends on the quality requirements of your script. If it doesn't matter whether it succeeds or fails, put the OERN in the first line (and meet the standards of the Scripting Guys).
A compromise/minimal impact/pythonic variation of your script:
Set WshNetwork = WScript.CreateObject("WScript.Network")
PrinterPath = "\\p1\(SW)_HP_LaserJet_8150_Series_PCL"
On Error Resume Next ' don't care if this fails
WshNetwork.RemovePrinterConnection PrinterPath, true, true
On Error GoTo 0 ' open eyes again
PrinterPath = "\\p1\(NE)_HP_LaserJet_5M"
WshNetwork.RemovePrinterConnection PrinterPath, true, true
Wscript.Quit 1 ' no parameter list () when calling a sub
This would restrict the "I don't care" section to one single operation.

Resources