Beispiel #1
0
 def __init__(self, server=None):
     #
     # If a server isn't specified,
     # spawn a new one.
     #
     if server is None:
         server = ZombieProxyServer()
     self.client = ZombieProxyClient(server.socket)
Beispiel #2
0
 def __init__(self, server=None):
     #
     # If a proxy server isn't specified, spawn one automatically.
     #
     if server is None:
         server = ZombieProxyServer()
     self.client = ZombieProxyClient(server.socket)
Beispiel #3
0
 def __init__(self, server=None):
     #
     # If a server isn't specified,
     # spawn a new one.
     #
     if server is None:
         server = ZombieProxyServer()
     self.client = ZombieProxyClient(server.socket)
Beispiel #4
0
 def setUp(self):
     super(TestServerCommunication, self).setUp()
     self.server = ZombieProxyServer()
     self.client = ZombieProxyClient()
Beispiel #5
0
class TestServerCommunication(TestCase):
    
    def setUp(self):
        super(TestServerCommunication, self).setUp()
        self.server = ZombieProxyServer()
        self.client = ZombieProxyClient()

    def tearDown(self):
        super(TestServerCommunication, self).tearDown()
        fudge.clear_expectations()
        self.server.kill()

    def test_encode(self):
        foo = {
            'foo': 'bar'
        }
        self.client.__encode__(foo) == dumps(foo)

        self.client.__encode__(FakeNode()) == 'ENCODED'

    def test_decode(self):
        foo = dumps({
            'foo': 'bar'
        })
        self.client.__decode__(foo) == loads(foo)

    def test_simple_send(self):
        self.client.send(
            "stream.end()"
        )

    def test_simple_json(self):
        obj = {
            'foo'   : 'bar',
            'test'  : 500
        }
        assert self.client.json(obj) == obj

    @fudge.with_fakes
    def test_simple_wait(self):

        js = """
        browser.visit("http://example.com", function(err, browser){
            if(err)
                stream.end(JSON.stringify(err.stack));
            else    
                stream.end();
        });
        """

        with fudge.patched_context(
            ZombieProxyClient,
            '__send__',
            (fudge.Fake('__send__', expect_call=True).
                with_args(js)
            )):

            self.client.wait('visit', 'http://example.com')

    @fudge.with_fakes
    def test_wait_without_arguments(self):

        js = """
        browser.wait(null, function(err, browser){
            if(err)
                stream.end(JSON.stringify(err.stack));
            else    
                stream.end();
        });
        """

        with fudge.patched_context(
            ZombieProxyClient,
            '__send__',
            (fudge.Fake('__send__', expect_call=True).
                with_args(js)
            )):

            self.client.wait('wait')
Beispiel #6
0
class Browser(BaseNode):

    def __init__(self, server=None):
        #
        # If a server isn't specified,
        # spawn a new one.
        #
        if server is None:
            server = ZombieProxyServer()
        self.client = ZombieProxyClient(server.socket)

    #
    # Document Content
    #
    @property
    def html(self):
        """
        Returns the HTML content of the current document.
        """
        return self.client.json('browser.html()')

    def css(self, selector, context=None):
        """
        Evaluate a CSS selector against the document (or an option context
        DOMNode) and return a list of DOMNode objects.
        """
        return self.__query__(selector, context)

    #
    # Navigation
    #
    @property
    def location(self):
        return self.client.json('browser.location')

    @location.setter
    def location(self, url):
        self.visit(url)

    @property
    def statusCode(self):
        return self.client.json('browser.statusCode')

    @property
    def redirected(self):
        return self.client.json('browser.redirected')
    
    @verb
    def visit(self, url):
        """
        Load the document from the specified URL.
        """
        self.client.wait('visit', url) 

    #
    # Forms
    #
    @verb
    def fill(self, field, value):
        self.__fill__(field, value)

    @verb
    def pressButton(self, selector):
        self.client.wait('pressButton', selector)
