testsuite.py 940 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
import os
import json

class TestSuite(object):
    def __init__(self):
        tsfile = os.environ.get('TESTSUITE_DATA_FILE')
        if tsfile == None:
            raise ValueError('TESTSUITE_DATA_FILE is not defined')
        with open(tsfile) as json_data:
            self.t = json.load(json_data)

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    def screenshot_filename(self, screenshots_dir):
        i = 1
        while True:
            screenshot_file = "%s/marionette_screenshot-%d.png" % (screenshots_dir, i)
            if not os.path.isfile(screenshot_file):
                return screenshot_file
            i += 1

    def screenshot(self, marionette, full=False):
        screenshots_dir = os.environ.get('MARIONETTE_SCREENSHOTS')
        screenshot_file = self.screenshot_filename(screenshots_dir)
        png_data = marionette.screenshot(format='binary', full=full)
        output = open(screenshot_file, 'w')
        output.write(png_data)
        output.close()