Why would DOORS DXL tempFileName function return \ on Windows 7 64-bit? - file-permissions

I have IBM DOORS installed on Windows 7 64-bit. When I run the DOORS DXL function tempFileName() I get \ instead of something like C:\Users\\AppData\Local\Temp. I've googled this problem but don't see anything about the issue. Anyone have an idea?
Some sample code demonstrating the problem is...
string productDetailsFile = tempFileName()
print "productDetailsFile = " productDetailsFile "\n"
if(canOpenFile(productDetailsFile, true))
print "Can write to file\n"
Stream out = write productDetailsFile
out << "Created by " doorsname " at " dateAndTime today ""
if (null out)
{
print "Could not create file " productDetailsFile ""
halt
}
flush out
close out
string directory = getDirOf (productDetailsFile)
print "directory = " directory "\n"
string newFileName = directory NLS_("\\") NLS_("DOORS_") doorsInfo(infoVersion) (NLS_(".xml_new"))
print "newFileName = " newFileName "\nAttempting to rename now\n"
string errorMsg = renameFile(productDetailsFile, newFileName)
if (!null errorMsg)
{
print "Rename failed with error - " errorMsg "\nTrying with modified file name now\n"
newFileName = directory NLS_("DOORS_") doorsInfo(infoVersion) (NLS_(".xml_new"))
print "newFileName = " newFileName "\nAttempting to rename now\n"
errorMsg = renameFile(productDetailsFile, newFileName)
if(!null errorMsg)
print "Still fails. Stopping script now, please send the DXL Output to Support"
}
else
print "Rename successful"

The root cause was that the computer running DOORs had a "System variable" of TEMP set to
C:\Users\user-name\AppData\Local\Temp and there were no "User variables" set
for TEMP.
To get the function working:
The "System variable" for TEMP was changed to "%SystemRoot%\TEMP"
Created another "System variable" called "TMP" and set it to "%SystemRoot%\TEMP" as well.
Created 2 "User variables": TEMP and TMP and set those to "%USERPROFILE%\AppData\Local\Temp".

Related

How to concatenate strings in python

I'm trying to run a command in Python by concatenating two strings, each string has an absolute path in it. It's throwing an error. Below is the code and error for reference. Kindly correct me where am I going wrong.
Code:
def test_execute_resources_temp_dir(self):
sourcePath = Path("Gemini_logo.png").absolute()
print(sourcePath)
with tempfile.TemporaryDirectory() as tmpdirname:
destination = Path(tmpdirname).resolve("Gemini_logo_converted.jpg")
print('created temporary directory', destination)
command = "magick convert" + sourcePath +" "+ destination
formatConversion = FormatConversion()
formatConversion.executeCommand(command)
Error:
TypeError: can only concatenate str (not "WindowsPath") to str test_FormatConversion.py:65: TypeError
You can replace sourcePath with str(sourcePath).
Similarly, you can replace destination with str(destination)
command = "magick convert" + str(sourcePath) +" "+ str(destination)
This worked out for me
def test_execute_resources_temp_dir(self):
os.chdir('..')
sourcePath = Path("src\\resources\\Gemini_logo.png").absolute()
print(sourcePath)
with tempfile.TemporaryDirectory() as tmpdirname:
# os.mkdir(os.path.basename(tmpdirname))
destination = Path(tmpdirname+"/Gemini_logo_converted1.jpg")
print('created temporary directory', destination)
command = **"magick convert"+" "+ str(sourcePath) + " " + str(destination)**

Groovy split path into name and parent

I am trying to split a path into parent and the name.
When trying
String path = "/root/file"
File file = new File(path)
println("Name: " + file.name)
println("Parent: " + file.parent)
We get
Name: file
Parent: /root
With the Windows path C:\\root\\file.exe we get
Name: C:\root\file.exe
Parent: null
Is this the intended behaviour? And if it is how do I get the same result for a Windows path? (If possible please without using regular expressions)
use .replace to change the "\" to "/
String path = "C:\\root\\file.exe"
path = path.replace("\\","/")
File file = new File(path)
println("Name: " + file.name)
println("Parent: " + file.parent)

