Example #1
0
    def record(cls, d, remote_d, url, screen_size, path, diffcolor, sleepfactor, save_diff, mask):
        print 'Begin record'
        try:
            os.makedirs(path)
        except:
            pass
        test = Test(screen_size, mask)
        run = TestRun(test, path, url, d, TestRunModes.RECORD, diffcolor, save_diff)
        run.set_window_size(*screen_size)
        navigate(d, url)
        start_time = d.execute_script('return +new Date();')
        d.execute_script('''
(function() {
var events = [];
window.addEventListener('click', function (e) { events.push([+new Date(), 'click', [e.clientX, e.clientY]]); }, true);
window.addEventListener('scroll', function (e) { events.push([+new Date(), 'scroll', [window.scrollX, window.scrollY]]); }, true);
window.addEventListener('keydown', function (e) { events.push([+new Date(), 'keydown', [e.keyCode, e.shiftKey]]); }, true);
window._getHuxleyEvents = function() { return events; };
})();
''')
        steps = []
        while True:
            if len(raw_input("Press enter to take a screenshot, or type Q+enter if you're done\n")) > 0:
                break
            screenshot_step = ScreenshotTestStep(d.execute_script('return Date.now();') - start_time, run, len(steps))
            run.d.save_screenshot(screenshot_step.get_path(run))
            steps.append(screenshot_step)
            print len(steps), 'screenshots taken'

        # now capture the events
        try:
            events = d.execute_script('return window._getHuxleyEvents();')
        except:
            raise TestError(
                'Could not call window._getHuxleyEvents(). ' +
                'This usually means you navigated to a new page, which is currently unsupported.'
            )
        for (timestamp, type, params) in events:
            if type == 'click':
                steps.append(ClickTestStep(timestamp - start_time, params))
            elif type == 'keyup' or type == 'keydown':
                steps.append(KeyTestStep(timestamp - start_time, params))
            elif type == 'scroll':
                steps.append(ScrollTestStep(timestamp - start_time, params))

        steps.sort(key=operator.attrgetter('offset_time'))

        test.steps = steps

        print
        raw_input(
            'Up next, we\'ll re-run your actions to generate screenshots ' +
            'to ensure they are pixel-perfect when running automated. ' +
            'Press enter to start.'
        )
        print
        cls.rerecord(test, path, url, remote_d, sleepfactor, diffcolor, save_diff)

        return test
Example #2
0
    def record(cls, d, remote_d, url, screen_size, path, diffcolor, sleepfactor, save_diff):
        print 'Begin record'
        try:
            os.makedirs(path)
        except:
            pass
        test = Test(screen_size)
        run = TestRun(test, path, url, d, TestRunModes.RECORD, diffcolor, save_diff)
        d.set_window_size(*screen_size)
        navigate(d, url)
        start_time = d.execute_script('return Date.now();')
        cls.get_events(d)
        steps = []
        rt = RepeatedTimer(1, cls.get_events, d) # capture events every second

        while True:
            if len(raw_input("Press enter to take a screenshot, or type Q+enter if you're done\n")) > 0:
                break
            screenshot_step = ScreenshotTestStep(d.execute_script('return Date.now();') - start_time, run, len(steps))
            run.d.save_screenshot(screenshot_step.get_path(run))
            steps.append(screenshot_step)
            print len(steps), 'screenshots taken'

        # capture the remaining events
        rt.stop()
        cls.get_events(d)


        for (timestamp, type, params) in TestRun.events:
            if type == 'click':
                steps.append(ClickTestStep(timestamp - start_time, params))
            elif type == 'keyup':
                steps.append(KeyTestStep(timestamp - start_time, params))

        steps.sort(key=operator.attrgetter('offset_time'))

        test.steps = steps

        print
        raw_input(
            'Up next, we\'ll re-run your actions to generate screenshots ' +
            'to ensure they are pixel-perfect when running automated. ' +
            'Press enter to start.'
        )
        print
        cls.rerecord(test, path, url, remote_d, sleepfactor, diffcolor, save_diff)

        return test
