Adding testcase results to Quality Center Run from a outside Python Script - python

I want to try to add all the step details - Expected, Actual, Status,
etc. to a QC Run for a testcase of a TestSet from a Python Script
living outside the Quality Center.
I have come till here (code given below) and I don't know how to add
Step Expected and Step Actual Result. If anyone knows how do it,
please help me out!! Please, I don't want any QTP solutions.
Thanks,
Code-
# Script name - add_tsrun.py
# C:\Python27\python.exe
# This script lives locally on a Windows machine that has - Python 2.7, Win32 installed, IE8
# Dependencies on Windows Machine - Python 2.7, PythonWin32 installed, IE8, a QC Account, connectivity to QCServer
import win32com.client, os
tdc = win32com.client.Dispatch("TDApiOle80.TDConnection")
tdc.InitConnection('http://QCSERVER:8080/qcbin')
tdc.Login('USERNAME', 'PASSWORD')
tdc.Connect('DOMAIN_NAME', 'PROJECT')
tsFolder = tdc.TestSetTreeManager.NodeByPath('Root\\test_me\\sub_folder')
tsList = tsFolder.FindTestSets('testset1')
ts_object = tsList.Item(1)
ts_dir = os.path.dirname('testset1')
ts_name = os.path.basename('testset1')
tsFolder = tdc.TestSetTreeManager.NodeByPath(ts_dir)
tsList = tsFolder.FindTestSets(ts_name)
ts_object = tsList.Item(1)
TSTestFact = ts_object.TSTestFactory
TestSetTestsList = TSTestFact.NewList("")
ts_instance = TestSetTestsList.Item(1)
newItem = ts_instance.RunFactory.AddItem(None) # newItem == Run Object
newItem.Status = 'No Run'
newItem.Name = 'Run 03'
newItem.Post()
newItem.CopyDesignSteps() # Copy Design Steps
newItem.Post()
steps = newItem.StepFactory.NewList("")
step1 = steps[0]
step1.Status = "Not Completed"
step1.post()
## How do I change the Actual Result??
## I can access the Actual, Expected Result by doing this, but not change it
step1.Field('ST_ACTUAL') = 'My actual result' # This works in VB, not python as its a Syntax error!!
Traceback ( File "<interactive input>", line 1
SyntaxError: can't assign to function call
Hope this helps you guys out there. If you know the answer to set the
Actual Result, please help me out and let me know. Thanks,
Amit

As Ethan Furman answered in your previous question:
In Python () represent calls to functions, while [] represent indexing and mapping.
So in other words, you probably want to do step1.Field['ST_ACTUAL'] = 'My actual result'

Found the answer after a lot of Google Search :)
Simple -> Just do this:
step1.SetField("ST_ACTUAL", "my actual result") # Wohhooooo!!!!
If the above code fails to work, try to do the following:-
(OPTIONAL) Set your win32 com as follows- (Making ''Late Binding'')
# http://oreilly.com/catalog/pythonwin32/chapter/ch12.html
a. Start PythonWin, and from the Tools menu, select the item COM Makepy utility.
b. Using Windows Explorer, locate the client subdirectory (OTA COM Type Library)
under the main win32com directory and double-click the file makepy.py.
Thank you all...

Related

How to change username of job in print queue using python & win32print

