Exemplo n.º 1
0
    def _do_task(self, task):
        if not self.test_passed:
            return
        time.sleep(2)
        self.step_passed = True
        self.step_screenshot_passed = True
        self.screenshot_percent = -1.0
        try:
            self.commands[task.action](task.args)
        except:
            traceback.print_exc()
            self.step_passed = False
            if not task.is_optional:
                self.test_passed = False
        time.sleep(self.wait_time)
        if task.take_screenshot:
            self._save_and_diff(task.screenshot_name)
            if self.screenshot_percent > task.threshold:
                self.step_screenshot_passed = False
                if task.is_optional:
                    self.test_screenshot_passed = False

        RunDao.add_run_step(self.run_id, task.action, task.args,
                            self.step_passed, task.take_screenshot,
                            self.screenshot_percent,
                            self.step_screenshot_passed,
                            (task.screenshot_name or ''))
Exemplo n.º 2
0
 def run(self):
     '''
     runs the test
     '''
     self.task_list = list(self.task_list)
     while self.task_list:
         self._do_task(self.task_list.pop(0))
     self.video.resume()
     self.video.stop()
     self.browser.quit()
     now = time.strftime('%Y-%m-%d %H:%M:%S')
     RunDao.update_run(self.run_id, now, self.test_passed,
                       self.test_screenshot_passed)
Exemplo n.º 3
0
def run_api(suite_id: int, test_id: int, run_id: int) -> flask.wrappers.Response:
    '''gives information for single-run view in json format'''
    step_headers = [
        "action", "optional", "arguments", "passed", "screenshot", "screenshot_percentage",
        "screenshot_passed", "screenshot_name"
    ]
    steps = tuple([json_safe(i) for i in j] for j in RunDao.get_steps_for_run(run_id))
    data = {
        "steps": [dict(zip(step_headers, i)) for i in steps]
    }
    return jsonify(data)
Exemplo n.º 4
0
def test_api(suite_id: int, test_id: int) -> flask.wrappers.Response:
    '''gives information for runs and step view in json format'''
    steps = TestDao.get_steps_for_test(test_id)
    runs = RunDao.get_runs(test_id)
    step_headers = ["action", "optional", "arguments", "screenshot", "screenshot_name", "threshold"]
    run_headers = ["id", "start", "end", "passed", "screenshot_passed"]
    data = {
        "suite": suite_id,
        "test": test_id,
        "steps": [dict(zip(step_headers, [json_safe(i) for i in j])) for j in steps],
        "runs": [dict(zip(run_headers, [json_safe(i) for i in j])) for j in runs]
    }
    return jsonify(data)
Exemplo n.º 5
0
    def __init__(self, test_id, size, wait_time=5, browser=None):
        now = time.strftime('%Y-%m-%d %H:%M:%S')
        self.run_id = RunDao.add_run(test_id, now)
        self.wait_time = wait_time
        self.task_list = TestDao.get_steps_for_test(test_id)
        self.test_passed = True
        self.test_screenshot_passed = True
        if not browser or browser.lower() not in BROWSERS.keys():
            self.browser = webdriver.Firefox()
        else:
            self.browser = BROWSERS[browser.lower()]()

        self.last_clicked_on = None
        self.step_screenshot_passed = None
        self.step_passed = None
        self.screenshot_percent = None

        self.browser.set_window_position(0, 0)
        self.browser.set_window_size(*size)
        self.browser.maximize_window()
        self.commands = {
            'visit': self._visit,
            'click': self._click,
            'import': self._import,
            'input': self._insert,
            'sleep': self._sleep,
            'refresh': self._refresh,
            'execute': self._execute,
            'assert': self._assert,
        }
        self.directory = os.path.join(config.BASE, str(test_id),
                                      str(self.run_id))
        self.baseline = os.path.join(config.BASE, str(test_id),
                                     config.BASELINE_DIR)

        utils.makedir(self.directory)
        utils.makedir(self.baseline)
        self.video = Video(os.path.join(self.directory, "video"), 0, 0, *size)
Exemplo n.º 6
0
def view_run(suite_id: int, test_id: int, run_id: int) -> str:
    '''shows an individual run'''
    steps = RunDao.get_steps_for_run(run_id)
    return render_template('view/run.html', suite_id=suite_id,
                           test_id=test_id, run_id=run_id, steps=steps)
Exemplo n.º 7
0
def view_test(suite_id: int, test_id: int) -> str:
    '''for list of steps and runs'''
    steps = TestDao.get_steps_for_test(test_id)
    runs = RunDao.get_runs(test_id)
    return render_template('view/test.html', suite_id=suite_id,
                           test_id=test_id, steps=steps, runs=runs)