Example #3
0
File: run.py Project: ssetem/huxley
    def record(cls, d, remote_d, url, screen_size, path, diffcolor, sleepfactor, save_diff, his_mode=False):
        print 'Begin record'
        if not os.path.exists(path):
            os.makedirs(path)

        test = Test(screen_size)
        run = TestRun(test, path, url, d, TestRunModes.RECORD, diffcolor, save_diff, his_mode)
        d.set_window_size(*screen_size)
        navigate(d, url)
        start_time = d.execute_script('return Date.now();')
        d.execute_script('''
(function() {
var events = [];
window.addEventListener('click', function (e) { events.push([Date.now(), 'click', [e.clientX, e.clientY]]); }, true);
window.addEventListener('mousedown', function (e) { events.push([Date.now(), 'mousedown', [e.clientX, e.clientY]]); }, true);
window.addEventListener('mouseup', function (e) { events.push([Date.now(), 'mouseup', [e.clientX, e.clientY]]); }, true);
window.addEventListener('mousemove', function (e) { events.push([Date.now(), 'mousemove', [e.clientX, e.clientY]]); }, true);
window.addEventListener('keyup', function (e) { events.push([Date.now(), 'keyup', String.fromCharCode(e.keyCode)]); }, true);
window._getHuxleyEvents = function() { return events; };
})();
''')
        steps = []
        mouse_action_stack = []
        drag_and_drop_sub_steps = []
        while True:
            if len(raw_input("Press enter to take a screenshot, or type Q+enter if you're done\n")) > 0:
                break
            screenshot_step = ScreenshotTestStep(d.execute_script('return Date.now();') - start_time, run, len(steps))
            if his_mode:
                screenshot_step.create_run_path(run)
                run.d.save_screenshot(screenshot_step.get_latest_path(run))
            else:
                run.d.save_screenshot(screenshot_step.get_path(run))

            steps.append(screenshot_step)
            print len(steps), 'screenshots taken'

        # now capture the events
        try:
            events = d.execute_script('return window._getHuxleyEvents();')
        except:
            raise TestError(
                'Could not call window._getHuxleyEvents(). ' +
                'This usually means you navigated to a new page, which is currently unsupported.'
            )
        for (timestamp, type, params) in events:
            if type == 'click':
                steps.append(ClickTestStep(timestamp - start_time, params))
            elif type == 'keyup':
                steps.append(KeyTestStep(timestamp - start_time, params))

            elif type == 'mousedown':
                steps.append(MouseDownTestStep(timestamp - start_time, params))
                del mouse_action_stack[:]
                mouse_action_stack.append({'action':'mousedown', 'offtime':(timestamp -start_time), 'position':params})
            elif type == 'mousemove':
                mouse_actions = [item['action'] for item in mouse_action_stack]
                if 'mousedown' in mouse_actions:
                    mouse_action_stack.append({'action':'mousemove', 'offtime':(timestamp -start_time), 'position':params})
            elif type == 'mouseup':
                mouse_actions = [item['action'] for item in mouse_action_stack]
                if 'mousedown' in mouse_actions:
                    mouse_down_index = mouse_actions.index('mousedown')
                    if (mouse_down_index<len(mouse_action_stack) - 1) and \
                            (mouse_action_stack[mouse_down_index]['position']<>params):
                        steps.append(DragAndDropTestStep(mouse_action_stack[mouse_down_index]['offtime'],
                                                     mouse_action_stack[mouse_down_index]['position'],
                                                     params))

                del mouse_action_stack[:]

        steps.sort(key=operator.attrgetter('offset_time'))

        test.steps = steps

        print
        raw_input(
            'Up next, we\'ll re-run your actions to generate screenshots ' +
            'to ensure they are pixel-perfect when running automated. ' +
            'Press enter to start.'
        )
        print
        cls.rerecord(test, path, url, remote_d, sleepfactor, diffcolor, save_diff, his_mode)

        return test
