7 Check that Object Browser is displayed.
9 def checkObjectBrowser():
10 waitFor("object.exists(':Object Browser_QtxTreeView')", 20000)
11 test.compare(findObject(":Object Browser_QtxTreeView").visible, True)
14 Check that Python console is displayed.
16 def checkPythonConsole():
17 waitFor("object.exists(':Python Console_PyConsole_EnhEditor')", 20000)
18 test.compare(findObject(":Python Console_PyConsole_EnhEditor").visible, True)
21 Activate menu for any level of depth.
22 For example: activateMenuItem("File","New")
24 def activateMenuItem(*menuPath):
25 menu = ":SALOME_QMenuBar"
26 parent = "{type='STD_TabDesktop' unnamed='1' visible='1' windowTitle?='SALOME *'}"
27 for item in menuPath[:-1]:
28 activateItem(waitForObjectItem(menu, item))
29 menu = "{title='%s' type='QMenu' unnamed='1' visible='1'}" % (item)
31 activateItem(waitForObjectItem(menu, menuPath[-1]))
34 Return current data in given format
36 def getCurrentDateString(format = "%d/%m/%Y %H:%M"):
37 now = datetime.datetime.now()
38 return str(now.strftime(format))
41 Return current user name
44 user = os.getenv("USER")
48 Return difference between given and current date
50 def dateDifferenceToNow(date_str, format="%d/%m/%Y %H:%M"):
51 now = datetime.datetime.now()
52 date_to_compare = datetime.datetime(*(time.strptime(date_str, format)[0:6]))
53 test.log("dateDifferenceToNow","now:"+str(now)+" date_to_compare:"+str(date_to_compare)+" dif:"+ str(now-date_to_compare))
54 return abs(now - date_to_compare)< datetime.timedelta(minutes = 1)
57 #--------------------------------------------------------------------------
59 #--------------------------------------------------------------------------
61 Open given file via menu "File"-"Open"
62 For example: openFile("/<Full path to file>")
64 def openFile(file_path):
65 activateMenuItem("File","Open...")
66 test.verify(os.path.exists(file_path))
67 realName = "{buddy=':Open File.File name:_QLabel' name='fileNameEdit' type='QLineEdit' visible='1'}" #:fileNameEdit_QLineEdit_2
68 waitForObject(realName).setText(file_path)
69 type(waitForObject(realName), "<Return>")
72 Save given file via menu "File"-"Save As"
73 For example: saveFile("/<Full path to file>")
75 def saveFile(file_path):
76 activateMenuItem("File","Save As...")
77 lineEditRealName = "{buddy=':Save File.File name:_QLabel' name='fileNameEdit' type='QLineEdit' visible='1'}"
78 saveBtnRealName = "{text='Save' type='QPushButton' unnamed='1' visible='1' window=':Save File_SUIT_FileDlg'}"#{text='Save' type='QPushButton' unnamed='1' visible='1' window=':Save File_SUIT_FileDlg'}
79 waitFor("object.exists('%s')" % lineEditRealName.replace("'", "\\'"), 2000)
80 waitForObject(lineEditRealName).setText(file_path)
81 type(waitForObject(lineEditRealName), "<Return>")
84 Import Python script via SALOME Python console
85 For example: importPythonScript("SMESH_test1")
87 def importPythonScript(fileName):
88 mouseClick(waitForObject(":Python Console_PyConsole_EnhEditor"), 50, 10, 0, Qt.LeftButton)
89 type(waitForObject(":Python Console_PyConsole_EnhEditor"), "import %s" % fileName)
90 type(waitForObject(":Python Console_PyConsole_EnhEditor"), "<Return>")
96 activateMenuItem("File","Close")
99 Makes dump of the study to given file via menu
102 def dumpStudy(file_path, save_gui_state = False ):
103 activateMenuItem("File","Dump Study...")
104 waitForObject(":Dump study.Save GUI state_QCheckBox").checked = save_gui_state
105 mouseClick(waitForObject(":fileNameEdit_QLineEdit_3"), 20, 11, 0, Qt.LeftButton)
106 waitForObject(":fileNameEdit_QLineEdit_3").setText(file_path)
107 type(waitForObject(":fileNameEdit_QLineEdit_3"), "<Return>")
110 Opens python script via menu File->Load Script
112 def loadScript(file_path):
113 activateMenuItem("File","Load Script...")
114 mouseClick(waitForObject(":fileNameEdit_QLineEdit_4"), 45, 12, 0, Qt.LeftButton)
115 waitForObject(":fileNameEdit_QLineEdit_4").setText(file_path)
116 clickButton(waitForObject(":Load python script.Open_QPushButton"))
119 #--------------------------------------------------------------------------
121 #--------------------------------------------------------------------------
123 Deselect all objects selected in Object browser.
126 objBrowser = waitForObject(":Object Browser_QtxTreeView")
127 objBrowser.clearSelection()
130 Select item in Object Browser tree under topTreeItem with possible modifier.
131 The mostly used values of modifier are Qt.ShiftModifier, Qt.ControlModifier
133 def selectObjectBrowserItem(item, topTreeItem = "HYDRO" , modifier = 0 ):
134 itemText = getItemText(item, topTreeItem)
135 waitForObjectItem(":Object Browser_QtxTreeView", itemText)
136 clickItem(":Object Browser_QtxTreeView", itemText, 30, 5, modifier, Qt.LeftButton)
139 Verify that given item exists in Object Browser
140 For example: checkOBItemNotExists("HYDRO", "NATURAL OBJECTS", "Immersible zone_1")
142 def checkOBItem(*parentNames):
143 treeObj = waitForObject(":Object Browser_QtxTreeView")
144 obj = getModelIndexByName(treeObj, *parentNames)
145 if (not obj is None) and obj.isValid():
146 test.compare(obj.text, parentNames[-1])
149 for name in parentNames:
151 test.fail("Unexpectedly failed to find the object in OB", s)
154 Verify that given item doesn't exist in Object Browser
155 For example: checkOBItemNotExists("HYDRO", "NATURAL OBJECTS", "Immersible zone_2")
157 def checkOBItemNotExists(*parentNames):
158 treeObj = waitForObject(":Object Browser_QtxTreeView")
159 obj = getModelIndexByName(treeObj, *parentNames)
161 for name in parentNames:
163 if (not obj is None) and obj.isValid():
164 test.fail("Unexpectedly object is found in OB", s)
166 test.passes("Object '%s' wasn't found in OB" % s)
169 Activate context menu item for the given object in the Object Browser.
170 For example: aactivateOBContextMenuItem("HYDRO.NATURAL OBJECTS", "Zone_1", "Show")
172 def activateOBContextMenuItem(parent, item, *menuPath):
174 name = getItemText(item, parent)
175 selectObjectBrowserItem(item, parent)
176 openItemContextMenu(waitForObject(":Object Browser_QtxTreeView"), name, 10, 1, 0)
178 except LookupError,err:
179 test.fail("Unexpectedly failed to find the object in OB", str(err))
182 Activate context menu item for the given list of objects in the Object Browser.
183 For example: activateOBContextMenuItems("HYDRO.NATURAL OBJECTS", ["Zone_1", "Zone_2"], "Show")
185 def activateOBContextMenuItems(topTreeItem, listItems, *menuPath):
187 selectObjectBrowserItem(listItems[0], topTreeItem)
188 for item in listItems[1:]:
189 itemText = getItemText(item, topTreeItem)
190 waitForObjectItem(":Object Browser_QtxTreeView", itemText)
191 clickItem(":Object Browser_QtxTreeView", itemText, 30, 5, Qt.ControlModifier, Qt.LeftButton)
192 openItemContextMenu(waitForObject(":Object Browser_QtxTreeView"), itemText, 10, 1, 0)
195 #--------------------------------------------------------------------------
197 #--------------------------------------------------------------------------
199 Activate context menu item at the given point of 3D viewer.
200 For example: activateOCCViewerContextMenuItem(100, 100, "Hide all")
202 def activateOCCViewerContextMenuItem(x, y, *menuPath):
203 activateViewerContextMenuItem(":SALOME *.3D View Operations_OCCViewer_ViewPort3d", x, y, *menuPath)
206 Click "Fit All" button
207 If isDeselectAll = True all selected objects will be deselected.
209 def fitAll(isDeselectAll=False):
212 clickButton(waitForObject(":SALOME *.Fit All_QToolButton"))
217 def resetOCCViewer():
218 clickButton(waitForObject(":SALOME *.Reset_QToolButton"))
221 Show/Hide trihedron axis in OCC Viewer
223 def showTrihedron(val):
224 btn = waitForObject(":SALOME *.Show/Hide trihedron_QToolButton")
225 if btn.checked != val:
228 Call Transparency popup menu in OCC Viewer
230 def setOCCViwerTransparency(value, pos_x = -1, pos_y = -1 ):
231 setTransparency(":SALOME *.3D View Operations_OCCViewer_ViewPort3d", value, pos_x, pos_y)
234 Call Isos popup menu in OCC Viewer
236 def setOCCViwerIsos(u, v, pos_x = -1, pos_y = -1):
237 setIsos(":SALOME *.3D View Operations_OCCViewer_ViewPort3d", u, v, pos_x, pos_y)
239 #--------------------------------------------------------------------------
241 #--------------------------------------------------------------------------
244 Activate context menu item at the given point of VTK viewer.
245 For example: activateVTKContextMenuItem(50, 100, "Hide")
247 def activateVTKContextMenuItem(x, y, *menuPath):
248 activateViewerContextMenuItem(":SALOME *.SVTK_RenderWindowInteractor_SVTK_RenderWindowInteractor", x, y, *menuPath)
250 def setVTKIsos(u, v, pos_x = -1, pos_y = -1):
251 setIsos(":SALOME *.SVTK_RenderWindowInteractor_SVTK_RenderWindowInteractor", u, v, pos_x, pos_y)
253 def setVTKTransparency(value, pos_x = -1, pos_y = -1 ):
254 setTransparency(":SALOME *.SVTK_RenderWindowInteractor_SVTK_RenderWindowInteractor", value, pos_x, pos_y)
257 #--------------------------------------------------------------------------
259 #--------------------------------------------------------------------------
261 Set button checked or unchecked
263 def setButtonChecked(button, isChecked):
264 if (isChecked != button.checked):
267 test.verify(button.checked == isChecked)
270 Select item with the given text in the combo box
272 def selectComboBoxItem(combo, itemText):
273 for index in range(combo.count):
274 if combo.itemText(index) == itemText:
275 combo.setCurrentIndex(index)
278 test.verify(combo.currentText == itemText)
282 Check that the combo box contains only the given items.
284 def checkComboBoxContent(combo, items):
285 sortItems = list(items)
289 for index in range(combo.count):
290 comboItems.append(str(combo.itemText(index)))
294 test.compare(comboItems, sortItems)
297 #--------------------------------------------------------------------------
299 #--------------------------------------------------------------------------
302 Returns the QModelIndex for child with given name and parent index
303 Warning: may works incorrectly for items with duplicated names
305 def getChildModelIndex(parentIdx, name):
307 if parentIdx is None:
309 childIdx = parentIdx.child(row, 0)
310 while childIdx.isValid():
311 if name == str(childIdx.data().toString()):
314 childIdx = childIdx.sibling(row, 0)
318 Returns the QModelIndex form given tree by list of hierarchical names
319 For example: getModelIndexByName(tree, "HYDRO", "NATURAL OBJECTS", "Immersible zone_1")
321 def getModelIndexByName(treeObj, *parentNames):
322 parentNodeName = parentNames[0].replace('_',"\\\\_")
323 waitForObjectItem(treeObj, parentNodeName)
324 # clickItem(treeObj, parentNodeName, 5, 5, 0, Qt.LeftButton)
326 root = treeObj.indexAt(QPoint(0,0))
328 for name in parentNames[1:]:
329 idx = getChildModelIndex(root, name)
335 def getObjectBrowserItem(theItem, theParent=":HYDRO_QModelIndex", theOccurrence = 1):
336 return "{column='0' container='%s' occurrence='%s' text='%s' type='QModelIndex'}" % (theParent, theOccurrence, theItem)
338 def getItemText(item, parent):
342 return "%s.%s" % (parent, item.replace('_',"\\\\_"))
344 def popupItem(*menuPath):
345 menu = waitForObject("{type='QtxMenu' unnamed='1' visible='1'}")
346 parent = "{type='QtxMenu' unnamed='1' visible='1'}"
347 for item in menuPath[:-1]:
348 test.log("Element",str(item)+" menu "+str(menu))
349 activateItem(waitForObjectItem(menu, item))
350 menu = "{title='%s' type='QMenu' unnamed='1' visible='1'}" % (item)
352 activateItem(waitForObjectItem(menu, menuPath[-1]))
354 def viewerPopupItem(menu_type, *menuPath ):
355 menu = waitForObject("{type='%s' unnamed='1' visible='1'}" % menu_type)
357 for item_name in menuPath[:-1]:
358 menu_children = object.children(menu)
359 for child in menu_children:
360 properties = object.properties(child)
361 if properties.get("text", "") == item_name:
362 mouseClick(child, 5, 5, 0, Qt.LeftButton)
366 activateItem(waitForObjectItem(menu, menuPath[-1]))
368 def activateViewerContextMenuItem(viewer, x, y, *menuPath):
369 vtkViewer = waitForObject(viewer)
371 x = vtkViewer.width/2
373 y = vtkViewer.height/2
375 mouseClick(vtkViewer, x, y, 0, Qt.LeftButton)
376 mouseClick(vtkViewer, x, y, 0, Qt.RightButton)
377 viewerPopupItem("QtxMenu", *menuPath)
378 res = waitFor("object.exists('%s')" % "{type=\\'QtxMenu\\' unnamed=\\'1\\' visible=\\'1\\'}",10000)
380 mouseClick(vtkViewer, x, y, 0, Qt.LeftButton)
383 def getFullItemName(itemIndex):
384 fullName = str(itemIndex.data().toString())
385 parentIndex = itemIndex.parent()
387 while parentIndex.isValid():
388 parentName = str(parentIndex.data().toString())
389 fullName = "%s::%s" % (parentName, fullName)
391 parentIndex = parentIndex.parent()
395 def getChildValues(parentIndex, theIsRecursive = True):
398 child_index0 = parentIndex.child(row, 0)
399 while child_index0.isValid():
400 child_index1 = child_index0.sibling(row, 1)
401 if child_index1.isValid():
402 key = getFullItemName(child_index0) # str(child_index0.data().toString())
403 value = str(child_index1.data().toString())
407 values.update(getChildValues(child_index0))
410 child_index0 = parentIndex.child(row, 0)
414 def getTreeValues(treeObj):
415 root = treeObj.indexAt(QPoint(0,0))
417 return getChildValues(root)
419 def checkContainsStringValues(values, stringKeys):
422 for key in stringKeys:
423 if not values.has_key(key):
425 test.fatal("Map of values doesn't contain %s key" % key)
426 elif len(values[key]) < 1:
428 test.fatal("Value for key %s is empty" % key)
432 def isInteger(value):
435 intValue = cast(value, int)
436 res = intValue is not None
450 def checkContainsIntValues(values, intKeys):
454 if not values.has_key(key):
456 test.fatal("Map of values doesn't contain %s key" % key)
457 elif not isInteger(values[key]):
459 test.fatal("Value for key %s is not an integer ('%s')" % (key, values[key]))
463 def checkContainsListOfIntValues(values, listOfIntKeys, sep):
466 for key in listOfIntKeys:
467 if not values.has_key(key):
469 test.fatal("Map of values doesn't contain %s key" % key)
471 listItems = values[key].split(sep)
473 for item in listItems:
474 if not isInteger(item):
476 test.fatal("Value for key %s is not a list of integer ('%s')" % (key, values[key]))
480 def checkContainsFloatValues(values, floatKeys):
483 for key in floatKeys:
484 if not values.has_key(key):
486 test.fatal("Map of values doesn't contain %s key" % key)
487 elif not isFloat(values[key]):
489 test.fatal("Value for key %s is not a float ('%s')" % (key, values[key]))
494 Set the given value to the input field.
496 def setInputFieldValue(field, value):
497 type(field, "<Ctrl+A>")
501 def clearSelection():
502 mouseClick(waitForObject(":SALOME *.3D View Operations_OCCViewer_ViewPort3d"), 1, 1, 0, Qt.LeftButton)
504 def getChildNames(tree, root):
507 rootName = str(root.data().toString())
508 while root.isValid():
509 rootName1 = str(root.data().toString())
510 child = root.child(0, 0)
512 childName = str(child.data().toString())
513 list.extend( getChildNames(tree, child) )
515 if not tree.isRowHidden(row, root.parent()):
516 name = getFullItemName(root)
519 root = root.sibling(row, 0)
523 def getTreeNames(tree):
524 root = tree.indexAt(QPoint(0,0))
525 return getChildNames( tree, root)