Exemplo n.º 1
0
    def action_submit(self, target, param):
        """This should only be used with livepage, to simulate an onsubmit.

        It could be possible to make this work when not testing a livepage
        app, using a monstrosity similar to that used by action_click, below.
        """
        def passed(ctx):
            self.passed()

        if isinstance(target, xpath):
            yield target._asjs(js.targetForm)
        else:
            yield livepage.var(js.targetForm, contentDocument[target]), livepage.eol

        yield livepage.var(js.postTarget, js.targetForm.action), livepage.eol
        for key, value in param.items():
            yield livepage.assign(js.targetForm[key].value, value), livepage.eol
        yield livepage.var(
            js.inputListener,
            contentDocument.defaultView.listenForInputEvents(
                livepage.anonymous(
                    self.handle.transient(passed)))), livepage.eol

        yield js.sendSubmitEvent(
            js.targetForm,
            livepage.anonymous(
                contentDocument.defaultView.stopListening(js.inputListener)))
Exemplo n.º 2
0
    def action_click(self, target, param):
        """TODO: Either decide that this should only be used in the presence
        of a real, honest-to-god livepage app, or figure out some way to simplify
        this monstrosity.
        """
        def passed(ctx):
            self.passed()

        if isinstance(target, xpath):
            yield target._asjs(js.targetNode)
        else:
            yield livepage.var(js.targetNode, gid(target)), livepage.eol

        ## If the testee is using livepage, we don't want the test to pass
        ## until all input events (and the response javascript from these
        ## input events) have passed. To do this we use listenForInputEvents,
        ## passing a continuation function which will be called when all input
        ## event responses have been evaluated. We call stopListening
        ## immediately after sending the click event. This means we
        ## start listening for input events, simulate the click, then stop listening.
        ## If any input events were initiated during the click, our test only passes
        ## when all event responses have been processed.

        ## If we are not using livepage, listenForInputEvents will not be defined.
        ## Because it is hard to do javascript tests (if statement) from python,
        ## ifTesteeUsingLivePage has been defined in livetest-postscripts.
        testDidPass = self.handle.transient(passed)
        yield [
            js.ifTesteeUsingLivePage(
                ## Using livepage
                livepage.anonymous(
                    livepage.assign(
                        ## Save the listener in a variable so we can stop listening later
                        js.inputListener,
                        contentDocument.defaultView.listenForInputEvents(
                            ## When all observed events complete, continue running tests
                            livepage.anonymous(
                                testDidPass)))),
                ## Not using livepage; do nothing here.
                livepage.anonymous('')), livepage.eol,
            js.sendClickEvent(
                ## Click our node.
                js.targetNode,
                ## Immediately after clicking the node, run this stuff.
                livepage.anonymous(
                    js.ifTesteeUsingLivePage(
                        ## We're done clicking the node, and we're using livepage.
                        ## Stop listening for input events. This will fire the continuation
                        ## immediately if no input events were observed; otherwise it
                        ## will wait for all responses to be evaluated before firing the
                        ## continuation.
                        livepage.anonymous(contentDocument.defaultView.stopListening(js.inputListener)),
                        ## We're done clicking the node, and we are not using livepage.
                        ## Call testDidPass.
                        livepage.anonymous(testDidPass))))]
Exemplo n.º 3
0
    def action_post(self, target, param):
        def passed(ctx):
            self.passed()

        if isinstance(target, xpath):
            yield target._asjs(js.targetForm)
        else:
            yield livepage.var(js.targetForm, contentDocument[target]), livepage.eol

        yield livepage.var(js.postTarget, js.targetForm.action), livepage.eol
        for key, value in param.items():
            yield livepage.assign(js.targetForm[key].value, value), livepage.eol
        yield js.addLoadObserver(
            livepage.anonymous(
                self.handle.transient(passed))), livepage.eol
        yield js.sendSubmitEvent(js.targetForm, livepage.anonymous(js))
Exemplo n.º 4
0
    def action_post(self, target, param):
        def passed(ctx):
            self.passed()

        if isinstance(target, xpath):
            yield target._asjs(js.targetForm)
        else:
            yield livepage.var(js.targetForm, contentDocument[target]), livepage.eol

        yield livepage.var(js.postTarget, js.targetForm.action), livepage.eol
        for key, value in param.items():
            yield livepage.assign(js.targetForm[key].value, value), livepage.eol
        yield js.addLoadObserver(
            livepage.anonymous(
                self.handle.transient(passed))), livepage.eol
        yield js.sendSubmitEvent(js.targetForm, livepage.anonymous(js))