18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

execute Command cscript shell

hsegurahsegura Members
edited November -1 in Sahi - Open Source
Hello team,

I have written the code to execute next command

C:\>cscript C:\mht_convert.vbs C:\xbmc.html C:\prueba.mht

with next script

_execute('cmd /C cscript C:\\mht_convert.vbs C:\\xbmc.html C:\\test.mht');

I want to run any vbs script without bat file

Comments

  • beesmanbeesman Members
    runAutoTest.wsf
    <package>
    <comment>
    </comment>
        <job  id="DoneInVBS">
            <comment>please put it To sahi_home\userdata\scripts</comment>
            <?job  debug="true"?>
            <script  language="VBScript">
    Option Explicit
    '----------------------------declare------------------------
                  Dim scriptPath, targetServer
                  Dim result 
                  Dim sahi   
                  Dim oExec  
                  Dim ieVersion
                  Dim WshShell
                  Dim fso, f, f1, fc, s
    '------------------------------------------------------------
                  scriptPath = "/01_MyFolder"
                  targetServer = "http://www.google.co.jp
    '--------------------------------------------------------
    
    Sub KillIE(ieOnly)
    On Error Resume Next
                  Dim objWMI 
                  Dim strComputer
                  Dim colProcesses
                  Dim objItem
                  strComputer = "."
                  Set objWMI = GetObject( "winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2" )
                  Set colProcesses = objWMI.ExecQuery( "SELECT * FROM Win32_Process  WHERE Name='iexplore.exe'" )
                  For Each objItem in colProcesses
                    objItem.terminate()
                  Next
                  
                  'kill wscript
                  If ieOnly = False Then
                      Set colProcesses = objWMI.ExecQuery( "SELECT * FROM Win32_Process  WHERE Name='wscript.exe'" )
                      For Each objItem in colProcesses
                        objItem.terminate()
                      next
                  End If
    End Sub
    '-------------------------function ----------------------------------------
                  result = MsgBox ("have to close all ie OK?",VbOKCancel + vbQuestion ,"Test automation")
                  If vbOK = result Then
                     KillIE true
                  Else
                    WScript.Quit 
                  End If
                  '
                  Set WshShell=WScript.CreateObject("WScript.Shell")
                  Set fso = WScript.CreateObject("Scripting.FileSystemObject")
                  If fso.FileExists (WshShell.CurrentDirectory & "/../../bin/sahi.bat") = False Then
                     MsgBox "sahi script works in %sahi_home%/userdata/scripts only!",vbOKOnly + vbInformation ,"Test automation"
                     Set WshShell = Nothing
                     Set fso = Nothing
                     WScript.Quit 
                  End if
                    scriptPath = WshShell.CurrentDirectory & scriptPath
                  If fso.FolderExists (scriptPath) = False Then
                     MsgBox scriptPath & " not exist exit",vbOKOnly + vbInformation ,"Test automation"
                     Set WshShell = Nothing
                     Set fso = Nothing
                     WScript.Quit 
                  End if
                  WshShell.Run  "..\..\tools\toggle_IE_proxy.exe enable"
    
                  ieVersion =  WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version")
                  Set f = fso.GetFolder(scriptPath)
                  Set fc = f.Files
                  sahi = "java -cp ../../lib/ant-sahi.jar net.sf.sahi.test.TestRunner "
                  sahi = sahi & scriptPath & "/${suitefile} ""C:\Program Files\Internet Explorer\IEXPLORE.EXE""  " & targetServer & " default localhost 9999 1 iexplore.exe "
                  if instr(ieVersion, "8.") = 1 Then
                      'Internet Explorer 8 needs an additional browser option “-noframemerging” to keep sessions separate.
                      sahi = sahi & """-noframemerging"""
                  end If
    
                   For Each f1 in fc
                      If Right(f1.name, Len("suite"))  = "suite" Then
                        MsgBox Replace(sahi, "${suitefile}", f1.name)
                        Set oExec = WshShell.Exec( Replace(sahi, "${suitefile}", f1.name))
                          'ActiveIE 
                        Do Until ActiveIE(WshShell)
                           WScript.Sleep 1000
                        Loop
                        
                        'sychronize
                        Do While oExec.Status = 0
                             WScript.Sleep 100
                        Loop
                        'gap
                        WScript.Sleep 1000
                       End If
                   Next
    
                  WshShell.Run  "..\..\tools\toggle_IE_proxy.exe disable"
                  KillIE false
                  Set WshShell = nothing
                  Set fso = nothing
                  WScript.Quit 
            </script>
        </job>
    </package>
    
    
    

    save as runAutoTest.wsf
    and double click will run
Sign In or Register to comment.