コード例 #1
0
ファイル: test_browser.py プロジェクト: jbochi/python-zombie
    def setUp(self):
        super(TestBrowser, self).setUp()
        self.browser = Browser()

        # Build the path to the example.html file
        path = os.path.dirname(os.path.abspath(__file__))
        path = os.path.join(path, 'helpers', 'example.html')
        self.path = 'file://%s' % path
        self.html = open(path, 'r').read()
コード例 #2
0
ファイル: test_browser.py プロジェクト: jbochi/python-zombie
class TestBrowser(BrowserClientTest):

    def setUp(self):
        super(TestBrowser, self).setUp()
        self.browser = Browser()

        # Build the path to the example.html file
        path = os.path.dirname(os.path.abspath(__file__))
        path = os.path.join(path, 'helpers', 'example.html')
        self.path = 'file://%s' % path
        self.html = open(path, 'r').read()

    def test_html(self):
        assert '<p>This is an HTML document</p>' in self.browser.visit(
            self.path
        ).html

    def test_css(self):
        self.browser.visit(self.path)
        for tag in ['h1', 'p', 'form', 'input', 'button']:
            matches = self.browser.css(tag)
            assert len(matches)

    def test_by_id(self):
        matches = self.browser.visit(self.path).css('#submit')
        assert len(matches) == 1
        assert matches[0].tagName.lower() == 'button'

    def test_by_class_name(self):
        matches = self.browser.visit(self.path).css('.textfield')
        assert len(matches) == 1
        assert matches[0].tagName.lower() == 'input'

    def test_location_get(self):
        assert self.browser.visit(self.path).location == self.path

    def test_location_set(self):
        self.browser.location = self.path
        assert self.browser.visit(self.path).location == self.path

    def test_fill(self):
        self.browser.visit(self.path).fill('q', 'Zombie.js')
        assert self.browser.css('input')[0].value == 'Zombie.js'

    def test_press_button(self):
        self.browser.visit(self.path)
        assert self.browser.location.endswith(self.path)
        self.browser.press_button('Search')
        assert self.browser.location.endswith('submit')