I am trying to change the user of a print job in the queue, as I want to create it on a service account but send the job to another users follow-me printing queue. I'm using the win32 module in python. Here is an example of my code:
from win32 import win32print
JOB_INFO_LEVEL = 2
pclExample = open("sample.pcl")
printer_name = win32print.GetDefaultPrinter()
hPrinter = win32print.OpenPrinter(printer_name)
try:
jobID = win32print.StartDocPrinter(hPrinter, 1, ("PCL Data test", None, "RAW"))
# Here we try to change the user by extracting the job and then setting it again
jobInfoDict = win32print.GetJob(hPrinter, jobID , JOB_INFO_LEVEL )
jobInfoDict["pUserName"] = "exampleUser"
win32print.SetJob(hPrinter, jobID , JOB_INFO_LEVEL , jobInfoDict , win32print.JOB_CONTROL_RESUME )
try:
win32print.StartPagePrinter(hPrinter)
win32print.WritePrinter(hPrinter, pclExample)
win32print.EndPagePrinter(hPrinter)
finally:
win32print.EndDocPrinter(hPrinter)
finally:
win32print.ClosePrinter(hPrinter)
The problem is I get an error at the win32print.SetJob() line. If JOB_INFO_LEVEL is set to 1, then I get the following error:
(1804, 'SetJob', 'The specified datatype is invalid.')
This is a known bug to do with how the C++ works in the background (Issue here).
If JOB_INFO_LEVEL is set to 2, then I get the following error:
(1798, 'SetJob', 'The print processor is unknown.')
However, this is the processor that came from win32print.GetJob(). Without trying to change the user this prints fine, so I'm not sure what is wrong.
Any help would be hugely appreciated! :)
EDIT:
Using Python 3.8.5 and Pywin32 303
At the beginning I thought it was a misunderstanding (I was also a bit skeptical about the bug report), mainly because of the following paragraph (which apparently seems to be wrong) from [MS.Docs]: SetJob function (emphasis is mine):
The following members of a JOB_INFO_1, JOB_INFO_2, or JOB_INFO_4 structure are ignored on a call to SetJob: JobId, pPrinterName, pMachineName, pUserName, pDrivername, Size, Submitted, Time, and TotalPages.
But I did some tests and ran into the problem. The problem is as described in the bug: filling JOB_INFO_* string members (which are LPTSTRs) with char* data.
Submitted [GitHub]: mhammond/pywin32 - Fix: win32print.SetJob sending ANSI to UNICODE API (and none of the 2 errors pops up). It was merged to main on 220331.
When testing the fix, I was able to change various properties of an existing job, I was amazed that it didn't have to be valid data (like below), I'm a bit curious to see what would happen when the job would be executed (as now I don't have a connection to a printer):
Change pUserName to str(random.randint(0, 10000)) to make sure it changes on each script run (PrintScreens taken separately and assembled in Paint):
Ways to go further:
Wait for a new PyWin32 version (containing this fix) to be released. This is the recommended approach, but it will also take more time (and it's unclear when it will happen)
Get the sources, either:
from main
from b303 (last stable branch), and apply the (above) patch(1)
build the module (.pyd) and copy it in the PyWin32's site-packages directory on your Python installation(s). Faster, but it requires some deeper knowledge, and maintenance might become a nightmare
Footnotes
#1: Check [SO]: Run / Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? (#CristiFati's answer) (Patching UTRunner section) for how to apply patches (on Win).

Maya RuntimeError: OpenMaya.py (kInvalidParameter): Index not in valid Range

I am writing a python tool that will store attributes of the stereoscopic camera in a scene into a JSON file.
I use this code to get the selected plane with the attributes I need to store
import maya.OpenMaya as om
selected = om.MSelectionList()
om.MGlobal.getActiveSelectionList(selected)
obj = om.MObject()
selected.getDependNode(0,obj)
sel = om.MFnDependencyNode(obj).name()
if sel != "npl_Near_ZP":
cmds.confirmDialog(title= 'Error:', message = 'Error: Please Select the correct plane', button =['OK'])
else:
jsonCreate(sel)
It was working perfectly before but now when I try to the script, I get the following runtime error and I 've sort of hit a wall here cause I don't understand what the problem is
Error: RuntimeError: file S:\Maya_2018_DI\build\Release\runTime\Python\Lib\site-packages\maya\OpenMaya.py line 18296: (kInvalidParameter): Index not in valid range #
I m still new to Maya so any help will be greatly appreciated
update I restarted my computer and the script is now running as it should. Can anyone explain this behaviour in case it happens again

How to assign a 2d libreoffice calc named range to a python variable. Can do it in Libreoffice Basic

I can't seem to find a simple answer to the question. I have this successfully working in Libreoffice Basic:
NamedRange = ThisComponent.NamedRanges.getByName("transactions_detail")
RefCells = NamedRange.getReferredCells()
Set MainRange = RefCells.getDataArray()
Then I iterate over MainRange and pull out the rows I am interested in.
Can I do something similar in a python macro? Can I assign a 2d named range to a python variable or do I have to iterate over the range to assign the individual cells?
I am new to python but hope to convert my iteration intensive macro function to python in hopes of making it faster.
Any help would be much appreciated.
Thanks.
LibreOffice can be manipulated from Python with the library pyuno. The documentation of pyuno is unfortunately incomplete but going through this tutorial may help.
To get started:
Python-Uno, the library to communicate via Uno, is already in the LibreOffice Python’s path. To initialize your context, type the following lines in your python shell :
import socket # only needed on win32-OOo3.0.0
import uno
# get the uno component context from the PyUNO runtime
localContext = uno.getComponentContext()
# create the UnoUrlResolver
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext )
# connect to the running office
ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager
# get the central desktop object
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
# access the current writer document
model = desktop.getCurrentComponent()
Then to get a named range and access the data as an array, you can use the following methods:
NamedRange = model.NamedRanges.getByName(“Test Name”)
MainRange = NamedRange.getDataArray()
However I am unsure that this will result in a noticeable preformance gain.

How can I switch between multiple open powerpoint presentations using python?

Judging by other posts such as Python Window Activation this might not be as simple as I was hoping, but I'm compelled to ask anyway.
In the snippet below, using win32com.client and Application.Presentations.Open(ppt1, ReadOnly=0) will open and activate a powerpoint presentation. Using Application.Presentations.Open(ppt2, ReadOnly=0) will open and activate another powerpoint presentation. As you will see, I can easily reference the former presentation and do SOME things with it, but it will NOT become the active window. How can this be accomplished?
Here's what I've been working with:
# The following requires two existing presentations
# ppt1.pptx and ppt2.pptx in a directory named C:\\pptTest\\
import win32com.client
Application = win32com.client.Dispatch("PowerPoint.Application")
directory = 'C:\\pptTest\\'
ppt_a = 'ppt_a.pptx'
ppt_b = 'ppt_b.pptx'
presentation_a = directory + ppt_a
presentation_b = directory + ppt_b
pres_a = Application.Presentations.Open(presentation_a, ReadOnly=0)
pres_b = Application.Presentations.Open(presentation_b, ReadOnly=0)
pres_a_slide1 = pres_a.Slides.Add(len(pres_a.Slides)+1, 12)
shape_a_1 = pres_a_slide1.Shapes.AddTextbox(Orientation=0x1,Left=100,Top=50,Width=400,Height=100)
shape_a_1.TextFrame.TextRange.Text='PRESENTATION A'
##%%
pres_b_slide1 = pres_b.Slides.Add(len(pres_b.Slides)+1, 12)
shape1 = pres_b_slide1.Shapes.AddTextbox(Orientation=0x1,Left=100,Top=50,Width=400,Height=100)
shape1.TextFrame.TextRange.Text='PRESENTATION B'
Result:
As you can see by the example, I can still reference the first presentation after opening another, but I can't make it the active window. The reason why I'm so interested in this, is that some methods will not work properly unless the presentation I'm editing through Python is also the active window. I'll get into those details as well if that is interesting to anyone.
Thank you for any suggestions!
Several examples, see if that works for you
import win32com.client as win32
file1='C:/test.pptm'
file2='C:/test2.pptm'
PowerPoint=win32.DispatchEx("PowerPoint.Application")
PowerPoint.Visible = True
Presentation1 = PowerPoint.Presentations.Open(file1)
Presentation2 = PowerPoint.Presentations.Open(file2)
PowerPoint.Windows(1).Activate()
PowerPoint.Windows(2).Activate()
print(PowerPoint.ActivePresentation.Name) # to see the name
PowerPoint.Presentations("test.pptm").Windows(1).Activate()
PowerPoint.Presentations("test2.pptm").Windows(1).Activate()
Presentation1.Windows(1).Activate()
Presentation2.Windows(1).Activate()
I dug through some old code and found something where I also had to switch between different open programs :
from win32com.client import Dispatch
autoit = Dispatch("AutoItX3.Control")
def _window_movement_windows(page_title):
autoit.WinSetOnTop(page_title, "", 1)
autoit.WinActivate(page_title, "")
autoit.WinWaitActive(page_title)
An example how to setup AutoIt with python can be found here : Calling AutoIt Functions in Python

gsm location in python

I have this script file in python running on S60:
import location
def current_location():
gsm_loc = location.gsm_location()
print gsm_loc
current_location()
instead of printing a tuple of mcc, mnc, lac and cellId it prints None.
on top of my python shell I see location between the capabilities included.
what can be the problem?
Development of the situation:
I thought maybe nevertheless, my problem is lack of capabilities. So I went to sign the PythonScriptShell file.
I used OPDA website - I know they sign all the capabilities but three - which I don't use.
I installed the signed PythonScriptShell file on my phone (N95). On the top the list of capabilities didn't change. tried to run the script again:
same result - prints None.
If anyone can help me with this, it's really important.
thank you.
I think I can answer now one part of the problem:
the reason for printing None is because there needed another capability: ReadDeviceData which wasn't included in the capabilities list on top of python shell.
still, remaining the other part of the problem, why this capability wasn't included when I signed PythonScriptShell file? It is not one of the three restricted capabilities.
I have same issue with all necessary scriptshell capabilities: 'PowerMgmnt', 'ReadDeviceData', 'WriteDeviceData', 'TrustedUI', 'ProtServ', 'SwEvent', 'Network services', 'LocalServices', 'ReadUserData', 'WriteUserData', 'Location', 'SurroundingsDD', 'UserEnviroment'.
Let's take a look at source code from PythonForS60/module-repo/dev-modules/location.py:
import e32
import _location
def gsm_location():
if e32.s60_version_info>=(3,0):
ret = _location.gsm_location()
if ret[4]==1: # relevant information ?
return (int(ret[0]),int(ret[1]),ret[2],ret[3])
else:
return None # information returned by _location.gsm_location() not relevant
else:
return _location.gsm_location()
On my Nokia E71 e32.s60_version_info == (3,1) and I get None value too.
I don't really know what means 'not relevant', but direct calling
>>> import _location
>>> _location.gsm_location()
(u'257', u'01', 555, 11, 0)
returns something close to my objective reality.

Categories

Resources