Beispiel #7
0
class Browser(BaseNode):
    def __init__(self, server=None):
        #
        # If a server isn't specified,
        # spawn a new one.
        #
        if server is None:
            server = ZombieProxyServer()
        self.client = ZombieProxyClient(server.socket)

    #
    # Document Content
    #
    @property
    def html(self):
        """
        Returns the HTML content of the current document.
        """
        return self.client.json('browser.html()')

    def css(self, selector, context=None):
        """
        Evaluate a CSS selector against the document (or an option context
        DOMNode) and return a list of DOMNode objects.
        """
        return self.__query__(selector, context)

    #
    # Navigation
    #
    @property
    def location(self):
        return self.client.json('browser.location')

    @location.setter
    def location(self, url):
        self.visit(url)

    @property
    def statusCode(self):
        return self.client.json('browser.statusCode')

    @property
    def redirected(self):
        return self.client.json('browser.redirected')

    @verb
    def visit(self, url):
        """
        Load the document from the specified URL.
        """
        self.client.wait('visit', url)

    #
    # Forms
    #
    @verb
    def fill(self, field, value):
        self.__fill__(field, value)

    @verb
    def pressButton(self, selector):
        self.client.wait('pressButton', selector)
Beispiel #8
0
class Browser(BaseNode):
    """
    A Browser object, analogous to zombie.Browser.
    """

    def __init__(self, server=None):
        #
        # If a proxy server isn't specified, spawn one automatically.
        #
        if server is None:
            server = ZombieProxyServer()
        self.client = ZombieProxyClient(server.socket)

    #
    # Document Content
    #
    @property
    def html(self):
        """
        Returns the HTML content of the current document.
        """
        return self.client.json('browser.html()')

    def css(self, selector, context=None):
        """
        Evaluate a CSS selector against the document (or an option context
        DOMNode) and return a list of DOMNode objects.
        """
        return self._query(selector, context)

    def text(self, value):
        return self.client.json('browser.text("%s")' % value)

    #
    # Navigation
    #
    def click_link(self, selector):
        self.client.wait('clickLink', selector)

    @property
    def location(self):
        return self.client.json('browser.location.toString()')

    @location.setter
    def location(self, url):
        self.visit(url)

    @verb
    def visit(self, url):
        """
        A shortcut to load the document from the specified URL.
        """
        self.client.wait('visit', url)

    @verb
    def back(self):
        self.client.wait('back')

    #
    # Forms
    #
    @verb
    def fill(self, field, value):
        """
        Fill a specified form field in the current document.
        """
        self._fill(field, value)

    @verb
    def press_button(self, selector):
        """
        Press a specific button (by innerText or CSS selector in the current
        document.
        """
        self.client.wait('pressButton', selector)
Beispiel #9
0
 def setUp(self):
     super(TestServerCommunication, self).setUp()
     self.server = ZombieProxyServer()
     self.client = ZombieProxyClient()
Beispiel #10
0
class TestServerCommunication(TestCase):
    def setUp(self):
        super(TestServerCommunication, self).setUp()
        self.server = ZombieProxyServer()
        self.client = ZombieProxyClient()

    def tearDown(self):
        super(TestServerCommunication, self).tearDown()
        fudge.clear_expectations()
        self.server.kill()

    def test_encode(self):
        foo = {'foo': 'bar'}
        self.client.__encode__(foo) == dumps(foo)

        self.client.__encode__(FakeNode()) == 'ENCODED'

    def test_decode(self):
        foo = dumps({'foo': 'bar'})
        self.client.__decode__(foo) == loads(foo)

    def test_simple_send(self):
        self.client.send("stream.end()")

    def test_simple_json(self):
        obj = {'foo': 'bar', 'test': 500}
        assert self.client.json(obj) == obj

    @fudge.with_fakes
    def test_simple_wait(self):

        js = """
        browser.visit("http://example.com", function(err, browser){
            if(err)
                stream.end(JSON.stringify(err.stack));
            else    
                stream.end();
        });
        """

        with fudge.patched_context(
                ZombieProxyClient, '__send__',
            (fudge.Fake('__send__', expect_call=True).with_args(js))):

            self.client.wait('visit', 'http://example.com')

    @fudge.with_fakes
    def test_wait_without_arguments(self):

        js = """
        browser.wait(null, function(err, browser){
            if(err)
                stream.end(JSON.stringify(err.stack));
            else    
                stream.end();
        });
        """

        with fudge.patched_context(
                ZombieProxyClient, '__send__',
            (fudge.Fake('__send__', expect_call=True).with_args(js))):

            self.client.wait('wait')