forked from cobrateam/splinter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
form_elements.py
130 lines (110 loc) · 6.19 KB
/
form_elements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- coding: utf-8 -*-
# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
class FormElementsTest(object):
def test_can_change_field_value(self):
"should provide a away to change field value"
self.browser.fill('query', 'new query')
value = self.browser.find_by_name('query').value
self.assertEqual('new query', value)
def test_should_provide_a_method_on_element_to_change_its_value(self):
self.browser.find_by_name('query').fill('new query')
value = self.browser.find_by_name('query').value
self.assertEqual('new query', value)
def test_submiting_a_form_and_verifying_page_content(self):
self.browser.fill('query', 'my name')
self.browser.find_by_name('send').click()
assert b'My name is: Master Splinter' in self.browser.html
def test_can_choose_a_radio_button(self):
"should provide a way to choose a radio button"
self.assertFalse(self.browser.find_by_id("gender-m").checked)
self.browser.choose("gender", "M")
self.assertTrue(self.browser.find_by_id("gender-m").checked)
def test_can_find_option_by_value(self):
"should provide a way to find select option by value"
self.assertEqual("Rio de Janeiro", self.browser.find_option_by_value("rj").text)
def test_can_get_value_attribute_for_a_option(self):
"should option have a value attribute"
self.assertEqual("rj", self.browser.find_option_by_value("rj")["value"])
def test_can_find_option_by_text(self):
"should provide a way to find select option by text"
self.assertEqual("rj", self.browser.find_option_by_text("Rio de Janeiro").value)
def test_can_select_a_option(self):
"should provide a way to select a option"
self.assertFalse(self.browser.find_option_by_value("rj").selected)
self.browser.select("uf", "rj")
self.assertTrue(self.browser.find_option_by_value("rj").selected)
def test_can_select_a_option_via_element(self):
"should provide a way to select a option via element"
self.assertFalse(self.browser.find_option_by_value("rj").selected)
self.browser.find_by_name("uf").select("rj")
self.assertTrue(self.browser.find_option_by_value("rj").selected)
def test_can_check_a_checkbox(self):
"should provide a way to check a radio checkbox"
self.assertFalse(self.browser.find_by_name("some-check").checked)
self.browser.check("some-check")
self.assertTrue(self.browser.find_by_name("some-check").checked)
def test_check_keeps_checked_if_called_multiple_times(self):
"should keep a checkbox checked if check() is called multiple times"
self.assertFalse(self.browser.find_by_name("some-check").checked)
self.browser.check("some-check")
self.browser.check("some-check")
self.assertTrue(self.browser.find_by_name("some-check").checked)
def test_can_uncheck_a_checkbox(self):
"should provide a way to uncheck a radio checkbox"
self.assertTrue(self.browser.find_by_name("checked-checkbox").checked)
self.browser.uncheck("checked-checkbox")
self.assertFalse(self.browser.find_by_name("checked-checkbox").checked)
def test_uncheck_should_keep_unchecked_if_called_multiple_times(self):
"should keep a checkbox unchecked if uncheck() is called multiple times"
self.assertTrue(self.browser.find_by_name("checked-checkbox").checked)
self.browser.uncheck("checked-checkbox")
self.browser.uncheck("checked-checkbox")
self.assertFalse(self.browser.find_by_name("checked-checkbox").checked)
def test_can_fill_text_field_in_form(self):
"should provide a away to change field value"
self.browser.fill_form({'query': 'new query'})
value = self.browser.find_by_name('query').value
self.assertEqual('new query', value)
def test_can_fill_password_field_in_form(self):
"should provide a way to change password value"
new_password = 'new password'
self.browser.fill_form({'password': new_password})
value = self.browser.find_by_name('password').value
self.assertEqual(new_password, value)
def test_can_fill_more_than_one_field_in_form(self):
"should provide a away to change field value"
self.browser.fill('query', 'my name')
self.assertFalse(self.browser.find_by_id("gender-m").checked)
self.assertFalse(self.browser.find_option_by_value("rj").selected)
self.assertFalse(self.browser.find_by_name("some-check").checked)
self.assertTrue(self.browser.find_by_name("checked-checkbox").checked)
self.browser.fill_form({
'query': 'another new query',
'description': 'Just another description value in the textarea',
'gender': 'M',
'uf': 'rj',
'some-check': True,
'checked-checkbox': False
})
query_value = self.browser.find_by_name('query').value
self.assertEqual('another new query', query_value)
desc_value = self.browser.find_by_name('description').value
self.assertEqual('Just another description value in the textarea', desc_value)
self.assertTrue(self.browser.find_by_id("gender-m").checked)
self.assertTrue(self.browser.find_option_by_value("rj").selected)
self.assertTrue(self.browser.find_by_name("some-check").checked)
self.assertFalse(self.browser.find_by_name("checked-checkbox").checked)
def test_can_fill_tel_text_field(self):
"should provide a way to change a tel field value"
new_telephone = '555-0042'
self.browser.fill_form({'telephone': new_telephone})
value = self.browser.find_by_name('telephone').value
self.assertEqual(new_telephone, value)
def test_can_fill_unknown_text_field(self):
"should provide a way to change a unknown text field type that isn't specifically defined"
new_search_keyword = 'foobar'
self.browser.fill_form({'search_keyword': new_search_keyword})
value = self.browser.find_by_name('search_keyword').value
self.assertEqual(new_search_keyword, value)