Skip to content

Commit f19d26f

Browse files
committed
Added space support for buttons
1 parent 5a7c5ee commit f19d26f

File tree

1 file changed

+44
-31
lines changed

1 file changed

+44
-31
lines changed

features/steps/web_steps.py

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,109 +30,121 @@
3030
from selenium.webdriver.support.ui import Select, WebDriverWait
3131
from selenium.webdriver.support import expected_conditions
3232

33-
ID_PREFIX = 'pet_'
33+
ID_PREFIX = "pet_"
3434

3535

3636
@when('I visit the "Home Page"')
3737
def step_impl(context):
38-
""" Make a call to the base URL """
38+
"""Make a call to the base URL"""
3939
context.driver.get(context.base_url)
4040
# Uncomment next line to take a screenshot of the web page
4141
# context.driver.save_screenshot('home_page.png')
4242

43+
4344
@then('I should see "{message}" in the title')
4445
def step_impl(context, message):
45-
""" Check the document title for a message """
46-
assert(message in context.driver.title)
46+
"""Check the document title for a message"""
47+
assert message in context.driver.title
48+
4749

4850
@then('I should not see "{text_string}"')
4951
def step_impl(context, text_string):
50-
element = context.driver.find_element(By.TAG_NAME, 'body')
51-
assert(text_string not in element.text)
52+
element = context.driver.find_element(By.TAG_NAME, "body")
53+
assert text_string not in element.text
54+
5255

5356
@when('I set the "{element_name}" to "{text_string}"')
5457
def step_impl(context, element_name, text_string):
55-
element_id = ID_PREFIX + element_name.lower().replace(' ', '_')
58+
element_id = ID_PREFIX + element_name.lower().replace(" ", "_")
5659
element = context.driver.find_element(By.ID, element_id)
5760
element.clear()
5861
element.send_keys(text_string)
5962

63+
6064
@when('I select "{text}" in the "{element_name}" dropdown')
6165
def step_impl(context, text, element_name):
62-
element_id = ID_PREFIX + element_name.lower().replace(' ', '_')
66+
element_id = ID_PREFIX + element_name.lower().replace(" ", "_")
6367
element = Select(context.driver.find_element(By.ID, element_id))
6468
element.select_by_visible_text(text)
6569

70+
6671
@then('I should see "{text}" in the "{element_name}" dropdown')
6772
def step_impl(context, text, element_name):
68-
element_id = ID_PREFIX + element_name.lower().replace(' ', '_')
73+
element_id = ID_PREFIX + element_name.lower().replace(" ", "_")
6974
element = Select(context.driver.find_element(By.ID, element_id))
70-
assert(element.first_selected_option.text == text)
75+
assert element.first_selected_option.text == text
76+
7177

7278
@then('the "{element_name}" field should be empty')
7379
def step_impl(context, element_name):
74-
element_id = ID_PREFIX + element_name.lower().replace(' ', '_')
80+
element_id = ID_PREFIX + element_name.lower().replace(" ", "_")
7581
element = context.driver.find_element(By.ID, element_id)
76-
assert(element.get_attribute('value') == u'')
82+
assert element.get_attribute("value") == ""
83+
7784

7885
##################################################################
7986
# These two function simulate copy and paste
8087
##################################################################
8188
@when('I copy the "{element_name}" field')
8289
def step_impl(context, element_name):
83-
element_id = ID_PREFIX + element_name.lower().replace(' ', '_')
90+
element_id = ID_PREFIX + element_name.lower().replace(" ", "_")
8491
element = WebDriverWait(context.driver, context.wait_seconds).until(
8592
expected_conditions.presence_of_element_located((By.ID, element_id))
8693
)
87-
context.clipboard = element.get_attribute('value')
88-
logging.info('Clipboard contains: %s', context.clipboard)
94+
context.clipboard = element.get_attribute("value")
95+
logging.info("Clipboard contains: %s", context.clipboard)
96+
8997

9098
@when('I paste the "{element_name}" field')
9199
def step_impl(context, element_name):
92-
element_id = ID_PREFIX + element_name.lower().replace(' ', '_')
100+
element_id = ID_PREFIX + element_name.lower().replace(" ", "_")
93101
element = WebDriverWait(context.driver, context.wait_seconds).until(
94102
expected_conditions.presence_of_element_located((By.ID, element_id))
95103
)
96104
element.clear()
97105
element.send_keys(context.clipboard)
98106

107+
99108
##################################################################
100109
# This code works because of the following naming convention:
101110
# The buttons have an id in the html hat is the button text
102-
# in lowercase followed by '-btn' so the Clean button has an id of
111+
# in lowercase followed by '-btn' so the Clear button has an id of
103112
# id='clear-btn'. That allows us to lowercase the name and add '-btn'
104113
# to get the element id of any button
105114
##################################################################
106115

116+
107117
@when('I press the "{button}" button')
108118
def step_impl(context, button):
109-
button_id = button.lower() + '-btn'
119+
button_id = button.lower().replace(" ", "_") + "-btn"
110120
context.driver.find_element(By.ID, button_id).click()
111121

122+
112123
@then('I should see "{name}" in the results')
113124
def step_impl(context, name):
114125
found = WebDriverWait(context.driver, context.wait_seconds).until(
115126
expected_conditions.text_to_be_present_in_element(
116-
(By.ID, 'search_results'),
117-
name
127+
(By.ID, "search_results"), name
118128
)
119129
)
120-
assert(found)
130+
assert found
131+
121132

122133
@then('I should not see "{name}" in the results')
123134
def step_impl(context, name):
124-
element = context.driver.find_element(By.ID, 'search_results')
125-
assert(name not in element.text)
135+
element = context.driver.find_element(By.ID, "search_results")
136+
assert name not in element.text
137+
126138

127139
@then('I should see the message "{message}"')
128140
def step_impl(context, message):
129141
found = WebDriverWait(context.driver, context.wait_seconds).until(
130142
expected_conditions.text_to_be_present_in_element(
131-
(By.ID, 'flash_message'),
132-
message
143+
(By.ID, "flash_message"), message
133144
)
134145
)
135-
assert(found)
146+
assert found
147+
136148

137149
##################################################################
138150
# This code works because of the following naming convention:
@@ -141,20 +153,21 @@ def step_impl(context, message):
141153
# We can then lowercase the name and prefix with pet_ to get the id
142154
##################################################################
143155

156+
144157
@then('I should see "{text_string}" in the "{element_name}" field')
145158
def step_impl(context, text_string, element_name):
146-
element_id = ID_PREFIX + element_name.lower().replace(' ', '_')
159+
element_id = ID_PREFIX + element_name.lower().replace(" ", "_")
147160
found = WebDriverWait(context.driver, context.wait_seconds).until(
148161
expected_conditions.text_to_be_present_in_element_value(
149-
(By.ID, element_id),
150-
text_string
162+
(By.ID, element_id), text_string
151163
)
152164
)
153-
assert(found)
165+
assert found
166+
154167

155168
@when('I change "{element_name}" to "{text_string}"')
156169
def step_impl(context, element_name, text_string):
157-
element_id = ID_PREFIX + element_name.lower().replace(' ', '_')
170+
element_id = ID_PREFIX + element_name.lower().replace(" ", "_")
158171
element = WebDriverWait(context.driver, context.wait_seconds).until(
159172
expected_conditions.presence_of_element_located((By.ID, element_id))
160173
)

0 commit comments

Comments
 (0)