def test_click(): page = TestAgent(TestApp()).get('/page1') assert_equal( page.one("//a[1]").click().request.path, '/page1' ) assert_equal( page.one("//a[2]").click().request.path, '/page2' ) assert_equal( len(page.all("//a")), 3 ) assert_raises( testino.MultipleMatchesError, page.one, "//a" ) assert_equal( page.click('//a[1]').request.path, page.one('//a[1]').click().request.path ) assert_equal( page.click(text=u'page 1').request.path, page.one('//a[text()="page 1"]').click().request.path ) assert_equal( page.click(href=u'page1').request.path, page.one('//a[@href="page1"]').click().request.path ) assert_equal( page.click(text=u'page 1', href=u'page1').request.path, page.one('//a[text()="page 1" and @href="page1"]').click().request.path )
def test_form_radio(): app = FormApp(""" <input name="a" value="1" type="radio"/> <input name="a" value="2" type="radio"/> <input name="b" value="3" type="radio"/> <input name="b" value="4" type="radio"/> """) r = TestAgent(app).get('/') r.all('//*[@name="a"]')[0].checked = True r.all('//*[@name="b"]')[0].checked = True assert_equal(r.one('//form').submit().body, 'a:<1>; b:<3>') r = TestAgent(app).get('/') r.one('//*[@name="a"][1]').checked = True r.one('//*[@name="a"][2]').checked = True assert_equal(r.one('//form').submit().body, 'a:<2>')
def test_tables(): header_values = ["foo", "bar", "baz"] table_text = html.div( html.table( html.thead( html.tr( *[html.th(html.span(i+" ")) for i in header_values])), html.tbody( html.tr( *[html.td(i) for i in [1, 2, 3]]), html.tr( *[html.td(i) for i in [4, 5, 6]]))), html.table( html.thead( html.tr( *[html.th(html.span(i+" ")) for i in header_values])), html.tbody( html.tr( *[html.td(i) for i in [1, 2, 3]]), html.tr( *[html.td(i) for i in [4, 5, 6]])))) agent = TestAgent(wz.Response([table_text])).get(u'/') table = agent.all(u"//table")[0] rows = [row.to_dict() for row in table.rows()] headers = table.headers() assert len(headers) == 3 assert headers == header_values assert len(rows) == 2 for i, row in enumerate(rows): for j, header in enumerate(header_values): index = (i * 3) + (j + 1) assert row[header] == str(index) assert row[header] == type(row[header])(index) for j, cell in enumerate(row.values()): index = (i * 3) + (j + 1) assert cell == str(index) lists = [ ['1', '2', '3'], [4, 5, 6], ] for row, l in zip(table.rows(), lists): row.assert_is(l) assert_raises( AssertionError, table.rows()[0].assert_is, ['flim', 'flam', 'flooble'] )
def test_all(): page = TestAgent(TestApp()).get('/form-checkbox') for name in ['a', 'b']: elements = page.all("//input[@name=$name]", name=name) for element in elements: assert element.element.attrib['name'] == name page = TestAgent(TestApp()).get('/form-checkbox') form = page.form data = [ dict(name="a", type="checkbox"), dict(name="b", type="checkbox")] for datum in data: xpath = "input[@name=$name and @type=$type]" elements = form.all(xpath, **datum) for element in elements: for key, value in datum.items(): assert element.element.attrib[key] == value
def test_css_selectors_are_equivalent_to_xpath(): page = TestAgent(TestApp()).get('/page1') assert_equal( list(page.all('//a')), list(page.all('a', css=True)) )
def test_in_operator_works_on_elementwrapper(): agent = TestAgent(wz.Response(['<p>Tea tray tea tray tea tray tea tray</p>'])).get('/') assert 'tea tray' in agent.one('//p') assert 'tea tray' in agent.all('//p')[0] assert 'teat ray' not in agent.one('//p') assert 'teat ray' not in agent.all('//p')[0]
def test_form_attribute_returns_parent_form(): form_page = TestAgent(TestApp()).get('/form-text') assert_equal(form_page.all('//input[@name="a"]')[0].form, form_page.one('//form'))