How to use staticTexts method in pyatom

Best Python code snippet using pyatom_python

bs_gilligan.py

Source:bs_gilligan.py Github

copy

Full Screen

...4###################################################################5def checkFileSyncing(appName):6 stepName = "check file syncing in "+ appName7 time.sleep(1)8 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name contains 'Updating'"):9 timeoutCount = 110 timeoutLimit = 12011 while timeoutCount <= timeoutLimit: 12 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name contains 'Updating'"): 13# print "*** INFO - object still valid"14 time.sleep(1)15 timeoutCount = timeoutCount + 116 17 else:18 if timeoutCount >= 1:19# print "*** INFO - object should be invalid"20 break21 22 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name contains 'Updating'"):23# print "*** INFO - stop checkFileSyncing"24 return True25 26 else:27 msg = "FAIL - "+ stepName28 bs_common.scriptFailedExit()29 return False30 31def contextMenu_fileDuplicate(testcaseId, appName, inFileName):32 stepName = "contextMenu file duplicate - "+ appName +" / "+ inFileName 33 time.sleep(1) 34 if not target.processes()["Safari"].frontWindow():35 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].click()36 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[inFileName]:37 bs_common.writeResults(testcaseId, stepName, "FAIL")38 msg = "FAIL - "+ stepName39 bs_common.writeItemToLogFile(msg)40 41 myBounds = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[inFileName].bounds()42 x = Foundation.NSMidX(myBounds)43 y = Foundation.NSMidY(myBounds)44 yOffset = (y - 60)45 time.sleep(1)46 keyboard.pressKey_(kVK_Control)47 mouse.click_((x, yOffset)) 48 keyboard.releaseKey_(kVK_Control)49 50 myAppFileType = getFileTypeFromAppName(appName)51 time.sleep(1) 52 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].menuItems()["Duplicate "+ myAppFileType].staticTexts()["Duplicate "+ myAppFileType].click()53 54 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name like '"+ inFileName +" copy'"):55 bs_common.writeResults(testcaseId, stepName, "FAIL")56 msg = "FAIL - "+ stepName57 bs_common.writeItemToLogFile(msg)58 59 else:60 bs_common.writeResults(testcaseId, stepName, "PASS") 61 msg = "PASS - "+ stepName62 bs_common.writeItemToLogFile(msg)63 64def contextMenu_fileDownload(testcaseId, appName, inFileName, inExportType):65 stepName = "contextMenu file download - "+ appName +" / "+ inFileName +" / "+ inExportType66 67 if not target.processes()["Safari"].frontWindow():68 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].click()69 time.sleep(1)70 71 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name contains '"+ inFileName +"'"):72 bs_common.writeResults(testcaseId, stepName, "FAIL")73 msg = "FAIL - "+ stepName74 bs_common.scriptFailedExit(msg)75 76 myBounds = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name contains '"+ inFileName +"'").bounds() 77 x = Foundation.NSMidX(myBounds)78 y = Foundation.NSMidY(myBounds)79 yOffset = (y - 60)80 mouse.click_((x, yOffset))81 time.sleep(1) 82 keyboard.pressKey_(kVK_Control)83 mouse.click_((x, yOffset)) 84 keyboard.releaseKey_(kVK_Control)85 time.sleep(1)86 87 myAppFileType = getFileTypeFromAppName(appName)88 89 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].menuItems()["Download "+ myAppFileType +"..."].staticTexts()["Download "+ myAppFileType +"..."].click()90 time.sleep(1)91 92 myExportType, myUploadedType = getFileExportType(appName, inExportType)93 94 fileExportPattern = re.compile('https://www\.icloud\.com/applications/bight/(.+)/en-us/source/resources/export/(.+)')95 fileUploadedPattern = re.compile('https://www\.icloud\.com/applications/bight/(.+)/bight/core_docs/(.+)/en-us/source/resources/images/(.+)')96 for image in target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].images(): 97 urlString = image.url()98 99 if urlString is None:100 bs_common.writeResults(testcaseId, stepName, "FAIL")101 msg = "FAIL - match "+ appName +" / "+ inFileName +" / "+ inExportType102 bs_common.scriptFailedExit(msg)103 104 resultExportPattern = fileExportPattern.match(urlString)105 resultUploadPattern = fileUploadedPattern.match(urlString)106 107 if "ubiquityws.icloud.com" in urlString:108# This is a document manager object. Skip. 109 continue110 111 if not resultExportPattern is None: 112 urlExportImage = resultExportPattern.groups()[1]113 if urlExportImage == myExportType:114 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[inExportType].click()115 break116 117 if not resultUploadPattern is None:118 urlUploadImage = resultUploadPattern.groups()[2]119 if urlUploadImage == myUploadedType:120 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[inExportType].click()121 break122 123 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[u"Creating a file for download..."].waitForInvalid()124 125 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[u"Creating a file for download..."]:126 bs_common.writeResults(testcaseId, stepName, "FAIL") 127 msg = "FAIL - "+ stepName +": download dialog still valid"128 bs_common.scriptFailedExit(msg)129 130 else:131 bs_common.writeResults(testcaseId, stepName, "PASS")132 msg = "PASS - "+ stepName133 bs_common.writeItemToLogFile(msg)134 135 time.sleep(3)136 137def createNewFile(testcaseId, appName, fileName):138 stepName = "create - "+ appName +" / "+ fileName139# baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName]140 141 myFileType = getFileTypeFromAppName(appName)142 143 if not target.processes()["Safari"].frontWindow():144 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].click()145 time.sleep(2)146 147 with patience(30):148 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()["Create "+ myFileType].isEnabled()149 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()["Create "+ myFileType].isEnabled():150 myCreateObject = "Create " + myFileType151 myBounds = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[myCreateObject].bounds()152 x = Foundation.NSMidX(myBounds)153 y = Foundation.NSMidY(myBounds)154 yOffset = (y - 60)155 mouse.click_((x, yOffset))156 else:157 bs_common.writeResults(testcaseId, stepName, "FAIL")158 msg = "FAIL - "+ stepName159 bs_common.scriptFailedExit(msg)160 161 if not selectGilliganTemplate(appName, fileName):162 bs_common.writeResults(testcaseId, stepName, "FAIL")163 msg = "FAIL - "+ stepName164 bs_common.scriptFailedExit(msg)165 166 with patience(30):167 target.processes()["Safari"].mainWindow().webViews()[0].staticTexts()["Loading..."].waitForInvalid()168 169 if not target.processes()["Safari"].mainWindow().webViews()[0].elements()[0].buttons().firstWithPredicate_("name contains '%'"): 170 bs_common.writeResults(testcaseId, stepName, "FAIL")171 msg = "FAIL - "+ stepName172 bs_common.scriptFailedExit(msg)173 174 fileNameToSplit = re.sub(r"([A-Z])", r" \1", fileName).split()175 splitFileName = ' '.join(fileNameToSplit)176 177 if appName == "Keynote":178 splitFileName = "Presentation"179 if not target.processes()["Safari"].windows().firstWithPredicate_("name contains '"+ splitFileName +"'"):180# if not target.processes()["Safari"].mainWindow().name()[splitFileName]:181# if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name contains '"+ splitFileName +"'"):182 bs_common.writeResults(testcaseId, stepName, "FAIL")183 msg = "FAIL - "+ stepName +": window name is wrong"184 bs_common.scriptFailedExit(msg)185 186 else:187 bs_common.writeResults(testcaseId, stepName, "PASS")188 msg = "PASS - "+ stepName189 bs_common.writeItemToLogFile(msg)190def createNewFromTemplate(testcaseId, templateKey, runDataFile):191 (appName, templateName) = templateKey.split("_")192 stepName = "new from template '"+ templateKey +"'"193 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName]194 195 fileType = getFileTypeFromAppName(appName)196 time.sleep(1) 197 loadGilliganApp(testcaseId, appName)198 199 time.sleep(1)200 createNewFromFileType = "Create " + fileType201 202 myBounds = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[createNewFromFileType].bounds()203 x = Foundation.NSMidX(myBounds)204 y = Foundation.NSMidY(myBounds)205 yOffset = (y - 90)206 mouse.click_((x, yOffset)) 207 208 startTimer = selectGilliganTemplate(appName, templateName)209 210 with patience(60):211 target.processes()["Safari"].mainWindow().webViews()[0].staticTexts()["Loading..."].waitForInvalid()212 213 if target.processes()["Safari"].mainWindow().webViews()[0].elements()[0].buttons().firstWithPredicate_("name contains '%'"): 214 stopTimer = time.time()215 timingResult = (stopTimer - startTimer)216 formattedResult = '{0:.3g}'.format(timingResult)217 bs_common.writePerformanceTestResults(testcaseId, stepName, "PASS", formattedResult)218 target.processes()["Safari"].mainWindow().click()219 target.processes()["Safari"].mainWindow().closeButton().click()220 221 else:222 bs_common.writePerformanceTestResults(testcaseId, stepName, "FAIL", 0.00)223 msg = "FAIL - "+ appName + " '"+ templateName +"' creation failed"224 bs_common.scriptFailedExit(msg)225 226 checkFileSyncing(appName)227 228 validateObject = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons()["Go to the iCloud home screen"]229 validateResult = bs_common.validateObject(validateObject)230 231 if not validateResult:232 bs_common.writeResults(testcaseId, stepName, "FAIL")233 msg = "FAIL - bs_common.validateObject: "+ validateObject234 bs_common.scriptFailedExit(msg)235 236 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons()["Go to the iCloud home screen"].click()237 238 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons()["Cancel"].isEnabled():239 bs_common.writePerformanceTestResults(testcaseId, stepName, "FAIL", 0.00)240 msg = "FAIL - Something is wrong. Should not see the template screen"241 bs_common.scriptFailedExit(msg)242 243 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].groups().firstWithPredicate_("helpTag contains 'Try again later'"):244 bs_common.writePerformanceTestResults(testcaseId, stepName, "FAIL", 0.00)245 msg = "FAIL - "+ appName + " '"+ templateName +"' Received 'Could not be Created' dialog"246 bs_common.scriptFailedExit(msg)247 248 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].groups().firstWithPredicate_("helpTag contains 'Try again later'").buttons()["OK"].click()249 target.processes()["Safari"].mainWindow().click()250 target.processes()["Safari"].mainWindow().closeButton().click()251 252 validateObject = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons()["Go to the iCloud home screen"]253 validateResult = bs_common.validateObject(validateObject)254 255 if not validateResult:256 bs_common.writeResults(testcaseId, stepName, "FAIL")257 msg = "FAIL - bs_common.validateObject: "+ validateObject258 bs_common.scriptFailedExit(msg)259 260 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons()["Go to the iCloud home screen"].click()261 bs_common.writeItemStatus(runDataFile, templateKey, 1)262def deleteGilliganFiles(testcaseId, appName):263 stepName = "delete files in "+ appName 264 if not target.processes()["Safari"].frontWindow():265 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].click()266 time.sleep(1) 267 268 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons().firstWithPredicate_("helpTag like 'Go to the iCloud home screen'"):269 loadGilliganApp(testcaseId, appName)270 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].images():271 msg = "INFO - no files on document manager for "+ appName272 bs_common.writeItemToLogFile(msg)273 return274 275 time.sleep(1)276 fileCount = str(target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].images().count())277 278 time.sleep(1)279 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].images()[0].click()280 keyboard.typeString_withModifiersMask_("a", (kUIACommandKeyMask))281 keyboard.typeVirtualKey_(kVK_Delete)282 time.sleep(1)283 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].groups()[0].buttons()["Delete"].click()284 285 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].images().count() > 0:286 bs_common.writeResults(testcaseId, stepName, "FAIL")287 msg = "FAIL - "+ stepName288 bs_common.scriptFailedExit(msg)289 290 else:291 bs_common.writeResults(testcaseId, stepName, "PASS")292 msg = "INFO - deleted "+ fileCount +" files in "+ appName + " document manager"293 bs_common.writeItemToLogFile(msg)294 295def exitGilligan(testcaseId, appName):296 stepName = "exit gilligan from - "+ appName297 if not target.processes()["Safari"].frontWindow():298 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].click()299 time.sleep(1)300 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons().firstWithPredicate_("helpTag like 'Go to the iCloud home screen'"):301 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons().firstWithPredicate_("helpTag like 'Go to the iCloud home screen'").click()302 time.sleep(1)303 304 if target.processes()["Safari"].windows()["iCloud"].webViews()[0].buttons()["Sign Out"].isEnabled():305 bs_common.writeResults(testcaseId, appName, "PASS")306# msg = "PASS - "+ stepName307# bs_common.writeItemToLogFile(msg)308 309 else:310 msg = "FAIL - "+ stepName311 bs_common.scriptFailedExit(msg)312def fileClose(testcaseId, inFileName):313 stepName = "file close - "+ inFileName314 if target.processes()["Safari"].windows().firstWithPredicate_("name contains '"+ inFileName +"'"):315 target.processes()["Safari"].windows().firstWithPredicate_("name contains '"+ inFileName +"'").click()316 time.sleep(1)317 keyboard.typeString_withModifiersMask_("w", (kUIACommandKeyMask))318 bs_common.writeResults(testcaseId, stepName, "PASS")319 msg = "PASS - "+ stepName320 bs_common.writeItemToLogFile(msg)321 322 else:323 bs_common.writeResults(testcaseId, stepName, "FAIL")324 msg = "FAIL - "+ stepName325 bs_common.scriptFailedExit(msg)326 327def fileFindReplace(testcaseId, appName, inFileName, inFindText, inReplaceText):328 stepName = "find '"+ inFindText +"' replace '"+ inReplaceText +"'"329 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0]330 myResults = bs_common.getResultsData()331 332 if baseObjectPath.staticTexts()["Loading..."]:333 with patience(30):334 baseObjectPath.staticTexts()["Loading..."].waitForInvalid()335 336 if not target.processes()["Safari"].windows().firstWithPredicate_("name like '*"+ inFileName +"*'"):337 bs_common.writeItemToLogFile("INFO - failed to find "+ inFileName +" open")338 bs_common.writeResults(testcaseId, stepName, "FAIL")339 msg = "FAIL - "+ stepName340 bs_common.scriptFailedExit(msg) 341 342 keyboard.typeVirtualKey_withModifiersMask_(3, (kUIAControlKeyMask))343 baseObjectPath.buttons()[0].click()344 baseObjectPath.menuItems()["Find & Replace"].click()345 baseObjectPath.textFields()["Find"].click()346 keyboard.typeString_(inFindText)347 baseObjectPath.textFields()["Replace"].click()348 keyboard.typeString_(inReplaceText)349 350 if baseObjectPath.textFields()["Replace"].value() == inReplaceText:351 baseObjectPath.buttons()["Done\n"].click()352 bs_common.writeResults(testcaseId, stepName, "PASS") 353 msg = "PASS - "+ stepName354 bs_common.writeItemToLogFile(msg)355 356 else:357 bs_common.writeResults(testcaseId, stepName, "FAIL")358 msg = "FAIL - "+ stepName359 bs_common.scriptFailedExit(msg) 360def fileShowHelp(testcaseId, appName, inFileName):361 stepName = "show help for '"+ inFileName +"'"362 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0]363 myResults = bs_common.getResultsData()364 365 if not target.processes()["Safari"].windows().firstWithPredicate_("name like '*"+ inFileName +"*'"):366 bs_common.writeItemToLogFile("INFO - failed to find "+ inFileName +" open")367 bs_common.writeResults(testcaseId, stepName, "FAIL")368 msg = "FAIL - "+ stepName369 bs_common.scriptFailedExit(msg) 370 371 if baseObjectPath.elements().firstWithPredicate_("className like 'UIAToolbar'").buttons()["Tools"]:372 baseObjectPath.elements().firstWithPredicate_("className like 'UIAToolbar'").buttons()["Tools"].click()373 374 else:375 bs_common.writeItemToLogFile("INFO - failed to find toolbar")376 bs_common.writeResults(testcaseId, stepName, "FAIL")377 msg = "FAIL - "+ stepName378 bs_common.scriptFailedExit(msg)379 380 if baseObjectPath.menuItems()["Help"]:381 baseObjectPath.menuItems()["Help"].click()382 383 else:384 bs_common.writeItemToLogFile("INFO - failed to find menuItem")385 bs_common.writeResults(testcaseId, stepName, "FAIL")386 msg = "FAIL - "+ stepName387 bs_common.scriptFailedExit(msg) 388 389 if target.processes()["Safari"].windows()["iCloud Help"]:390 target.processes()["Safari"].windows()["iCloud Help"].closeButton().click()391 bs_common.writeResults(testcaseId, stepName , "PASS") 392 msg = "PASS - "+ stepName393 bs_common.writeItemToLogFile(msg)394 395 else:396 bs_common.writeItemToLogFile("INFO - failed to find help window")397 bs_common.writeResults(testcaseId, stepName, "FAIL")398 msg = "FAIL - "+ stepName399 bs_common.scriptFailedExit(msg)400 401def fileOpen(testcaseId, appName, inFileName):402 stepName = "file open - "+ appName +" / "+ inFileName 403 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'"):404 bs_common.writeResults(testcaseId, stepName, "FAIL")405 msg = "FAIL - "+ stepName406 bs_common.writeItemToLogFile(msg)407 408 myBounds = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'").bounds()409 x = Foundation.NSMidX(myBounds)410 y = Foundation.NSMidY(myBounds)411 yOffset = (y - 60)412 mouse.doubleClick_((x, yOffset)) 413 414 target.processes()["Safari"].mainWindow().webViews()[0].staticTexts()["Loading..."].waitForInvalid()415 416 if target.processes()["Safari"].mainWindow().webViews()[0].staticTexts()["Loading..."]:417 bs_common.writeResults(testcaseId, stepName, "FAIL")418 msg = "FAIL - "+ stepName419 bs_common.scriptFailedExit(msg)420 421 if not target.processes()["Safari"].mainWindow().webViews()[0].elements()[0].buttons().firstWithPredicate_("name contains '%'"): 422 bs_common.writeResults(testcaseId, stepName, "FAIL")423 msg = "FAIL - "+ stepName424 bs_common.scriptFailedExit(msg)425 426 else:427 bs_common.writeResults(testcaseId, stepName, "PASS")428 msg = "PASS - "+ stepName429 bs_common.writeItemToLogFile(msg)430 431def fileOpenUploaded(testcaseId, appName, inFileName):432 stepName = "file open - "+ appName +" / "+ inFileName 433 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'"):434 bs_common.writeResults(testcaseId, stepName, "FAIL")435 msg = "FAIL - "+ stepName +": file not found"436 bs_common.writeItemToLogFile(msg)437 438 myBounds = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'").bounds()439 x = Foundation.NSMidX(myBounds)440 y = Foundation.NSMidY(myBounds)441 yOffset = (y - 60)442 mouse.doubleClick_((x, yOffset)) 443 444 if target.processes()["Safari"].windows()[appName +" for iCloud beta"]: 445 timeoutCount = 1446 timeoutLimit = 120447 while timeoutCount <= timeoutLimit: 448 if target.processes()["Safari"].windows()[appName +" for iCloud beta"].webViews()[0].staticTexts()["Loading..."]: 449# print "*** INFO - object still valid"450 time.sleep(1)451 timeoutCount = timeoutCount + 1452 453 else:454 if timeoutCount >= 1:455# print "*** INFO - object should be invalid"456 break457 458 if target.processes()["Safari"].windows()[appName +" for iCloud beta"].webViews()[0].groups()[0]:459 target.processes()["Safari"].windows()[appName +" for iCloud beta"].webViews()[0].groups()[0].buttons()["Open"].click() 460 461 if not target.processes()["Safari"].windows()[appName +" for iCloud beta"].webViews()[0].staticTexts()["Loading..."]:462# print "*** INFO - stop checking"463 return True464 465# else:466# msg = "FAIL - "+ stepName +": failed white screen 'Loading...' validation"467# bs_common.scriptFailedExit(msg)468# return False469 470 target.processes()["Safari"].mainWindow().webViews()[0].staticTexts()["Loading..."].waitForInvalid()471 472 if target.processes()["Safari"].mainWindow().webViews()[0].staticTexts()["Loading..."]:473 bs_common.writeResults(testcaseId, stepName, "FAIL")474 msg = "FAIL - "+ stepName +": failed normal 'Loading...' validation"475 bs_common.scriptFailedExit(msg)476 477 if not target.processes()["Safari"].mainWindow().webViews()[0].elements()[0].buttons().firstWithPredicate_("name contains '%'"): 478 bs_common.writeResults(testcaseId, stepName, "FAIL")479 msg = "FAIL - "+ stepName +": failed to find % on toolbar"480 bs_common.scriptFailedExit(msg)481 482 else:483 bs_common.writeResults(testcaseId, stepName, "PASS")484 msg = "PASS - "+ stepName485 bs_common.writeItemToLogFile(msg) 486 487def fileRename(testcaseId, appName, inFileName, inFileRenamedTo):488 stepName = "file rename - "+ appName +" / "+ inFileName +" to "+ inFileRenamedTo489 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'"):490 bs_common.writeResults(testcaseId, stepName, "FAIL")491 msg = "FAIL - "+ stepName492 bs_common.scriptFailedExit(msg)493 494 try:495 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'").click()496 497 except:498 myBounds = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'").bounds()499 x = Foundation.NSMidX(myBounds)500 y = Foundation.NSMidY(myBounds)501 mouse.click_((x, y)) 502 503 keyboard.typeString_(inFileRenamedTo)504 keyboard.typeVirtualKey_(kVK_Return)505 506 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name contains '"+ inFileRenamedTo +"'"):507 bs_common.writeResults(testcaseId, stepName, "FAIL")508 msg = "FAIL - "+ stepName509 bs_common.scriptFailedExit(msg)510 511 else:512 bs_common.writeResults(testcaseId, stepName, "PASS") 513 msg = "PASS - "+ stepName514 bs_common.writeItemToLogFile(msg)515 516 time.sleep(3)517 518def formatMenuShowHide(testcaseId, appName, inFileName):519 stepName = "format menu show / hide"520 myResults = bs_common.getResultsData()521 522 if target.processes()["Safari"].windows()[inFileName]: 523 if target.processes()["Safari"].mainWindow().webViews()[0].buttons()["Text"]:524 if target.processes()["Safari"].mainWindow().webViews()[0].elements().firstWithPredicate_("className like 'UIAToolbar'").buttons()["Tools"]:525 target.processes()["Safari"].mainWindow().webViews()[0].elements().firstWithPredicate_("className like 'UIAToolbar'").buttons()["Tools"].click()526 527 if target.processes()["Safari"].mainWindow().webViews()[0].menuItems()["Hide Format Panel"].staticTexts()["Hide Format Panel"]:528 target.processes()["Safari"].mainWindow().webViews()[0].menuItems()["Hide Format Panel"].staticTexts()["Hide Format Panel"].click()529 530 else:531 bs_common.writeItemToLogFile("INFO - failed to find menuItem 'Hide Format Panel'")532 bs_common.writeResults(testcaseId, stepName, "FAIL")533 msg = "FAIL - "+ stepName534 bs_common.scriptFailedExit(msg)535 536 time.sleep(5)537 538 if target.processes()["Safari"].mainWindow().webViews()[0].elements().firstWithPredicate_("className like 'UIAToolbar'").buttons()["Tools"]:539 target.processes()["Safari"].mainWindow().webViews()[0].elements().firstWithPredicate_("className like 'UIAToolbar'").buttons()["Tools"].click()540 541 if target.processes()["Safari"].mainWindow().webViews()[0].menuItems()["Show Format Panel"].staticTexts()["Show Format Panel"]:542 target.processes()["Safari"].mainWindow().webViews()[0].menuItems()["Show Format Panel"].staticTexts()["Show Format Panel"].click()543 544 else:545 bs_common.writeItemToLogFile("INFO - failed to find menuItem 'Show Format Panel'")546 bs_common.writeResults(testcaseId, stepName, "FAIL")547 msg = "FAIL - "+ stepName548 bs_common.scriptFailedExit(msg)549 550 if target.processes()["Safari"].mainWindow().webViews()[0].buttons()["Text"]: 551 bs_common.writeResults(testcaseId, stepName, "PASS")552 msg = "PASS - "+ stepName553 bs_common.writeItemToLogFile(msg)554 555 else:556 bs_common.writeResults(testcaseId, stepName, "FAIL")557 msg = "FAIL - "+ stepName558 bs_common.scriptFailedExit(msg)559 560def gearMenu_fileDelete(testcaseId, appName, inFileName):561 stepName = "gearMenu file delete - "+ appName +" / "+ inFileName562 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[inFileName]:563 bs_common.writeResults(testcaseId, stepName, "FAIL")564 msg = "FAIL - "+ stepName565 bs_common.writeItemToLogFile(msg)566 567 myBounds = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[inFileName].bounds()568 x = Foundation.NSMidX(myBounds)569 y = Foundation.NSMidY(myBounds)570 yOffset = (y - 60)571 mouse.click_((x, yOffset))572 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons().firstWithPredicate_("name contains 'Document and Sort Options'").click()573 574 myAppFileType = getFileTypeFromAppName(appName)575 576 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].menuItems()[4].staticTexts()["Delete "+ myAppFileType].click()577 578 time.sleep(1)579 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].groups()[0].buttons()["Delete"].click()580 time.sleep(1)581 582 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[inFileName]:583 bs_common.writeResults(testcaseId, stepName, "FAIL")584 msg = "FAIL - "+ stepName585 bs_common.writeItemToLogFile(msg)586 587 else:588 bs_common.writeResults(testcaseId, stepName, "PASS") 589 msg = "PASS - "+ stepName590 bs_common.writeItemToLogFile(msg)591 592def gearMenu_fileDownload(testcaseId, appName, inFileName, inExportType):593 stepName = "gearMenu file download - "+ appName +" / "+ inFileName +" / "+ inExportType594 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name like '"+ inFileName +"'"):595 bs_common.writeResults(testcaseId, stepName, "FAIL")596 msg = "FAIL - bs_gilligan.gearMenu_fileDownload: file not found in document manager: "+ inFileName597 bs_common.scriptFailedExit(msg)598 599 myBounds = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name like '"+ inFileName +"'").bounds() 600 x = Foundation.NSMidX(myBounds)601 y = Foundation.NSMidY(myBounds)602 yOffset = (y - 60)603 mouse.click_((x, yOffset)) 604 605 try:606 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons().firstWithPredicate_("name contains 'Document and Sort Options'").click()607 608 except:609 bs_common.writeResults(testcaseId, stepName, "FAIL")610 msg = "FAIL - bs_gilligan.gearMenu_fileDownload: failed to click gearMenu button"611 bs_common.scriptFailedExit(msg)612 613 myAppFileType = getFileTypeFromAppName(appName)614 615 try:616 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].menuItems()["Download "+ myAppFileType +"..."].staticTexts()["Download "+ myAppFileType +"..."].click()617 618 except:619 bs_common.writeResults(testcaseId, stepName, "FAIL")620 msg = "FAIL - bs_gilligan.gearMenu_fileDownload: failed to click gearMenu menu item"621 bs_common.scriptFailedExit(msg)622 623 myExportType, myUploadedType = getFileExportType(appName, inExportType)624 625 fileExportPattern = re.compile('https://www\.icloud\.com/applications/bight/(.+)/en-us/source/resources/export/(.+)')626 fileUploadedPattern = re.compile('https://www\.icloud\.com/applications/bight/(.+)/bight/core_docs/(.+)/en-us/source/resources/images/(.+)')627 for image in target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].images(): 628 urlString = image.url()629 630 if urlString is None:631 bs_common.writeResults(testcaseId, stepName, "FAIL")632 msg = "FAIL - bs_gilligan.gearMenu_fileDownload: match failed for "+ inFileName633 bs_common.scriptFailedExit(msg)634 635 resultExportPattern = fileExportPattern.match(urlString)636 resultUploadPattern = fileUploadedPattern.match(urlString)637 638 if "ubiquityws.icloud.com" in urlString:639# This is a document manager object. Skip. 640 continue641 642 if not resultExportPattern is None: 643# print "*** matched export image pattern"644 urlExportImage = resultExportPattern.groups()[1]645 if urlExportImage == myExportType:646 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].images().firstWithPredicate_("url like '"+ urlString +"'").click()647 break648 649 if not resultUploadPattern is None:650# print "*** matched upload image pattern" 651 urlUploadImage = resultUploadPattern.groups()[2]652 if urlUploadImage == myUploadedType:653 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].images().firstWithPredicate_("url like '"+ urlString +"'").click()654 break655 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[u"Creating a file for download..."].waitForInvalid()656 657 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[u"Creating a file for download..."]:658 bs_common.writeResults(testcaseId, stepName, "FAIL") 659 msg = "FAIL - "+ stepName +": download dialog still valid"660 bs_common.scriptFailedExit(msg)661 662 else:663 bs_common.writeResults(testcaseId, stepName, "PASS")664 msg = "PASS - "+ stepName665 bs_common.writeItemToLogFile(msg)666 667 time.sleep(3)668 669def gearMenu_fileDuplicate(testcaseId, appName, inFileName):670 stepName = "gearMenu file duplicate - "+ appName +" / "+ inFileName671 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'"):672 bs_common.writeResults(testcaseId, stepName, "FAIL")673 msg = "FAIL - "+ stepName674 bs_common.writeItemToLogFile(msg)675 676 myBounds = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'").bounds()677 x = Foundation.NSMidX(myBounds)678 y = Foundation.NSMidY(myBounds)679 yOffset = (y - 60)680 mouse.click_((x, yOffset))681 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons().firstWithPredicate_("name contains 'Document and Sort Options'").click()682 683 myAppFileType = getFileTypeFromAppName(appName)684 685 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].menuItems()["Duplicate "+ myAppFileType].staticTexts()["Duplicate "+ myAppFileType].click()686 687 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name like '"+ inFileName +" copy'"):688 bs_common.writeResults(testcaseId, stepName, "FAIL")689 msg = "FAIL - "+ stepName690 bs_common.writeItemToLogFile(msg)691 692 else:693 bs_common.writeResults(testcaseId, stepName, "PASS") 694 msg = "PASS - "+ stepName695 bs_common.writeItemToLogFile(msg)696 697 time.sleep(3)698 699def gearMenu_fileUpload(testcaseId, appName, inFileName):700 stepName = "gearMenu file upload - "+ appName +" / "+ inFileName701 myConfigData = bs_common.getConfigurationData()702 myFileImportPath = myConfigData["fileImportPath"]703 myFileName, myFileExtenstion = inFileName.split(".")704 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons().firstWithPredicate_("name contains 'Document and Sort Options'").click()705 706 myAppFileType = getFileTypeFromAppName(appName)707 708 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].menuItems()["Upload "+ myAppFileType +"..."].staticTexts()["Upload "+ myAppFileType +"..."].click()709 710 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name like 'Choose * upload*'"):711 baseObjectPath.buttons()["Choose Files"].click()712 713 keyboard.typeString_withModifiersMask_("g", (kUIAShiftKeyMask|kUIACommandKeyMask))714 keyboard.typeString_(myFileImportPath +"/"+ inFileName) 715 keyboard.typeVirtualKey_(kVK_Return)716 time.sleep(1)717 target.processes()["Safari"].mainWindow().sheet().buttons()["Choose"].click()718 719 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons()["Cancel\n"].waitForInvalid()720 721 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name like '"+ myFileName +"*'"):722 bs_common.writeResults(testcaseId, stepName, "FAIL")723 msg = "FAIL - "+ stepName724 bs_common.scriptFailedExit(msg)725 726 else:727 bs_common.writeResults(testcaseId, stepName, "PASS") 728 msg = "PASS - "+ stepName729 bs_common.writeItemToLogFile(msg)730 731def getFileExportType(appName, exportType):732 if appName == "Pages" and exportType == "Pages":733 return "export-pages.png", "uploaded_pages.jpg"734 735 elif appName == "Pages" and exportType == "Word":736 return "export-word.png", "uploaded_word.jpg"737 738 elif appName == "Numbers" and exportType == "Numbers":739 return "export-numbers.png", "uploaded_numbers.jpg"740 741 elif appName == "Numbers" and exportType == "Excel":742 return "export-excel.png", "uploaded_excel.jpg"743 744 elif appName == "Keynote" and exportType == "Keynote":745 return "export-keynote.png", "uploaded_keynote.jpg" 746 747 elif appName == "Keynote" and exportType == "PowerPoint":748 return "export-powerpoint.png", "uploaded_powerpoint.jpg"749 750 elif exportType == "PDF":751 return "export-pdf.png", "export_pdf.png"752 753def getFileTypeFromAppName(appName):754 if appName == "Keynote":755 fileType = "Presentation"756 return fileType757 elif appName == "Numbers":758 fileType = "Spreadsheet"759 return fileType760 elif appName == "Pages":761 fileType = "Document"762 return fileType763 764def loadGilliganApp(testcaseId, appName):765 stepName = "load gilligan "+ appName 766 time.sleep(1)767 768 try:769 target.processes()["Safari"].mainWindow().webViews()[0].buttons()[appName].click()770 771 except:772 bs_common.writeResults(testcaseId, stepName, "FAIL")773 msg = "FAIL - bs_gilligan.loadGilliganApp: failed to click app icon"774 bs_common.scriptFailedExit(msg)775 776 target.processes()["Safari"].mainWindow().webViews()[0].staticTexts()["Loading..."].waitForInvalid()777 778 if target.processes()["Safari"].mainWindow().webViews()[0].staticTexts()["Loading..."]:779 bs_common.writeResults(testcaseId, stepName, "FAIL")780 msg = "FAIL - bs_gilligan.loadGilliganApp: loading... still valid"781 bs_common.scriptFailedExit(msg)782 783 if not target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[appName +" for iCloud"]:784 785 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons().firstWithPredicate_("name contains 'Get started with'").isEnabled() == True:786 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons().firstWithPredicate_("name contains 'Get started with'").click()787 788 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts().firstWithPredicate_("name contains 'Choose a Template'").isEnabled() == True:789 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons().firstWithPredicate_("name contains 'Cancel'").click()790 791 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].menuItems().firstWithPredicate_("name contains 'Learn More About'").isEnabled() == True:792 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons()["Show help"].click() 793 794 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].staticTexts()[appName +" for iCloud"]:795 bs_common.writeResults(testcaseId, stepName, "PASS")796 msg = "PASS - "+ stepName 797 bs_common.writeItemToLogFile(msg)798 799 else:800 bs_common.writeResults(testcaseId, stepName, "FAIL")801 msg = "FAIL - bs_gilligan.loadGilliganApp: failed to find proper app state"802 bs_common.scriptFailedExit(msg)803 804def modifySpreadsheetTabs(testcaseId, inFileName):805 stepName = "modify spreadsheet tabs"806 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0]807 myResults = bs_common.getResultsData()808 809 if baseObjectPath.staticTexts()["Loading..."]:810 with patience(30):811 baseObjectPath.staticTexts()["Loading..."].waitForInvalid()812 813 if not target.processes()["Safari"].windows().firstWithPredicate_("name like '*"+ inFileName +"*'"):814 bs_common.writeItemToLogFile("INFO - failed to find "+ inFileName +" open")815 bs_common.writeResults(testcaseId, stepName, "FAIL")816 msg = "FAIL - "+ stepName817 bs_common.scriptFailedExit(msg) 818 819 baseObjectPath.buttons()[0].click()820 time.sleep(1)821 baseObjectPath.buttons()[0].click()822 time.sleep(1)823 824 if not baseObjectPath.staticTexts()["Sheet 1"] and baseObjectPath.staticTexts()["Sheet 2"]:825 bs_common.writeItemToLogFile("INFO - failed to find new spreadsheet tabs")826 bs_common.writeResults(testcaseId, stepName, "FAIL")827 msg = "FAIL - "+ stepName828 bs_common.scriptFailedExit(msg) 829 830 keyboard.pressKey_(kVK_Control)831 baseObjectPath.staticTexts()["Sheet 2"].click()832 keyboard.releaseKey_(kVK_Control)833 baseObjectPath.menuItems()["Delete Sheet"].staticTexts()["Delete Sheet"].click()834 time.sleep(1)835 836 if baseObjectPath.staticTexts()["Sheet 2"]:837 bs_common.writeItemToLogFile("INFO - failed to delete tab 'Sheet 2'")838 bs_common.writeResults(testcaseId, stepName, "FAIL")839 msg = "FAIL - "+ stepName840 bs_common.scriptFailedExit(msg) 841 842 baseObjectPath.staticTexts()["Sheet 1"].click()843 baseObjectPath.staticTexts()["Sheet 1"].doubleClick()844 keyboard.typeString_("Bills")845 keyboard.typeVirtualKey_(kVK_Return)846 time.sleep(1)847 848 if not baseObjectPath.staticTexts()["Bills"]:849 bs_common.writeItemToLogFile("INFO - failed to rename tab")850 bs_common.writeResults(testcaseId, stepName, "FAIL")851 msg = "FAIL - "+ stepName852 bs_common.scriptFailedExit(msg) 853 854 else:855 bs_common.writeResults(testcaseId, stepName, "PASS")856 msg = "PASS - "+ stepName857 bs_common.writeItemToLogFile(msg)858 859def selectGilliganTemplate(appName, inFileName): 860 stepName = "select template: "+ inFileName861 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName]862 filePattern = re.compile('https://www\.icloud\.com/applications/bight/(.+)/bight/templates/(.+)/en-us/source/(.+)/(.+)\.(.+)')863 864 fileFindTries = 0865 fileFound = False866 867 while fileFindTries < 4 and not fileFound:868 for image in baseObjectPath.images():869 urlString = image.url()870 result = filePattern.match(urlString)871 if "ubiquityws.icloud.com" in urlString:872# This is a document manager object. Skip. 873 continue874 875 if result is None:876 sys.stderr.write("%s '%s' could not match pattern in url '%s'\n" % (appName, inFileName, urlString))877 return False878 879 urlAppName = result.groups()[2]880 urlAppVersion = result.groups()[0]881 urlAppfile = result.groups()[3]882 883 strippedFileName = "".join(inFileName.split())884 885 if not urlAppfile == strippedFileName:886 continue887 888 else:889 image.click()890 time.sleep(1)891 baseObjectPath.buttons().firstWithPredicate_("name contains 'Choose'").click()892 startTimer = time.time()893 fileFound = True894 return startTimer895 break896 897 keyboard.typeVirtualKey_(kVK_DownArrow)898 time.sleep(1)899 fileFindTries = fileFindTries + 1900 901 if fileFindTries == 2 and not fileFound:902 sys.stderr.write(appName + " '"+ inFileName +"' not found\n")903 return False904 905def validateGearMenu(testcaseId, appName):906 stepName = "validate gearMenu"907 myReturnStatus = True908# baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName]909 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons().firstWithPredicate_("name contains 'Document and Sort Options'").isValid():910 myAppFileType = getFileTypeFromAppName(appName)911 912 myMenuItem = ["Create", "Upload", "Download", "Duplicate", "Delete", "Share", "Send"]913 target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].buttons().firstWithPredicate_("name contains 'Document and Sort Options'").click()914 915 itemIndex = 0916 for item in myMenuItem: 917 if target.processes()["Safari"].mainWindow().webViews()[0].webViews()[appName].menuItems()[itemIndex].staticTexts().firstWithPredicate_("value contains '"+ item +"'"):918 msg = "PASS - gearMenu - '"+ item +"'"919 bs_common.writeItemToLogFile(msg)920 itemIndex = itemIndex + 1921 922 else:923 msg = "FAIL - gearMenu - '"+ item +"'"924 bs_common.writeItemToLogFile(msg)925 itemIndex = itemIndex + 1926 myReturnStatus = False927 928 if not myReturnStatus:929 keyboard.typeVirtualKey_(kVK_Escape)930 bs_common.writeResults(testcaseId, stepName, "FAIL")931 msg = "FAIL - "+ stepName...

