Skip to content

Commit ce0f52a

Browse files
committed
Revising - putting features onto their own page, e.g. Library
1 parent 9c1e22d commit ce0f52a

11 files changed

+51
-85
lines changed

src/main/java/com/coveros/training/DbServlet.java

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) {
3636
pl.cleanAndMigrateDatabase();
3737
request.setAttribute(RESULT, "cleaned and migrated");
3838
}
39+
request.setAttribute("return_page", "library.html");
3940

4041
ServletUtils.forwardToResult(request, response, logger);
4142
}

src/main/java/com/coveros/training/LibraryLendServlet.java

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
3535
final LibraryActionResults libraryActionResults = libraryUtils.lendBook(book, borrower, now);
3636

3737
request.setAttribute("result", libraryActionResults.toString());
38+
request.setAttribute("return_page", "library.html");
3839
ServletUtils.forwardToResult(request, response, logger);
3940
}
4041

src/main/java/com/coveros/training/LibraryRegisterBookServlet.java

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
2727
final LibraryActionResults libraryActionResults = libraryUtils.registerBook(book);
2828

2929
request.setAttribute("result", libraryActionResults.toString());
30+
request.setAttribute("return_page", "library.html");
3031
ServletUtils.forwardToResult(request, response, logger);
3132
}
3233

src/main/java/com/coveros/training/LibraryRegisterBorrowerServlet.java

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
2727
final LibraryActionResults libraryActionResults = libraryUtils.registerBorrower(borrower);
2828

2929
request.setAttribute("result", libraryActionResults);
30+
request.setAttribute("return_page", "library.html");
3031
ServletUtils.forwardToResult(request, response, logger);
3132
}
3233

src/main/java/com/coveros/training/LoginServlet.java

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
4040
final Boolean userRegistered = loginUtils.isUserRegistered(username, password);
4141
String responseText = userRegistered ? "access granted" : "access denied";
4242
request.setAttribute("result", responseText);
43+
request.setAttribute("return_page", "library.html");
4344
ServletUtils.forwardToResult(request, response, logger);
4445
}
4546

src/main/java/com/coveros/training/RegisterServlet.java

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
5050
final String prettyString = registrationResult.toPrettyString();
5151

5252
request.setAttribute("result", prettyString);
53+
request.setAttribute("return_page", "library.html");
5354
forwardToResult(request, response, logger);
5455
}
5556

src/main/webapp/index.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Demo Index</title>
6+
</head>
7+
<body>
8+
<ul>
9+
<li><a href="library.html">Library</a></li>
10+
</ul>
11+
</body>
12+
</html>

src/main/webapp/result.jsp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
<p><pre id="result">${result}</pre></p>
99
</body>
1010
<p>
11-
<a href="/demo/library">Return</a>
11+
<a href="${return_page}">Return</a>
1212
</p>
1313
</html>

ui_tests/features/authentication_ui.feature

+3-20
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,17 @@ Feature: A user may authenticate to the system through the UI
44
I want to be able to authenticate myself
55
So that I can use its features securely
66

7-
# This user story relates to behavior from a UI-centric point of view.
7+
# This user story relates to behavior from a UI-centric point of view.
8+
# Note that we want as few UI tests as possible. Logic should be tested lower down, this
9+
# is just to test the UI
810

911
Scenario: Registering a new user
1012
Given I am not registered
1113
When I register with a username of "Byron" and a password of "OAh8Wq8CajGZwURSXI8uSS"
1214
Then it indicates I am successfully registered
1315

14-
Scenario: Registering as an existing user (negative case)
15-
Given I am registered as "Byron" with a password of "OAh8Wq8CajGZwURSXI8uSS"
16-
When I try to register again
17-
Then it indicates I am already registered
18-
19-
Scenario: Registering with a poor password (negative case)
20-
Given I am not registered
21-
When I register with a username of "Byron" and a password of "short"
22-
Then it indicates that I used a poor password
23-
24-
Scenario: Registering with a poor password (negative case)
25-
Given I am not registered
26-
When I register with a username of "Byron" and a password of "simplybad"
27-
Then it indicates that I used a poor password
28-
2916
Scenario: Login with valid user
3017
Given I am registered as "Byron" with a password of "OAh8Wq8CajGZwURSXI8uSS"
3118
When I login with those credentials
3219
Then the system allows secure access
3320

34-
Scenario: Login with invalid user (negative case)
35-
Given There is no user with the username "Robert"
36-
When I login with that username and any password
37-
Then the system denies me access