Example #4
0
File: run.py Project: ssetem/huxley
    def record(cls,
               d,
               remote_d,
               url,
               screen_size,
               path,
               diffcolor,
               sleepfactor,
               save_diff,
               his_mode=False):
        print 'Begin record'
        if not os.path.exists(path):
            os.makedirs(path)

        test = Test(screen_size)
        run = TestRun(test, path, url, d, TestRunModes.RECORD, diffcolor,
                      save_diff, his_mode)
        d.set_window_size(*screen_size)
        navigate(d, url)
        start_time = d.execute_script('return Date.now();')
        d.execute_script('''
(function() {
var events = [];
window.addEventListener('click', function (e) { events.push([Date.now(), 'click', [e.clientX, e.clientY]]); }, true);
window.addEventListener('mousedown', function (e) { events.push([Date.now(), 'mousedown', [e.clientX, e.clientY]]); }, true);
window.addEventListener('mouseup', function (e) { events.push([Date.now(), 'mouseup', [e.clientX, e.clientY]]); }, true);
window.addEventListener('mousemove', function (e) { events.push([Date.now(), 'mousemove', [e.clientX, e.clientY]]); }, true);
window.addEventListener('keyup', function (e) { events.push([Date.now(), 'keyup', String.fromCharCode(e.keyCode)]); }, true);
window._getHuxleyEvents = function() { return events; };
})();
''')
        steps = []
        mouse_action_stack = []
        drag_and_drop_sub_steps = []
        while True:
            if len(
                    raw_input(
                        "Press enter to take a screenshot, or type Q+enter if you're done\n"
                    )) > 0:
                break
            screenshot_step = ScreenshotTestStep(
                d.execute_script('return Date.now();') - start_time, run,
                len(steps))
            if his_mode:
                screenshot_step.create_run_path(run)
                run.d.save_screenshot(screenshot_step.get_latest_path(run))
            else:
                run.d.save_screenshot(screenshot_step.get_path(run))

            steps.append(screenshot_step)
            print len(steps), 'screenshots taken'

        # now capture the events
        try:
            events = d.execute_script('return window._getHuxleyEvents();')
        except:
            raise TestError(
                'Could not call window._getHuxleyEvents(). ' +
                'This usually means you navigated to a new page, which is currently unsupported.'
            )
        for (timestamp, type, params) in events:
            if type == 'click':
                steps.append(ClickTestStep(timestamp - start_time, params))
            elif type == 'keyup':
                steps.append(KeyTestStep(timestamp - start_time, params))

            elif type == 'mousedown':
                steps.append(MouseDownTestStep(timestamp - start_time, params))
                del mouse_action_stack[:]
                mouse_action_stack.append({
                    'action': 'mousedown',
                    'offtime': (timestamp - start_time),
                    'position': params
                })
            elif type == 'mousemove':
                mouse_actions = [item['action'] for item in mouse_action_stack]
                if 'mousedown' in mouse_actions:
                    mouse_action_stack.append({
                        'action':
                        'mousemove',
                        'offtime': (timestamp - start_time),
                        'position':
                        params
                    })
            elif type == 'mouseup':
                mouse_actions = [item['action'] for item in mouse_action_stack]
                if 'mousedown' in mouse_actions:
                    mouse_down_index = mouse_actions.index('mousedown')
                    if (mouse_down_index<len(mouse_action_stack) - 1) and \
                            (mouse_action_stack[mouse_down_index]['position']<>params):
                        steps.append(
                            DragAndDropTestStep(
                                mouse_action_stack[mouse_down_index]
                                ['offtime'],
                                mouse_action_stack[mouse_down_index]
                                ['position'], params))

                del mouse_action_stack[:]

        steps.sort(key=operator.attrgetter('offset_time'))

        test.steps = steps

        print
        raw_input(
            'Up next, we\'ll re-run your actions to generate screenshots ' +
            'to ensure they are pixel-perfect when running automated. ' +
            'Press enter to start.')
        print
        cls.rerecord(test, path, url, remote_d, sleepfactor, diffcolor,
                     save_diff, his_mode)

        return test