Zip multiple files using 7zip.exe in C#

I have to zip multiple files together using 7zip.exe. I have paths of two files say file1 and file2. I append the two paths using the following.
string filetozip = file1+ "\"" + file2+" "; and do the below
Process proc = new Process();
proc.StartInfo.FileName = #"C:\Freedom\7-Zip\7z.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.Arguments = string.Format(" a -tzip \"{0}\" \"{1}\" -mx=9 -mem=AES256 -p\"{2}\" ", destZipFile, filetozip , zipPassword);
proc.Start();
proc.WaitForExit();
if (proc.ExitCode != 0)
{
throw new Exception("Error Zipping Data File : " + proc.StandardError.ReadToEnd());
}
filetozip is passed as an argument above. The above code does not work properly. I am getting proc.ExitCode=1. Which is the right way to append the file paths.Is string filetozip = file1+ "\"" + file2+" "; the right way? I can have one or more files. What is the separator used?
The command line that you want to create looks like
plus the required switches (arguments quoted and space delimited).
String.Join or StringBuilder are some coding things that may be helpful

Open Relative path in VBS with OpenText and SaveAs method

ok so I have some code in a vbs file, where basically I want to open a CSV file. Perform some changes (I can work that out later) and then save it as an xls. The code works flawlessly when run with a fully qualified file path. However I need the file path to be relative. The files will always be opened and saved to the same path the script is run from. Ive looked at GetParentFolderName and GetAbsolutePathName. However I cant figure how to call the fully qualified path in the text. I've tried just putting the variable where the file name is with and without quotes, appended it with a period.
Any example on building the function or whatever, and then calling it in the code below would be a huge help.
Dim myXL
Const xlDelimited = 1
Const xlWorkbookNormal = -4143
Set myXL=CreateObject("Excel.Application")
myXL.Visible=False
myXL.WorkBooks.OpenText "file.csv", , , xlDelimited, , , , , True
myXL.DisplayAlerts=False
MORE CODE WILL GO HERE
myXL.ActiveWorkbook.SaveAs "new_file.xls", xlWorkbookNormal
myXL.DisplayAlerts=True
myXL.ActiveWorkbook.Close False
myXL.Quit
Set myXL = Nothing
You can get the path of your script by using this code that i Found at an answer about Relative Path
p = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
p should be the path to your script you can then edit "file.csv" to p & "\file.csv" and so.
To point out/emphasize that
you should never use string concatenation to build pathes; .BuildPath() is the way to go
"relative path" needs a clear "relative to what" specification
VBScript's concatenation operator is & not . (dot/period)
:
>> f = WScript.ScriptFullName
>> n = WScript.ScriptName
>> p = goFS.GetParentFolderName(f)
>> a = goFS.GetAbsolutePathName(n)
>> c = goWS.CurrentDirectory
>> WScript.Echo "c", c
>> WScript.Echo "p", p
>> WScript.Echo "?", p & n
>> Wscript.Echo "a", a
>> WScript.Echo "!", goFS.BuildPath(p, n)
>>
c C:\Documents and Settings\eh
p M:\bin
? M:\binivbs.wsf
a C:\Documents and Settings\eh\ivbs.wsf
! M:\bin\ivbs.wsf

How to use SoapUI/Groovy to add Test Results to Quality Center Test Run