ui_tests/features/environment.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ def __open_browser(context):
4141
# browser. It's eye-opening.
4242
#
4343
# for instance:
44-
# [1568045962.076][INFO]: [e18882b1f2abbda89f232f777f98f686] COMMAND TypeElement {
45-
# "id": "0.47079920350295135-1",
46-
# "sessionId": "e18882b1f2abbda89f232f777f98f686",
47-
# "text": "Byron",
48-
# "value": [ "B", "y", "r", "o", "n" ]
49-
# }
44+
# [1568045962.076][INFO]: [e18882b1f2abbda89f232f777f98f686] COMMAND TypeElement {
45+
# "id": "0.47079920350295135-1",
46+
# "sessionId": "e18882b1f2abbda89f232f777f98f686",
47+
# "text": "Byron",
48+
# "value": [ "B", "y", "r", "o", "n" ]
49+
# }
5050
#context.driver = webdriver.Chrome(service_args=["--verbose","--logepath=C:\\temp\\qc1.log"])
5151
context.driver = webdriver.Chrome()
5252
return context.driver

ui_tests/features/steps/authenticationStepDefs.py

+23-58
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
empty_database = ''
55
one_user_registered = 'alice password123'
6+
URL = 'http://localhost:8080/demo/library.html'
67

78

89
@given('I am not registered')
@@ -16,56 +17,12 @@ def step_impl(context, username_text, password_text):
1617
pass
1718

1819

19-
def __register_user(context, username_text, password_text):
20-
driver = context.driver
21-
driver.get("http://localhost:8080/demo")
22-
username = driver.find_element_by_id("register_username")
23-
username.clear()
24-
username.send_keys(username_text)
25-
password = driver.find_element_by_id("register_password")
26-
password.clear()
27-
password.send_keys(password_text)
28-
submit_button = driver.find_element_by_id("register_submit")
29-
submit_button.click()
30-
31-
32-
def __login_user(context, username_text, password_text):
33-
driver = context.driver
34-
driver.get("http://localhost:8080/demo")
35-
username = driver.find_element_by_id("login_username")
36-
username.clear()
37-
username.send_keys(username_text)
38-
password = driver.find_element_by_id("login_password")
39-
password.clear()
40-
password.send_keys(password_text)
41-
submit_button = driver.find_element_by_id("login_submit")
42-
submit_button.click()
43-
44-
4520
@then('it indicates I am successfully registered')
4621
def step_impl(context):
4722
result = context.driver.find_element_by_id('result')
4823
assert_that(result.text, contains_string('successfully registered: true'))
4924

5025

51-
@when('I try to register again')
52-
def step_impl(context):
53-
__register_user(context, context.username, context.password)
54-
pass
55-
56-
57-
@then('it indicates I am already registered')
58-
def step_impl(context):
59-
result = context.driver.find_element_by_id('result')
60-
assert_that(result.text, contains_string('successfully registered: false'))
61-
62-
63-
@then('it indicates that I used a poor password')
64-
def step_impl(context):
65-
result = context.driver.find_element_by_id('result')
66-
assert_that(result.text, is_not(contains_string('successfully registered: true')))
67-
68-
6926
@given('I am registered as "{username}" with a password of "{password}"')
7027
def step_impl(context, username, password):
7128
context.username = username
@@ -86,19 +43,27 @@ def step_impl(context):
8643
assert_that(result.text, contains_string('access granted'))
8744

8845

89-
@given('There is no user with the username "{username}"')
90-
def step_impl(context, username):
91-
context.username = username
92-
pass
93-
94-
95-
@when('I login with that username and any password')
96-
def step_impl(context):
97-
__login_user(context, context.username, "anypassword")
98-
pass
46+
def __register_user(context, username_text, password_text):
47+
driver = context.driver
48+
driver.get(URL)
49+
username = driver.find_element_by_id("register_username")
50+
username.clear()
51+
username.send_keys(username_text)
52+
password = driver.find_element_by_id("register_password")
53+
password.clear()
54+
password.send_keys(password_text)
55+
submit_button = driver.find_element_by_id("register_submit")
56+
submit_button.click()
9957

10058

101-
@then('the system denies me access')
102-
def step_impl(context):
103-
result = context.driver.find_element_by_id('result')
104-
assert_that(result.text, contains_string('access denied'))
59+
def __login_user(context, username_text, password_text):
60+
driver = context.driver
61+
driver.get(URL)
62+
username = driver.find_element_by_id("login_username")
63+
username.clear()
64+
username.send_keys(username_text)
65+
password = driver.find_element_by_id("login_password")
66+
password.clear()
67+
password.send_keys(password_text)
68+
submit_button = driver.find_element_by_id("login_submit")
69+
submit_button.click()

0 commit comments

Comments
 (0)