|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 |
|
3 | 3 | import os, sys, requests, json, logging, time, httplib, base64 |
4 | | -from PIL import Image |
5 | 4 | from optparse import OptionParser |
6 | 5 | from datetime import datetime |
7 | 6 |
|
8 | | -__version__ = '2.41.2' |
| 7 | +__version__ = '2.41.4' |
9 | 8 |
|
10 | 9 | FORMAT = "%(message)s" |
11 | 10 | logging.basicConfig(format=FORMAT) |
@@ -427,45 +426,38 @@ def set_project_framework(self, project_id, frameworkId): |
427 | 426 | """ Start a test run on a device group |
428 | 427 | """ |
429 | 428 | def start_test_run(self, project_id, device_group_id=None, device_model_ids=None, name=None, additional_params={}): |
430 | | - me = self.get_me() |
431 | | - payload={} if name is None else {'name':name} |
| 429 | + # check project validity |
432 | 430 | project = self.get_project(project_id) |
433 | 431 | if not 'id' in project: |
434 | 432 | print "Project %s not found" % project_id |
435 | 433 | sys.exit(1) |
436 | 434 |
|
437 | | - if device_group_id is None and device_model_ids is None: |
438 | | - print "Device group or device models must be defined" |
439 | | - sys.exit(1) |
440 | | - |
441 | | - if device_group_id is not None: |
442 | | - device_group = self.get("users/%s/device-groups/%s" % (me['id'], device_group_id)) |
443 | | - if not 'id' in device_group: |
444 | | - print "Device group %s not found" % device_group_id |
445 | | - sys.exit(1) |
446 | | - |
447 | | - if int(device_group['deviceCount']) == 0: |
448 | | - print "ERROR: No devices at device group %s" % device_group['id'] |
449 | | - sys.exit(1) |
| 435 | + # start populating parameters for the request payload... |
| 436 | + payload={} |
450 | 437 |
|
451 | | - # Update device group |
452 | | - reply = self.set_project_config(project_id=project_id, payload={'usedDeviceGroupId': device_group_id}) |
453 | | - if int(reply['usedDeviceGroupId']) != int(device_group_id): |
454 | | - print "Unable to set used device group to %s for project %s" % (device_group_id, project_id) |
455 | | - sys.exit(1) |
456 | | - print "Starting test run on project %s \"%s\" using device group %s \"%s\"" % (project['id'], project['name'], device_group['id'], device_group['displayName']) |
| 438 | + if name is not None: |
| 439 | + payload['name'] = name |
457 | 440 |
|
| 441 | + if device_group_id is not None: |
| 442 | + payload['usedDeviceGroupId'] = device_group_id |
| 443 | + print "Starting test run on project %s \"%s\" using device group %s" % (project['id'], project['name'], device_group_id) |
| 444 | + elif device_model_ids is not None: |
| 445 | + payload['usedDeviceIds[]'] = device_model_ids |
| 446 | + print "Starting test run on project %s \"%s\" using device models ids %s" % (project['id'], project['name'], device_model_ids) |
458 | 447 | else: |
459 | | - payload={'usedDeviceIds[]': device_model_ids} |
460 | | - print "Starting test run on project %s \"%s\" using device models ids %s " % (project['id'], project['name'], device_model_ids) |
| 448 | + print "Either device group or device models must be defined" |
| 449 | + sys.exit(1) |
461 | 450 |
|
462 | | - # Start run |
463 | | - path = "/users/%s/projects/%s/runs" % ( me['id'], project_id ) |
| 451 | + # add optional request params that the user might have specified |
464 | 452 | payload.update(additional_params) |
465 | | - reply = self.post(path=path, payload=payload) |
466 | | - print "Test run id: %s" % reply['id'] |
467 | | - print "Name: %s" % reply['displayName'] |
468 | | - return reply['id'] |
| 453 | + |
| 454 | + # actually start the test run |
| 455 | + me = self.get_me() |
| 456 | + path = "/users/%s/projects/%s/runs" % (me['id'], project_id) |
| 457 | + test_run = self.post(path=path, payload=payload) |
| 458 | + print "Test run id: %s" % test_run['id'] |
| 459 | + print "Name: %s" % test_run['displayName'] |
| 460 | + return test_run['id'] |
469 | 461 |
|
470 | 462 |
|
471 | 463 | """ Start a test run on a device group and wait for completion |
@@ -633,9 +625,15 @@ def download_test_screenshots(self, project_id, test_run_id): |
633 | 625 | ''' Earlier downloaded images are checked, and if needed re-downloaded. |
634 | 626 | ''' |
635 | 627 | try: |
| 628 | + from PIL import Image |
636 | 629 | im=Image.open(full_path) |
637 | 630 | im.verify() |
638 | 631 | logger.info("Screenshot %s already exists - skipping download" % full_path) |
| 632 | + except ImportError: |
| 633 | + if os.path.isfile(full_path): # fallback if Pillow fails to import |
| 634 | + logger.info("Screenshot %s already exists - skipping download" % full_path) |
| 635 | + else: |
| 636 | + raise # jump to next block |
639 | 637 | except: |
640 | 638 | url = "me/projects/%s/runs/%s/device-runs/%s/screenshots/%s" % (project_id, test_run['id'], device_run['id'], screenshot['id']) |
641 | 639 | prog = DownloadProgressBar() |
|
0 commit comments