Ejemplo n.º 1
0
class Action(db.Document, Executable):

    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    name = db.StringField(required=True)
    start_state = db.ReferenceField("State", required=True)
    end_state = db.ReferenceField("State", required=True)
    steps = db.ListField(db.EmbeddedDocumentField(Command), required=False)
    execution_results = []

    def execute(self, driver, config):
        logging.debug("Executing Action %s" % self.name)
        # if not self.start_state.is_state_present(driver):
        #     result =Result(step_results=self.execution_results,passed=False,message="State %s not present" % self.start_state)
        #     result.failed_state = self.start_state
        #     result.actual_state = self.start_state.get_current_state(driver)
        #     result.actual_state.save()
        #     result.html = driver.html
        #     result.screenshot = driver.get_screenshot_as_base64()
        #     return result
        result = Executable.execute(self, driver, config)
        if not result.passed:
            result.failed_state = self.start_state
            result.actual_state = self.start_state.get_current_state(driver)
            result.actual_state.save()
            result.html = driver.html
            result.screenshot = driver.get_screenshot_as_base64()
        return result
Ejemplo n.º 2
0
class Result(db.EmbeddedDocument):
    total_indents = 0

    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    passed = db.BooleanField(required=True)
    message = db.StringField(required=True)
    exception = db.StringField(max_length=255, required=False)
    step_results = db.ListField(db.EmbeddedDocumentField('self'))
    failed_state = db.ReferenceField('State', required=False)
    actual_state = db.ReferenceField('State', required=False)
    html = db.StringField(required=False)
    screenshot = db.StringField(required=False)

    def __str__(self):
        Result.total_indents += 1
        message = "Executable Passed=%s %s \r\n" % (self.passed, self.message)
        for result in self.step_results:
            for indent in range(0, Result.total_indents):
                message += " "
            message += str(result)
        Result.total_indents -= 1
        return message

    def __repr__(self):
        return "Result(%s,%s)" % (self.passed, self.message)
Ejemplo n.º 3
0
class Post(db.Document):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    title = db.StringField(max_length=255, required=True)
    body = db.StringField(required=True)
    comments = db.ListField(db.EmbeddedDocumentField('Comment'))

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at'],
        'ordering': ['-created_at']
    }
Ejemplo n.º 4
0
class ElementState(db.Document):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    html = db.StringField(required=False)
    locators = db.ListField(db.EmbeddedDocumentField(Locator))
    screenshot = db.StringField(required=False)
    location = db.EmbeddedDocumentField(Location, required=False)
    type = db.StringField(required=False)

    def __unicode__(self):
        return self.locators

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at'],
        'ordering': ['-created_at']
    }

    def __str__(self):
        repr = "ElementState: "
        for locator in self.locators:
            repr += "{}, ".format(str(locator))
        return repr

    def __eq__(self, other):
        if other is None:
            return False
        for locator in self.locators:
            if locator in other.locators:
                return True
        return False

    def __ne__(self, other):
        return not self.__eq__(other)

    def set_location(self, element):
        self.location = Location(x=element.location['x'],
                                 y=element.location['y'],
                                 width=element.size['width'],
                                 height=element.size['height'])
Ejemplo n.º 5
0
class SuiteConfig(db.Document):
    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    start_after = db.DateTimeField(default=datetime.datetime.now,
                                   required=True)
    configs = db.ListField(db.EmbeddedDocumentField(RunConfig, required=True))

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at'],
        'ordering': ['-created_at']
    }

    @staticmethod
    def default():
        suite = SuiteConfig(configs=[RunConfig(browser="Firefox")])
        suite.save()
        return suite
Ejemplo n.º 6
0
class SuiteRun(db.Document, Executable):

    created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
    name = db.StringField(max_length=255, required=False)
    suite = db.ReferenceField(Suite, required=True)
    config = db.ReferenceField(SuiteConfig, required=True)
    start_after = db.DateTimeField(default=datetime.datetime.now, required=True)
    started_time = db.DateTimeField(default=datetime.datetime.now, required=True)
    ended_time = db.DateTimeField(default=datetime.datetime.now, required=True)
    status = db.StringField(max_length=25,required=True, choices=Status.ALL_STATUS)
    message = db.StringField(max_length=255,required=True)
    user = db.StringField(max_length=255, required=True)
    suite_results = db.ListField(db.EmbeddedDocumentField(Result), required=False)

    meta = {
        'allow_inheritance': True,
        'indexes': ['-created_at'],
        'ordering': ['-created_at']
    }

    def execute(self, driver):
        logging.debug("Executing Suite %s" % self.name)
        self.driver = driver
        suite_result = Result(passed=True,message="Passed",exception="Passed")

        for test in self.tests:
            test_result = test.execute(driver)
            suite_result.step_results.append(test_result)
            if not test_result.passed:
                suite_result.passed = False
                suite_result.message = str(self.__class__)
                suite_result.exception = test_result.exception
                suite_result.failed_state = test_result.failed_state
                suite_result.actual_state = test_result.actual_state
                suite_result.html = self.driver.page_source
                suite_result.screenshot = self.driver.get_screenshot_as_base64()

        self.suite_results.append(suite_result)
        self.cascade_save()
        return suite_result