Full Screen

Full Screen

bs_bight.py

Source:bs_bight.py Github

copy

Full Screen

...24def fileRename(testcaseId, appName, inFileToRename, inFileToRenameTo):25 stepName = "file rename from '"+ inFileToRename +"' to '"+ inFileToRenameTo +"'"26 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0].webViews().firstWithPredicate_("className like 'UIAWebView'")27 baseObjectPath.buttons().firstWithPredicate_("name contains '"+ appName +"'").click() 28 if not baseObjectPath.staticTexts().firstWithPredicate_("name like '*"+ inFileToRename +"*'"):29 bs_common.writeResults(testcaseId, stepName, "FAIL")30 msg = "FAIL - "+ stepName31 bs_common.scriptFailedExit(msg)32 baseObjectPath.staticTexts().firstWithPredicate_("name like '*"+ inFileToRename +"*'").doubleClick() 33 keyboard.typeString_(inFileToRenameTo)34 keyboard.typeVirtualKey_(kVK_Return)35 36 if not baseObjectPath.staticTexts().firstWithPredicate_("name like '*"+ inFileToRenameTo +"*'"):37 bs_common.writeResults(testcaseId, stepName, "FAIL")38 msg = "FAIL - "+ stepName39 bs_common.scriptFailedExit(msg)40 41 else:42 bs_common.writeResults(testcaseId, stepName, "PASS") 43 msg = "PASS - "+ stepName44 bs_common.writeItemToLogFile(msg)45 46def fileReplace(testcaseId, appName, inFileName, inNewFileName):47 stepName = "file replace - '"+ inFileName +"' with '"+ inNewFileName +"'"48 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0].webViews().firstWithPredicate_("className like 'UIAWebView'")49 myConfigData = bs_common.getConfigurationData()50 myFileImportPath = myConfigData["fileImportPath"]51 52 baseObjectPath.buttons().firstWithPredicate_("name contains '"+ appName +"'").click() 53 if not baseObjectPath.staticTexts().firstWithPredicate_("name like '*"+ inFileName +"*'"):54 bs_common.writeResults(testcaseId, stepName, "FAIL")55 msg = "FAIL - "+ stepName56 bs_common.scriptFailedExit(msg)57 58 baseObjectPath.buttons().firstWithPredicate_("name contains 'Document and Sort Options'").click()59 60 myAppFileType = getFileTypeFromAppName(myAppName)61 62 baseObjectPath.menuItems()["Upload "+ myAppFileType +"..."].staticTexts()["Upload "+ myAppFileType +"..."].click() 63 keyboard.typeString_withModifiersMask_("g", (kUIAShiftKeyMask|kUIACommandKeyMask))64 keyboard.typeString_(myFileImportPath)65 target.processes()["Safari"].mainWindow().sheet().buttons()["Go"].click()66 67 target.processes()["Safari"].mainWindow().sheet().radioButtons()["list view"].click() 68 target.processes()["Safari"].mainWindow().sheet().outlines()["list view"].visibleColumns()["Name"].textFields()[0].click()69 70 for i in target.processes()["Safari"].mainWindow().sheet().outlines()["list view"].visibleColumns()["Name"].textFields():71 if i.value() == item:72 target.processes()["Safari"].mainWindow().sheet().buttons()["Choose"].click()73 break74 75 else:76 keyboard.typeVirtualKey_(kVK_DownArrow)77 78 if baseObjectPath.buttons()["Replace\n"]:79 baseObjectPath.buttons()["Replace\n"].click()80 81def fileDelete(testcaseId, appName, inFileName):82 stepName = "file delete - "+ appName +" / "+ inFileName83 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0].webViews().firstWithPredicate_("className like 'UIAWebView'")84 85 baseObjectPath.buttons().firstWithPredicate_("name contains '"+ appName +"'").click() 86 87 myFileName, myFileExtension = os.path.splitext(inFileName) 88 89 if not baseObjectPath.staticTexts()[myFileName]:90 bs_common.writeResults(testcaseId, stepName, "FAIL")91 msg = "FAIL - "+ stepName92 bs_common.scriptFailedExit(msg)93 94 myBounds = baseObjectPath.staticTexts()[myFileName].bounds()95 x = Foundation.NSMidX(myBounds)96 y = Foundation.NSMidY(myBounds)97 yOffset = (y - 60)98 mouse.click_((x, yOffset))99 keyboard.typeVirtualKey_(kVK_Delete)100 101 time.sleep(1)102 baseObjectPath.groups()[0].buttons()["Delete"].click()103 time.sleep(1)104 105 if baseObjectPath.staticTexts()[myFileName]:106 bs_common.writeResults(testcaseId, stepName, "FAIL")107 msg = "FAIL - "+ stepName108 bs_common.scriptFailedExit(msg)109 110 else:111 bs_common.writeResults(testcaseId, stepName, "PASS") 112 msg = "PASS - "+ stepName113 bs_common.writeItemToLogFile(msg)114def folderRename(testcaseId, appName, inFolderToRename, inFolderRenameTo):115 stepName = "folder rename from '"+ inFolderToRename +"' to '"+ inFolderRenameTo +"'"116 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0].webViews().firstWithPredicate_("className like 'UIAWebView'")117 baseObjectPath.buttons().firstWithPredicate_("name contains '"+ appName +"'").click() 118 if not baseObjectPath.staticTexts().firstWithPredicate_("name like '*"+ inFolderToRename +"*'"):119 bs_common.writeResults(testcaseId, stepName, "FAIL")120 msg = "FAIL - "+ stepName121 bs_common.scriptFailedExit(msg)122 123# baseObjectPath.staticTexts().firstWithPredicate_("name like '*"+ inFolderToRename +"*'").click() 124 baseObjectPath.staticTexts()[inFolderToRename].click()125 126# myBounds = baseObjectPath.staticTexts().firstWithPredicate_("name like '*"+ inFolderToRename +"*'").bounds()127 myBounds = baseObjectPath.staticTexts()[inFolderToRename].bounds()128 x = Foundation.NSMidX(myBounds)129 y = Foundation.NSMidY(myBounds)130 yOffset = (y + 60)131 mouse.click_((x, yOffset)) 132 keyboard.typeString_(inFolderRenameTo)133 keyboard.typeVirtualKey_(kVK_Return)134 135# if not baseObjectPath.staticTexts().firstWithPredicate_("name like '*"+ inFolderRenameTo +"*'"):136 if not baseObjectPath.staticTexts()[inFolderRenameTo]:137 bs_common.writeResults(testcaseId, stepName, "FAIL")138 msg = "FAIL - "+ stepName139 bs_common.scriptFailedExit(msg)140 141 else:142 yOffset = (y - 90)143 mouse.click_((x, yOffset))144 bs_common.writeResults(testcaseId, stepName, "PASS") 145 msg = "PASS - "+ stepName146 bs_common.writeItemToLogFile(msg)147 148def folderDelete(testcaseId, appName, inFolderName):149 stepName = "folder delete - "+ appName +" / "+ inFolderName150 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0].webViews().firstWithPredicate_("className like 'UIAWebView'")151 152 baseObjectPath.buttons().firstWithPredicate_("name contains '"+ appName +"'").click() 153 154 if not baseObjectPath.staticTexts().firstWithPredicate_("name like '"+ inFolderName +"'"):155 bs_common.writeResults(testcaseId, stepName, "FAIL")156 msg = "FAIL - "+ stepName157 bs_common.scriptFailedExit(msg)158 159 baseObjectPath.staticTexts().firstWithPredicate_("name like '"+ inFolderName +"'").click()160 161 while baseObjectPath.staticTexts().firstWithPredicate_("name like '"+ inFolderName +"*'"): 162 if baseObjectPath.staticTexts().firstWithPredicate_("name like 'No Presentations'").isValid():163 bs_common.writeItemToLogFile("INFO - Folder should be deleted now")164 165 else: 166 if baseObjectPath.staticTexts().firstWithPredicate_("name like 'Presentation*'"):167 myBounds = baseObjectPath.staticTexts().firstWithPredicate_("name like 'Presentation*'").bounds()168 x = Foundation.NSMidX(myBounds)169 y = Foundation.NSMidY(myBounds)170 yOffset = (y - 60)171 172 mouse.click_((x, yOffset)) 173 keyboard.typeVirtualKey_(kVK_Delete) 174 time.sleep(1)175 baseObjectPath.groups()[0].buttons()["Delete"].click()176 177 if baseObjectPath.staticTexts().firstWithPredicate_("name like '"+ inFolderName +"*'"):178 bs_common.writeResults(testcaseId, stepName, "FAIL")179 msg = "FAIL - "+ stepName180 bs_common.scriptFailedExit(msg)181 182 else:183 bs_common.writeResults(testcaseId, stepName, "PASS") 184 msg = "PASS - "+ stepName185 bs_common.writeItemToLogFile(msg)186def gearMenu_fileDownload(testcaseId, appName, inFileName, inFileFormat):187 stepName = "gearMenu file download '"+ inFileName +"' as '"+ inFileFormat +"'"188 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0].webViews().firstWithPredicate_("className like 'UIAWebView'")189 baseObjectPath.buttons().firstWithPredicate_("name contains '"+ appName +"'").click() 190 191 if not baseObjectPath.staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'"):192 bs_common.writeResults(testcaseId, stepName, "FAIL")193 msg = "FAIL - "+ stepName194 bs_common.scriptFailedExit(msg)195 196 myBounds = baseObjectPath.staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'").bounds()197 x = Foundation.NSMidX(myBounds)198 y = Foundation.NSMidY(myBounds)199 yOffset = (y - 60)200 mouse.click_((x, yOffset)) 201 202 myAppFileType = getFileTypeFromAppName(appName)203 204 baseObjectPath.buttons().firstWithPredicate_("name contains 'Document and Sort Options'").click()205 baseObjectPath.menuItems()["Download "+ myAppFileType +"..."].staticTexts()["Download "+ myAppFileType +"..."].click() 206 207 if baseObjectPath.staticTexts()["Choose a download format."]:208 baseObjectPath.staticTexts()[inFileFormat].click()209 210 timeout = 0211 if baseObjectPath.staticTexts().firstWithPredicate_("value like '*Creating a file for download*'"):212 while timeout < 120:213 if bool(baseObjectPath.staticTexts().firstWithPredicate_("value like '*Creating a file for download*'").isValid()):214 time.sleep(1)215 timeout = timeout + 1216 217 else:218 if timeout > 0:219 break 220 bs_common.writeResults(testcaseId, stepName, "PASS") 221 msg = "PASS - "+ stepName222 bs_common.writeItemToLogFile(msg) 223 224def gearMenu_fileDuplicate(testcaseId, appName, inFileName):225 stepName = "gearMenu file duplicate - "+ inFileName226 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0].webViews().firstWithPredicate_("className like 'UIAWebView'")227 228 myAppFileType = getFileTypeFromAppName(appName)229 baseObjectPath.buttons().firstWithPredicate_("name contains '"+ appName +"'").click() 230 if not baseObjectPath.staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'"):231 bs_common.writeResults(testcaseId, stepName, "FAIL")232 msg = "FAIL - "+ stepName233 bs_common.scriptFailedExit(msg)234 235 myBounds = baseObjectPath.staticTexts().firstWithPredicate_("name beginswith '"+ inFileName +"'").bounds()236 x = Foundation.NSMidX(myBounds)237 y = Foundation.NSMidY(myBounds)238 yOffset = (y - 60)239 mouse.click_((x, yOffset)) 240 241 baseObjectPath.buttons().firstWithPredicate_("name contains 'Document and Sort Options'").click()242 baseObjectPath.menuItems()["Duplicate "+ myAppFileType].staticTexts()["Duplicate "+ myAppFileType].click() 243 244 if not baseObjectPath.staticTexts().firstWithPredicate_("name like '*"+ inFileName +"*copy'"):245 bs_common.writeResults(testcaseId, stepName, "FAIL")246 msg = "FAIL - "+ stepName247 bs_common.scriptFailedExit(msg)248 249 else:250 bs_common.writeResults(testcaseId, stepName, "PASS") 251 msg = "PASS - "+ stepName252 bs_common.writeItemToLogFile(msg)253def gearMenu_fileUpload(testcaseId, item):254 stepName = "gearMenu file upload - "+ item255 baseObjectPath = target.processes()["Safari"].mainWindow().webViews()[0].webViews().firstWithPredicate_("className like 'UIAWebView'")256 myConfigData = bs_common.getConfigurationData()257 myFileImportPath = myConfigData["fileImportPath"]258 259 myFileName, myAppName = getAppNameAndFileName(item)260 261 baseObjectPath.buttons().firstWithPredicate_("name contains '"+ myAppName +"'").click() 262 baseObjectPath.buttons().firstWithPredicate_("name contains 'Document and Sort Options'").click()263 264 myAppFileType = getFileTypeFromAppName(myAppName)265 266 baseObjectPath.menuItems()["Upload "+ myAppFileType +"..."].staticTexts()["Upload "+ myAppFileType +"..."].click() 267 keyboard.typeString_withModifiersMask_("g", (kUIAShiftKeyMask|kUIACommandKeyMask))268 keyboard.typeString_(myFileImportPath)269 target.processes()["Safari"].mainWindow().sheet().buttons()["Go"].click()270 271 target.processes()["Safari"].mainWindow().sheet().radioButtons()["list view"].click() 272 target.processes()["Safari"].mainWindow().sheet().outlines()["list view"].visibleColumns()["Name"].textFields()[0].click()273 274 for i in target.processes()["Safari"].mainWindow().sheet().outlines()["list view"].visibleColumns()["Name"].textFields():275 if i.value() == item:276 target.processes()["Safari"].mainWindow().sheet().buttons()["Choose"].click()277 break278 279 else:280 keyboard.typeVirtualKey_(kVK_DownArrow)281 282 time.sleep(2)283 284 if baseObjectPath.buttons()["Replace\n"]:285 baseObjectPath.buttons()["Replace\n"].click()286 287 timeout = 0288 if baseObjectPath.staticTexts().firstWithPredicate_("value like '*Uploading*'"):289 while timeout < 120:290 if bool(baseObjectPath.staticTexts().firstWithPredicate_("value like '*Uploading*'").isValid()):291 time.sleep(1)292 timeout = timeout + 1293 294 else:295 if timeout > 0:296 break 297 298 if not baseObjectPath.staticTexts().firstWithPredicate_("name like '*"+ myFileName +"*'"):299 bs_common.writeResults(testcaseId, stepName, "FAIL")300 msg = "FAIL - "+ stepName301 bs_common.scriptFailedExit(msg)302 303 else:304 bs_common.writeResults(testcaseId, stepName, "PASS") 305 msg = "PASS - "+ stepName306 bs_common.writeItemToLogFile(msg)307def getAppNameAndFileName(inItem):308 myFileName, myFileExtension = os.path.splitext(inItem)309 310 if myFileExtension == ".key":311 myAppName = "Keynote"312 ...