I had a scenario where I need to add my test results from a SoapUI test case to a related test case in HP Quality Center. How could I go about doing this with Groovy.
Quality Center offers an OTA API to interface with it; however, it is written to use the Microsoft COM structure which Java/Groovy has no native way to consume. Lucky, there is a Groovy library, Scriptom, that allows Groovy to consume COM interfaces.
After getting every setup, this is the sample code that I came up with:
import org.codehaus.groovy.scriptom.*
def tstCaseName = "NAME_OF_TESTCASE"
tstCaseName = tstCaseName.replaceAll(/[ ]/) { match ->
"*"
}
Scriptom.inApartment
{
// Create an entry point for QC
def tdc = new ActiveXObject ('TDApiOle80.TDConnection')
// Connect to QC, Login with Credentials, connect to Project
tdc.InitConnectionEx('http://qc.example.com/qcbin')
tdc.Login('USER_NAME', 'PASSWORD')
tdc.Connect('DOMAIN_NAME','PROJECT_NAME')
// Find the set of tests in the Test Plan
tsFolder = tdc.TestSetTreeManager.NodeByPath('Root\\PATH\\TO\\TEST\\CALENDAR\\Spaces are allowed')
tsList = tsFolder.FindTestSets('NAME_OF_TEST_CALENDAR')
tsObject = tsList.Item(1)
// Get the list of TestCases in the Test Plan and filter it down to the one Test Case we are interested in
TSTestFact = tsObject.TSTestFactory
tstSetFilter = TSTestFact.Filter
tstSetFilter.Filter["TS_NAME"] = '*' + tstCaseName
TestSetTestsList = TSTestFact.NewList(tstSetFilter.Text)
tsInstance = TestSetTestsList.Item(1)
// Create a new Test Run
newRun= tsInstance.RunFactory.AddItem('Run_Auto')
newRun.Status = 'Not Completed'
newRun.Post()
newRun.CopyDesignSteps()
newRun.Post()
// Populate Auto Run Test step Data
def tsStepData = new Object[3]
tsStepData[0]='Auto Data'
tsStepData[1]='Not Completed'
tsStepData[2]='Results from Automated Test'
// Create new Test Step in the run with our Auto Run Data
tsSteps = newRun.StepFactory.AddItem(tsStepData)
tsSteps.Field['ST_ACTUAL'] = 'These are the actual results from my test!!'
tsSteps.post()
}
I had issues with the scriptom and being new to Groovy but having experience with Quality Center I wrote a tear down script for my SoapUI test that writes my results to a flat file and then I use the VBScript to pull the data in.
These scripts use hard coded values but hopefully will get you started:
VAPI-XP Script - http://ryanoglesby.net/2013/08/23/executing-soapui-from-quality-center-part-1/
'*******************************************************************
'Debug, CurrentTestSet, CurrentTest, CurrentRun
'Debug, CurrentTestSet, CurrentTSTest, CurrentRun
'**************************************************************************
Sub Test_Main(Debug, CurrentTestSet, CurrentTest, 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
'**************************************************************************
' Define the path for SOAPUI executable bat file and Project xml
' Project xml contains the test case(s) that need to be executed
'**************************************************************************
Dim trPath 'Path to test runner bat file
Dim soapResults 'Result file generated by SoapUI Groovy Script
Dim projFP 'SoapUI Project File Path
Dim spath 'Result File - Currently not using
Dim tf 'Test Factory Object
Dim ts 'Test ID
Dim TSuite 'SoapUI Test Suite Name
Dim Tcase 'SoapUI Test Case Name
Dim resultsP 'SoapUI output Report Location - Currently Not using
projFP = "C:\SOME\FILE\PATH\soapui-project.xml"
spath = "C:\File.txt"
trPath = "C:\program files\SmartBear\SoapUI-Pro-4.5.2\bin\testrunner.bat"
soapResults = "C:\Groovy_Report\test1.txt"
'Strings for SoapUI Execution
TSuite="SOAPUI_TESTSUITE_NAME"
Tcase="SOAPUI_TESTCASE_NAME"
resultsP="C:\SoapResults\" & Tcase
Set tf = TDConnection.TestFactory
Set ts = tf.Item(Field("TS_TEST_ID"))
'**************************************************************************
' Invoke SOAPUI and execute the selected project
'**************************************************************************
invokeSOAPUIClient trPath, projFP, TSuite, Tcase, resultsP, CurrentTest, CurrentRun
'**************************************************************************
' Get the Results from the text file in to Run Steps of the test case
'**************************************************************************
'wait 1 second to allow for larger files to complete writing
TDOutput.Print "Start Wait 10"
XTools.Sleep 1000
TDOutput.Print "END Wait 10"
'Get Result file and write to run steps
getResultsToQC CurrentRun, soapResults
'**************************************************************************
' handle run-time errors
'**************************************************************************
If Not Debug Then
If Err.Number <> 0 Then
TDOutput.Print "Run-time error - Execute SOAPUI:Enter SuB - [" & Err.Number & "] : " & Err.Description
CurrentRun.Status = "Failed"
CurrentTest.Status = "Failed"
Else
CurrentRun.Status = "Passed" 'Need Function here to determine if all steps passed
CurrentTest.Status = "Passed" 'Need Function here to determine if all steps passed
End If
End If
End Sub
'**************************************************************************
' Sub for executing SOAPUI with the selected project
'**************************************************************************
' soapuiTestrunnerPath: TestRunner .bat file
' projectLocation: Project file location
'**************************************************************************
Sub invokeSOAPUIClient(soapuiTestrunnerPath, projectLocation, TSuite, Tcase, resultsP, CurrentTest, CurrentRun)
'**************************************************************************
' Execute SOAPUI from the command line
' Output Test Values for reference - Not Required
'**************************************************************************
TDOutput.Print "TSuite: " & TSuite
TDOutput.Print "Tcase: " & Tcase
TDOutput.Print "resultsP: " & resultsP
set fileSystem = CreateObject("Scripting.FileSystemObject")
'**************************************************************************
' Raise error if SOAPUI is not installed in the host where program is
' runned or if the path of executable bat file provided is not correct
'**************************************************************************
If ( not fileSystem.FileExists(soapuiTestrunnerPath)) then
Err.Raise 8
Err.Description = "soapUI testrunner not found: " + soapuiTestrunnerPath
End if
'**************************************************************************
'args will be the options that you wish to pass to the TestRunner
'for a full list of options call the test runner from the command prompt with
'no options
'**************************************************************************
Dim args
'args = "-s" & chr(34) & TSuite & chr(34) & " -c" & chr(34) & TCase & chr(34) & " -Drpath=" & resultsP & " -r -a -I "& chr(34) & projectLocation & chr(34) &""
args = "-s" & TSuite & " -c" & TCase & " -M -j -F XML -R test.xml -f " & resultsP & " -r -g -A -I "& chr(34) & projectLocation & chr(34) &""
XTools.run soapuiTestrunnerPath, args, -1, true
End Sub
'**************************************************************************
' Sub for Adding Results to QC - Parent to addRunData() function
' function will parse the result file generated by SoapUI Groovy Script &
' add the run details for the Soap UI test to the QC run
'**************************************************************************
' sFile: File path to Groovy Script Results "C:\Groovy_Report\test1.txt"
' Currently this value is HARD CODED
'**************************************************************************
sub getResultsToQC(CurrentRun, sFile)
Set objFS = CreateObject("Scripting.FileSystemObject")
'Create object for result file
Set objFile = objFS.GetFile(sFile)
'OPen Stream to read in file
Set ts = objFile.OpenAsTextStream(1,-2)
'Loop through file line by line
Do Until ts.AtEndOfStream
'Create string value for current line
strLine = ts.ReadLine
'TDOutput.Print strLine
'Split values based on delimiter (Set in groovy Script)
ArrSplit=Split(strLine, "|")
size = Ubound(ArrSplit)
'Determine action for array values
'Size = 6 is a report value that will have pass/fail
'Size <> 6 is a info value and will have status = N/A
if(size=6) Then
'StepName
sStepName = ArrSplit(1) & "-" & ArrSplit(2)
'Clean Step Status and determine pass/fail
sSplit = Split(ArrSplit(4),":")
sValue = Trim(sSplit(1))
if(sValue="VALID")Then
sStatus = "Passed"
Elseif (sValue="FAILED") then
sStatus = "Failed"
Else
sStatus = "N\A"
End If
'Step Description
sDescription = ArrSplit(5)
'Step Expected
sExpected = ArrSplit(3)
'Step Actual
sActual = Trim(ArrSplit(6))
'Add run result to current execution run
addRunData CurrentRun, sStepName, sStatus, sDescription, sExpected, sActual
else
'Added in case other options arise in the future
if(Trim(ArrSplit(0)) = "INFO") Then
sStepName = "INFO - " & ArrSplit(1)
sStatus = "N/A"
sDescription = ArrSplit(1)
sExpected = "N/A"
sActual = ArrSplit(2)
addRunData CurrentRun, sStepName, sStatus, sDescription, sExpected, sActual
End If
End if
Loop
ts.Close
end sub
'**************************************************************************
' Sub for adding Test Steps to the current run
' function will add the run details for the Soap UI test to the QC run
'**************************************************************************
' sStepName: Passed from getResultsToQC - String to display the step name
' sStatus: Passed from getResultsToQC - String to determine step status
' sDescription: Passed from getResultsToQC - String to describe step
' sExpected: Passed from getResultsToQC - String to show expected value
' sActual: Passed from getResultsToQC - String to show actual value
'**************************************************************************
Sub addRunData(CurrentRun, sStepName, sStatus, sDescription, sExpected, sActual )
Dim objRun
Set objRun = CurrentRun
'Create Step object and add values to Object array
Set objStep = objRun.StepFactory.AddItem(null)
objStep.Field("ST_STEP_NAME")= sStepName
objStep.Field("ST_STATUS") = sStatus
objStep.Field("ST_DESCRIPTION") = sDescription
objStep.Field("ST_EXPECTED") = sExpected
objStep.Field("ST_ACTUAL") = sActual
objStep.Post
Set objStep = Nothing
end sub
Groovy SoapUI TearDown Script - http://ryanoglesby.net/2013/08/28/executing-soapui-from-quality-center-part-2-groovy-teardown-script/
import jxl.*
import jxl.write.*
import java.lang.*
import com.eviware.soapui.support.XmlHolder
//*********************************************************************
//Define Array to hold reporting data
//*********************************************************************
def reportInfo = []
//*********************************************************************
//Define test name
//*********************************************************************
def testName= testRunner.testCase.name.toString()
def fpath = context.expand( '${projectDir}' )
def tcase = testRunner.testCase
//*********************************************************************
//Get number of Test steps
//*********************************************************************
def size = testRunner.testCase.getTestStepCount();
//*********************************************************************
//loop through test steps
//*********************************************************************
for(int i = 0; i<size; i++){
//*********************************************************************
//get Step Name
//*********************************************************************
name = tcase.getTestStepAt(i).getName()
//*********************************************************************
//create test step object
//*********************************************************************
testStep = testRunner.getTestCase().getTestStepByName(“$name”)
//*********************************************************************
//Get test step type
//*********************************************************************
def stepType = testStep.config.type
//*********************************************************************
//Determine course of action for each step type
//*********************************************************************
if(stepType==”datasink”){
//*********************************************************************
//Info Step as we won’t be running assertions on this step type
//Data will be added to reportInfo Array
//*********************************************************************
def info = “INFO | Data Sink Step | “+name
reportInfo << info
}else if(stepType==”groovy”){
//*********************************************************************
//Info Step as we won’t be running assertions on this step type
//Data will be added to reportInfo Array
//*********************************************************************
def info = “INFO | Groovy Script Step | “+name
reportInfo << info
}else if(stepType==”request”){
//*********************************************************************
//Report Step as we WILL be running assertions on this step type
//Data will be added to reportInfo Array
//*********************************************************************
//Create List of Assertion names, Counter == alist Size, and
//Assertion status
//*********************************************************************
def assertionNameList = testStep.getAssertionList().name
def counter = assertionNameList.size()
def assertionStatus = testStep.getAssertionList()
//*********************************************************************
//Loop through assertionList
//*********************************************************************
for(j=0;j<counter;j++)
{
def iAssertionName = assertionNameList[j]
def iAssertionStatus = testStep.getAssertionAt(j).getStatus().toString()
def tstep = testStep.getName()
if(iAssertionName==”SOAP Response”){
//*********************************************************************
//If Assertion type is SOAP Response Capture Step Status and XML
//*********************************************************************
def response = context.expand( ‘${‘+tstep+’#Response}’ )
response = response.replace(“\n”, “”)
response = response.replace(“\r”, “”)
def type = testStep.getAssertionAt(j).config.type
def reportString = “Report | ” + tstep + ” | ” + iAssertionName + ” | Expected Success Response |” + “Status: ” + iAssertionStatus + ” | ” + type + ” | ” + response
log.info reportString
reportInfo << reportString
}else{
//*********************************************************************
//If Assertion type is NOT SOAP Response Capture:
// Step Status
// Expected Value
// Assertion Type
// Actual (If Error=Error Message Else = Expected)
//*********************************************************************
def expect = testStep.getAssertionAt(j).expectedContent
def expectedValue = context.expand(expect)
def gStatus = testStep.getAssertionAt(j).status
gStatus = gStatus.toString()
def gAssert = testStep.getAssertionAt(j)
def gType = testStep.getAssertionAt(j).config.type
if(gStatus!=’FAILED’){
def reportString = “Report | ” + tstep + ” | ” + iAssertionName + ” | Expected: ” + expectedValue + “|” + ” Status: ” + gStatus + “|” + ” Type: ” + gType + “|” + expectedValue
log.info reportString
reportInfo << reportString
}else{
for( e in testStep.getAssertionAt(j).errors ){
def reportString = “Report | ” + tstep + ” | ” + iAssertionName + ” | Expected: ” + expectedValue + “|” + ” Status: ” + gStatus + “|” + ” Type: ” + gType + “|” + ” Error [" + e.message + "]”
log.info reportString
reportInfo << reportString
}
}
}
}
}else{
//*********************************************************************
//We will want to log a message for this step
//for currently unhandled step types
//*********************************************************************
}
}
//*********************************************************************
//capture execution time
//*********************************************************************
def gTimeInfo = “INFO | TIME | “+testRunner.getTimeTaken()
reportInfo << gTimeInfo
log.info gTimeInfo
//*********************************************************************
//create report for test
//*********************************************************************
//Folder within directory to save results to. If folder does not exist
//we will create it
//*********************************************************************
def folder = “Groovy_Report”
//*********************************************************************
//Directory to place create folder in or location of Folder
//*********************************************************************
def dir = “c:/”
//*********************************************************************
//Define and execute folder creation method
//*********************************************************************
def c
c = createFolder(dir,folder)
//*********************************************************************
//Define test file name and create report file
//*********************************************************************
def fName = “test1″
createfile(c,”fName”,”.txt”,reportInfo)
//*********************************************************************
//Create File Method
//*********************************************************************
//Input:
// dir: root folder directory
// filenm: name of file to be created minus the extension
// ext: file extension to be used
// info: array of strings containing your file data
//*********************************************************************
public void createfile(def dir, def filenm, def ext, def info){
new File(“$dir/$filenm$ext”).withWriter { out ->
info.each {
out.println it
}
}
}
//*********************************************************************
//Create File Method
//*********************************************************************
//Input:
// dir: root folder directory
// folder: folder to add to directory
//Output:
// String: directory root for file creation
//*********************************************************************
public String createFolder(def dir,def folder){
File f = new File(“$dir/$folder”);
f.mkdirs();
return “$dir/$folder”
}

Resources