def createWidgets(self): """ """ self.readButton = QPushButton("&Read SeleniumIDE\n(HTML File)") self.exportButton = QPushButton( "&Import in %s" % Settings.instance().readValue(key='Common/product-name')) self.exportButton.setEnabled(False) self.actsTable = ActionsTableView(self, core=self.core()) rightLayout = QVBoxLayout() rightLayout.addWidget(QLabel("Controls")) rightLayout.addWidget(self.readButton) rightLayout.addWidget(self.exportButton) rightLayout.addStretch(1) leftLayout = QVBoxLayout() leftLayout.addWidget(QLabel("Actions")) leftLayout.addWidget(self.actsTable) mainLayout = QHBoxLayout() mainLayout.addLayout(leftLayout) mainLayout.addLayout(rightLayout) self.setLayout(mainLayout)
def onImport(self): """ Export data """ self.core().debug().addLogSuccess( "exporting data" ) # import selenium example # { # "steps": [ # { "action-name": "OPEN BROWSER", "action-description": "", "action-params": "", "action-value": "https://www.google.fr"}, # { "action-name": "CLICK ELEMENT", "action-description": "", "action-params": "id=test", "action-value": ""} # ] # } # import sikuli example # { # "steps": [ # { "action-name": "CLICK ON", "action-description": "", "image-base64": "iVBORw0KGgoAAAANSUhEUgAAAEgAAAAYCAIAAADWASznAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAASdEVYdFNvZnR3YXJlAEdyZWVuc2hvdF5VCAUAAAK9SURBVFhH3Zhda9NQGMdPk9565Y1XCvsOBkREEEEZCjIYjslATFDxZggKo+CFnyAbG2MX+hn2wpbdbrdt19LKKoTaObRpN0JWF/uWtjk+T3LSppkbZVCxefhdPOd/npfzH11hI1TdpZ+m6dwN+jo62oAFMKLu5vP5XC5HaGwsWDHSxMZs285mMsR+FQ0Z9POMruuk8zIaNmavWpZF2lI0fFBKifUiGj7QWPM5Hz7QWH2G/2c0t1VYaW8LAd1B6sAdVaygfhnQWPUZ/38gtR1jzaB+GdCYOcX3WFFwuBsludpVSqrz4/TEmIxHyPFWafy1cYpvpJngRnvFK0tLgdvOltBfrDQGWXG2xgNkUpnkGXNY19kUMF/GKZg7CdVkc5KvpTBtLbNKqrluldoFjSkJxF6jJ5qb+JlkLQyphXdKzT0OsiJQw+YgcCbGBOfyawOX9cWeaCw5T4FkgqvuYWotccZ7ZyJVquc39or9jd40f0tnQ3AeIFp4YjMHWRGo8QMq0Z9wLpV1bG6vC10FWXSekhQhN5OYNhc5/Z2Mvw+aXDm/sVfsz33TWO4GKmITM8V0JwywIlDjB2Ry/JhjLLiblNOu0hUTIuSnCUybC9zxW2diUTb8Nf2NxprzlDWhr9E3jeGOQoUZY0MGWBGs8QEyKY1zPWadUi/aq0Jp3pkYF+G2Ese0Me+VFWX9gsZx4XeRHd3ARm+avur7aHlzfKJSGWTF2RoPkEnxQWTI3DR/wqKtk6A+RNDYj/uR4SDWYTwL1XwTuB0usJIc3ouEDzR2cDcSMg4fXmm1WuTbnUjIOPo4jX9ofp+4nr9NQgPYsW07k8mQWmqn9OFp4dE19RYZacACGAE77J85X7LZcrlcr/u+w0YzwAIYATtfczlN08hBoZDb30+nUslEIhEfyYBnw+PBAhgBO0fl8olh/AEFAxxb9lhHWwAAAABJRU5ErkJggg==", "opt-c": "0.6" } # ] # } # import remote-tests # supported file PY_EXT, PNG_EXT, TXT_EXT, TEST_UNIT_EXT, TEST_SUITE_EXT, TEST_PLAN_EXT, TEST_GLOBAL_EXT, TEST_CONFIG_EXT, TEST_DATA_EXT # content must be encoded in base 64 # { # "files": [ # { "file-path": "/A/B/test.tux", "content-file": "SGVsbG8gd29ybGQuIEJvbmpvdXIgw6Agdm91cyE="} # ] # } jsonStr = self.inDataEdit.toPlainText() try: jsonObj = json.loads(jsonStr) except Exception as e: QMessageBox.warning(self, "Plugin %s" % Settings.instance().readValue( key = 'Plugin/name' ), "Bad json message!" ) if not DEBUGMODE: self.core().sendMessage( cmd='import', data = jsonObj ) self.core().hide()
Logger.instance().info("init received") self.logWarning(msg="init called: %s" % request['data']) self.sendNotify(request=request, data="notify sent") def onAgentAlive(self, client, tid, request): """ Function to overwrite """ Logger.instance().info("alive received") if __name__ == '__main__': app = QApplication(sys.argv) # initiliaze settings application, read settings from the ini file Settings.initialize() # initialize logger logPathFile = "%s/%s" % ( Settings.getDirExec(), Settings.instance().readValue( key ='Trace/file' ) ) level = Settings.instance().readValue( key ='Trace/level' ) size = Settings.instance().readValue( key ='Trace/max-size-file' ) nbFiles = int( Settings.instance().readValue( key ='Trace/nb-backup-max' ) ) Logger.initialize( logPathFile=logPathFile, level=level, size=size, nbFiles=nbFiles, noSettings=True ) # init the plugin # MyPlugin = CorePlugin.GenericPlugin( Plugin = MyPlugin( pluginName=CONFIG_JSON["plugin"]["name"], pluginType=CONFIG_JSON["plugin"]["type"] ) sys.exit(app.exec_())
""" return str( base64.b64decode(ciphertext) , "utf8") def testConnection(self): """ """ self.TestSettings.emit(self.config) if __name__ == '__main__': app = QApplication(sys.argv) # initiliaze settings application, read settings from the ini file Settings.initialize() # initialize logger logPathFile = "%s/%s" % ( QtHelper.dirExec(), Settings.instance().readValue( key = 'Trace/file' ) ) level = Settings.instance().readValue( key = 'Trace/level' ) size = Settings.instance().readValue( key = 'Trace/max-size-file' ) nbFiles = int( Settings.instance().readValue( key = 'Trace/nb-backup-max' ) ) Logger.initialize( logPathFile=logPathFile, level=level, size=size, nbFiles=nbFiles, noSettings=True ) # init the core plugin MyPlugin = CorePlugin.MainWindow(debugMode=DEBUGMODE) # create the main widget WidgetSettings = SettingsPage(parent=MyPlugin) MyPlugin.addSettingsPage( widget=WidgetSettings ) WidgetMain = MainPage(parent=MyPlugin) MyPlugin.addMainPage( pageName=WidgetSettings.cfg()["plugin"]["name"],
def cfg(self): """ """ return self.config if __name__ == '__main__': app = QApplication(sys.argv) # initiliaze settings application, read settings from the ini file Settings.initialize() # initialize logger logPathFile = "%s/%s" % (QtHelper.dirExec(), Settings.instance().readValue(key='Trace/file')) level = Settings.instance().readValue(key='Trace/level') size = Settings.instance().readValue(key='Trace/max-size-file') nbFiles = int(Settings.instance().readValue(key='Trace/nb-backup-max')) Logger.initialize(logPathFile=logPathFile, level=level, size=size, nbFiles=nbFiles, noSettings=True) # init the core plugin MyPlugin = CorePlugin.MainWindow(debugMode=DEBUGMODE) # create the main widget WidgetSettings = SettingsPage(parent=MyPlugin) MyPlugin.addSettingsPage(widget=WidgetSettings)
def addResultsInTestLab(self, testcases, config={}): """ """ try: # connect self.RestAuthenticate(logger=self.logResultsStatus) rootFolder = self.RestFindTestsetFolder( logger=self.logResultsStatus, folderName="Root", parentId="-1") if rootFolder is None: raise Exception("Unable to detect the root folder in test lab") rootTpFolder = self.RestFindTestFolder( logger=self.logResultsStatus, folderName="Subject", parentId="0") if rootTpFolder is None: raise Exception( "Unable to detect the root folder in test plan") # clean up the path testsetpath = config["TestSet_Path"].replace("//", "/") if testsetpath.startswith("/"): testsetpath = testsetpath[1:] if testsetpath.endswith("/"): testsetpath = testsetpath[:-1] if not len(testsetpath): folders = [] else: folders = self.__splitall(testsetpath) # iterate on all folders ret = None parentId = rootFolder["id"] for d in folders: ret = self.RestFindTestsetFolder(logger=self.logResultsStatus, folderName=d, parentId=parentId) if ret is None and not config["Add_Folders"]: raise Exception('Folder (%s) is missing in test lab' % d) elif ret is None and config["Add_Folders"]: parentId = self.RestAddTestsetFolder( logger=self.logResultsStatus, folderName=d, parentId=parentId) else: parentId = ret["id"] if config["Add_TestSet"]: testsetId = self.RestCreateTestset( logger=self.logResultsStatus, testsetName=config["TestSet_Name"], parentId=parentId, subtypeId=config["TestSet_TypeId"]) else: oTestset = self.RestFindTestset( logger=self.logResultsStatus, testsetName=config["TestSet_Name"], parentId=parentId) testsetId = oTestset["id"] for tc in testcases: # clean the testpath testpath = "%s/" % tc['testpath'] testpath = testpath.replace("//", "/") if testpath.startswith("/"): testpath = testpath[1:] if testpath.endswith("/"): testpath = testpath[:-1] if not len(testpath): folders = [] else: folders = self.__splitall(testpath) # iterate on all folders ret = None parentIdTp = rootTpFolder["id"] for d in folders: ret = self.RestFindTestFolder(logger=self.logResultsStatus, folderName=d, parentId=parentIdTp) if ret is None: raise Exception('Folder (%s) is missing in test plan' % d) else: parentIdTp = ret["id"] if parentIdTp is None: raise Exception('Folder parent id is missing ?') # finally search the test in testplan ? oTest = self.RestFindTest(logger=self.logResultsStatus, testName=tc['testname'], parentId=parentIdTp) if config["Add_TestInstance"]: # add the test instance in testset testinsId = self.RestCreateTestInstance( logger=self.logResultsStatus, testId=oTest["id"], testsetId=testsetId, subtypeId=config["TestInstance_TypeId"]) else: oTestins = self.RestFindTestInstance( logger=self.logResultsStatus, testinsName=tc["name"], parentId=oTest["id"]) testinsId = oTestins["id"] # create a run with the state not completed runName = "%s_%s" % ( Settings.instance().readValue(key='Common/name'), time.strftime('%d-%m-%y %H:%M', time.localtime())) ownerName = self.core().settings().cfg( )["credentials"]["login"] runId = self.RestCreateRun(logger=self.logResultsStatus, testinsId=testinsId, runName=runName, ownerName=ownerName, testsetId=testsetId, testId=oTest["id"], testStatus="Not Completed", subtypeId=config["TestRun_TypeId"]) # create a run for all steps steps = self.RestGetTestInstanceSteps( logger=self.logResultsStatus, runId=runId) if "steps" in tc: i = 0 for stpId in steps: try: stp = tc["steps"][i] except Exception as e: raise Exception("step %s is missing" % i) else: self.RestUpdateRunStep( logger=self.logResultsStatus, stepId=stpId, runId=runId, stepStatus=stp["result"], stepActual=stp["actual"]) i += 1 else: for stpId in steps: self.RestUpdateRunStep(logger=self.logResultsStatus, stepId=stpId, runId=runId, stepStatus=tc["result"], stepActual="") # complete the run self.RestUpdateRun(logger=self.logResultsStatus, runId=runId, runStatus=tc["result"]) # disconnect self.RestLogout(logger=self.logResultsStatus) self.ResultsExported.emit(testcases, config) except Exception as e: if self.WsLwssoCookie is not None: self.RestLogout(logger=self.logResultsStatus) self.logResultsStatus("Error on result(s) export") self.Error.emit("%s" % e)
def addResultsInTestLab(self, testcases, config={}): """ """ try: # connect self.logResultsStatus("Connection to the COM API...") pythoncom.CoInitialize() qc_cx = win32client.Dispatch("TDApiOle80.TDConnection") qc_cx.InitConnectionEx(self.url) qc_cx.Login(self.login, self.password) qc_cx.Connect(self.domain, self.project) self.logResultsStatus("Connected") # find path folder in test lab self.logResultsStatus("Finding path in test lab...") if config["Add_Folders"]: testsetpath = "Root/%s" % (config["TestSet_Path"]) testsetpath = os.path.normpath(testsetpath) testsetpathSplit = self.__splitpath(path=testsetpath) treeManager = qc_cx.TestSetTreeManager tl = "Root/" if len(testsetpathSplit) == 1: testLabFolder = treeManager.NodeByPath( os.path.normpath(tl)) for f in testsetpathSplit[1:]: try: testLabFolder = treeManager.NodeByPath( os.path.normpath("%s/%s" % (tl, f))) tl = os.path.normpath("%s/%s" % (tl, f)) except pythoncom.com_error as e: self.logResultsStatus( "Creating folder %s in test lab..." % f) testLabFolder = treeManager.NodeByPath( os.path.normpath("%s" % tl)) testLabFolder = testLabFolder.AddNode(f) tl = os.path.normpath("%s/%s" % (tl, f)) else: treeManager = qc_cx.TestSetTreeManager testsetpath = "Root/%s" % (config["TestSet_Path"]) testsetpath = os.path.normpath(testsetpath) testLabFolder = treeManager.NodeByPath(testsetpath) if testLabFolder is None: raise Exception( 'Unable to find the provided path in test lab') # create the testset according to the testset name provided if config["Add_TestSet"]: self.logResultsStatus("Creating testset (%s) in test lab..." % config["TestSet_Name"]) testsetFactory = testLabFolder.TestSetFactory testset = testsetFactory.AddItem(None) testset.Name = config["TestSet_Name"] testset.SetField( "CY_COMMENT", u"<html><body>%s</body></html>" % "testset generated automatically") testset.Post() else: # find testset name self.logResultsStatus("Searching testset (%s) in test lab..." % config["TestSet_Name"]) testset = None testsets = testLabFolder.FindTestSets(config["TestSet_Name"]) if testsets is None: raise Exception('Unable to find the test set in test lab') for ts in testsets: if ts.Name == config["TestSet_Name"]: testset = ts break if testset is None: raise Exception('Testset (%s) not found in test lab' % config["TestSet_Name"]) # add test instance in testset ? if config["Add_TestInstance"]: self.logResultsStatus("Finding test(s) from testplan...") tsTestFactory = testset.TSTestFactory treeTpManager = qc_cx.TreeManager for tc1 in testcases: testpath = "Subject/%s/" % tc1['testpath'] testpath = os.path.normpath(testpath) try: testPlanFolder = treeTpManager.NodeByPath(testpath) except pythoncom.com_error as e: raise Exception( 'Unable to find the provided path %s in test plan' % tc1['testpath']) try: testsTp = testPlanFolder.FindTests(tc1['testname']) except pythoncom.com_error as e: raise Exception( 'Test (%s) not found in test plan (%s)' % (tc1['testname'], tc1['testpath'])) objTestTp = None if testsTp is not None: for tTp in testsTp: if tTp.Name == tc1['testname']: objTestTp = tTp break if objTestTp is None: raise Exception( 'Test object (%s) not found in test plan (%s)' % (tc1['testname'], tc1['testpath'])) testInstance = tsTestFactory.AddItem(None) testInstance.Status = "No Run" testInstance.SetField("TC_TEST_ID", objTestTp) testInstance.Post() self.logResultsStatus("Finding test instance in test lab...") #find testset name self.logResultsStatus("Refreshing testset (%s) from test lab..." % config["TestSet_Name"]) testset = None testsets = testLabFolder.FindTestSets(config["TestSet_Name"]) if testsets is None: raise Exception('Unable to find the test set in test lab') for ts in testsets: if ts.Name == config["TestSet_Name"]: testset = ts break if testset is None: raise Exception('Testset (%s) not found in test lab' % config["TestSet_Name"]) # get tests instance testsetList = testset.TSTestFactory.NewList("") testInstances = [] for ti in testsetList: testInstances.append(ti) if not len(testInstances): raise Exception('Testset (%s) is empty' % config["TestSet_Name"]) # finally run all testcases instances for tc in testcases: testI = None testIN = tc["name"] self.logResultsStatus( "Test instance to search in testset: (%s)" % testIN) for ti in testInstances: self.logResultsStatus("Test instance detected: (%s)" % ti.Name) if ti.Name == testIN: testI = ti break if testI is None: raise Exception("test instance (%s) not found" % testIN) self.logResultsStatus("Running test instance (%s)..." % testIN) # run test instance runFactory = testI.RunFactory runName = "%s_%s" % ( Settings.instance().readValue(key='Common/name'), time.strftime('%d-%m-%y %H:%M', time.localtime())) runInstance = runFactory.AddItem(runName) runInstance.Status = tc["result"] runInstance.CopyDesignSteps() runInstance.Post() # set steps results if "steps" in tc: i = 0 for stepFactory in runInstance.StepFactory.NewList(""): try: stp = tc["steps"][i] except Exception as e: raise Exception("step %s is missing" % i) else: stepFactory.Status = stp["result"] stepFactory.SetField("ST_ACTUAL", stp["actual"]) stepFactory.post() stepFactory.UnLockObject() i += 1 # if no step is provided but exists on qc # then you set all steps with the result of the testcase else: for stepFactory in runInstance.StepFactory.NewList(""): stepFactory.Status = tc["result"] stepFactory.post() stepFactory.UnLockObject() # disconnect self.logResultsStatus("Disconnection from the COM API...") qc_cx.Logout() qc_cx.ReleaseConnection() self.logResultsStatus("Disconnected") self.ResultsExported.emit() except pythoncom.com_error as e: hr, msg, exc, arg = e.args if exc is None: details = "HP connect missing!" else: _, _, details, _, _, _ = exc self.logTestsStatus("Error on test(s) export") self.Error.emit("%s: %s" % (msg, details)) except Exception as e: self.logResultsStatus("Error on results(s) export") self.Error.emit("%s" % e)