Full Screen

Full Screen

topiccombs_xiaoiqa.py

Source:topiccombs_xiaoiqa.py Github

copy

Full Screen

1#!/usr/bin/python2# -*- coding: utf-8 -*-3#########################################################################4# File Name: topiccombs_xiaoiqa.py5# Author: yaojia6# mail: hityaojia@163.com 7# Created Time: 2016-08-24 10:08:258#########################################################################9import os10import sys11import random12import json13import re14import time15pwd = data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".")16class xiaoiqa:17 def __init__(self, para_path = pwd + "/data/xiaoiqa_para", baseqa_path = pwd + "/data/xiaoiqa_baseqa", allcatg_path = pwd + "/data/xiaoiqa_catg", \18 domainqa_path = pwd + "/data/xiaoiqa_domainqa", catgqa_path = pwd + "/data/xiaoiqa_catgqa", catgokqa_path = pwd + "/data/xiaoiqa_catgokqa",\19 startsearch_path = pwd + "/data/xiaoiqa_gosearchqa", domainqa_catg_path = pwd + "/data/xiaoiqa_domaincatg"):20 self.para2name = {}21 self.baseqa = []22 self.catgs = set()23 self.domainqa = {}24 self.domaincatgs = set()25 self.catgqa = {}26 self.catgokqa = {}27 self.startsearchqa = set()28 self.joinword = [u"还是", u"或是", u"?", u"呢?", u"或者", u"或"]29 self.search_re = u"(搜索|查.{0,3}下|搜.{0,3}下|查查|搜搜|检索|查询)"30 self.dictload(self.para2name, para_path)31 self.dictload(self.domainqa, domainqa_path)32 self.dictload(self.catgqa, catgqa_path)33 self.dictload(self.catgokqa, catgokqa_path)34 self.listload(self.baseqa, baseqa_path)35 self.setload(self.catgs, allcatg_path)36 self.setload(self.domaincatgs, domainqa_catg_path)37 self.setload(self.startsearchqa, startsearch_path)38 def setload(self, _set, path):39 for line in open(path):40 _set.add(line.strip().decode("utf-8"))41 def listload(self, _list, path):42 for line in open(path):43 _list.append(line.strip().decode("utf-8"))44 def dictload(self, _dict, path):45 for line in open(path):46 infos = line.strip().decode("utf-8").split(" ", 1)47 if len(infos) != 2:continue48 if infos[0] not in _dict:49 _dict[infos[0]] = infos[1].split()50 else:51 for tem in infos[1].split():52 _dict[infos[0]].append(tem)53 def dictrandom(self, _dict):54 sortedkeys = sorted(_dict.keys())55 randtexts = [ random.sample(_dict[key], 1)[0] for key in sortedkeys]56 return randtexts57 def baseanswer(self, queryobj, topicobj, contexts = [[]] ):58 if re.search(self.search_re, queryobj.rawtext):59 topicobj["Slots"]["Gosearch"] = 160 return random.sample(self.startsearchqa, 1)[0]61 topicobj["Slots"]["Gosearch"] = 062 return random.sample(self.baseqa, 1)[0]63 def domainanswer(self):64 twocatgs = random.sample(self.domaincatgs, 2)65 joinword = random.sample(self.joinword, 1)[0]66 catgs = joinword.join(twocatgs) + "?"67 startwords = u"要 查 看 找".split()68 catgs = random.sample(startwords, 1)[0] + catgs69 statictexts = self.dictrandom(self.domainqa)70 insertpos = 1#random.sample(range(2), 1)[0]71 statictexts.insert(insertpos, catgs)72 return "".join(statictexts)73 def catganswer(self, queryobj, topicdict):74 has_pars = set(topicdict.get("Slots", {}).keys())75 all_pars = set(self.para2name.keys())76 has_no_pars = all_pars - has_pars77 #如果获取到的参数已经足够多了,表示可以搜索了,Gosearch==178 if len(all_pars) - len(has_no_pars) > 1:79 topicdict["Slots"]["Gosearch"] = 180 return random.sample(self.startsearchqa, 1)[0]#u"开始搜索"81 #如果句子直接有搜索的含义,直接开始搜索82 if re.search(self.search_re, queryobj.rawtext) and len(all_pars) - len(has_no_pars) > 0:83 topicdict["Slots"]["Gosearch"] = 184 return random.sample(self.startsearchqa, 1)[0]#u"开始搜索"85 #如果has_no_pars为空,表示需要是否直接返回一般句式86 topicdict["Slots"]["Gosearch"] = 087 if not has_no_pars:88 statictexts = self.dictrandom(self.catgokqa)89 return "".join(statictexts)90 else:91 statictexts = self.dictrandom(self.catgqa)92 pars = random.sample(has_no_pars, 1)[0]93 parnames = self.para2name[pars]94 parname = random.sample(parnames, 1)[0]95 statictexts.insert(2, parname)96 return "".join(statictexts)97 def qamain(self, queryobj, topic_obj, contexts = [[]] ):98 if type(topic_obj) is not list:99 topic_obj = [topic_obj]100 for topic_dict in topic_obj:101 #print "++++"102 #print json.dumps(topic_dict, ensure_ascii=False)103 domain = topic_dict.get("Domain", "")104 answer = ""105 searchok = topic_dict["Slots"].get("Searchtag", 0)106 if domain == u"基础交互":107 answer = self.baseanswer(queryobj, topic_dict, contexts)108 searchok = searchok 109 110 if domain == u"商品":111 answer = self.domainanswer()112 searchok = 0113 114 if domain in self.catgs:115 answer = self.catganswer(queryobj, topic_dict)116 searchok = 1117 118 if answer:119 topic_dict["Slots"]["Suggestion"] = answer120 topic_dict["Slots"]["Searchtag"] = searchok121 #print answer122 #return answer123 return topic_obj124xiaoiqaobj = xiaoiqa()125Combxiaoiqa = xiaoiqaobj.qamain126 127#t_dict = {128# "Domain":u"男上装",129# "Slots":{130# "price":1,131# "discount":2,132# "distance":1,133# "rating":2,134# "reputation":1,135# "attention":4,136# }137# }138#obj = xiaoiqa()139#print obj.qamain(t_dict)140#...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful