mirror of
https://dev.azure.com/Foster-X/CMP329%20CW2/_git/CMP329%20CW2
synced 2025-07-27 05:03:31 +00:00
Login failures are tested properly in testposter.java
This commit is contained in:
parent
30519bfee4
commit
76e47a0bc6
8 changed files with 136 additions and 56 deletions
10
src/csv/reports/test-report-20250405-172431.csv
Normal file
10
src/csv/reports/test-report-20250405-172431.csv
Normal file
|
@ -0,0 +1,10 @@
|
|||
Role,Username,Step,Result
|
||||
author,testuser,Login,PASS
|
||||
author,testuser,Post Access,PASS
|
||||
author,testuser,Post Creation,PASS
|
||||
author,testuser,Post Visible,PASS
|
||||
author,testuser,Post Deleted,PASS
|
||||
subscriber,subscriber,Login,FAIL
|
||||
subscriber,subscriber,Unexpected Error,FAIL - Login failed for user: subscriber ==> expected: <true> but was: <false>
|
||||
unauthorised,fakename,Login,FAIL
|
||||
unauthorised,fakename,Unexpected Error,FAIL - Login failed for user: fakename ==> expected: <true> but was: <false>
|
|
6
src/csv/reports/test-report-20250405-173219.csv
Normal file
6
src/csv/reports/test-report-20250405-173219.csv
Normal file
|
@ -0,0 +1,6 @@
|
|||
Role,Username,Step,Result
|
||||
author,testuser,Login,FAIL
|
||||
author,testuser,Unexpected Error,FAIL - Login failed for user: testuser ==> expected: <true> but was: <false>
|
||||
subscriber,subscriber,Login,FAIL
|
||||
subscriber,subscriber,Unexpected Error,FAIL - Login failed for user: subscriber ==> expected: <true> but was: <false>
|
||||
unauthorised,fakename,Login,FAIL
|
|
6
src/csv/reports/test-report-20250405-173318.csv
Normal file
6
src/csv/reports/test-report-20250405-173318.csv
Normal file
|
@ -0,0 +1,6 @@
|
|||
Role,Username,Step,Result
|
||||
author,testuser,Login,PASS
|
||||
author,testuser,Post Access,PASS
|
||||
author,testuser,Post Creation,PASS
|
||||
author,testuser,Post Visible,PASS
|
||||
author,testuser,Post Deleted,PASS
|
|
12
src/csv/reports/test-report-20250405-173426.csv
Normal file
12
src/csv/reports/test-report-20250405-173426.csv
Normal file
|
@ -0,0 +1,12 @@
|
|||
Role,Username,Step,Result
|
||||
author,testuser,Login,PASS
|
||||
author,testuser,Post Access,PASS
|
||||
author,testuser,Post Creation,PASS
|
||||
author,testuser,Post Visible,PASS
|
||||
author,testuser,Post Deleted,PASS
|
||||
subscriber,subscriber,Login,PASS
|
||||
subscriber,subscriber,Post Access,PASS
|
||||
subscriber,subscriber,Post Creation,SKIPPED (Not permitted)
|
||||
subscriber,subscriber,Post Visible,SKIPPED
|
||||
subscriber,subscriber,Post Deleted,SKIPPED
|
||||
unauthorised,fakename,Login,FAIL
|
|
9
src/csv/reports/test-report-20250405-174035.csv
Normal file
9
src/csv/reports/test-report-20250405-174035.csv
Normal file
|
@ -0,0 +1,9 @@
|
|||
Role,Username,Step,Result
|
||||
author,testuser,Login,FAIL
|
||||
author,testuser,Unexpected Error,FAIL - Login failed for user: testuser ==> expected: <true> but was: <false>
|
||||
subscriber,subscriber,Login,PASS
|
||||
subscriber,subscriber,Post Access,PASS
|
||||
subscriber,subscriber,Post Creation,SKIPPED (Not permitted)
|
||||
subscriber,subscriber,Post Visible,SKIPPED
|
||||
subscriber,subscriber,Post Deleted,SKIPPED
|
||||
unauthorised,fakename,Login,PASS
|
|
12
src/csv/reports/test-report-20250405-174245.csv
Normal file
12
src/csv/reports/test-report-20250405-174245.csv
Normal file
|
@ -0,0 +1,12 @@
|
|||
Role,Username,Step,Result
|
||||
author,testuser,Login,PASS (Logged in succesfully)
|
||||
author,testuser,Post Access,PASS
|
||||
author,testuser,Post Creation,PASS
|
||||
author,testuser,Post Visible,PASS
|
||||
author,testuser,Post Deleted,PASS
|
||||
subscriber,subscriber,Login,PASS (Logged in succesfully)
|
||||
subscriber,subscriber,Post Access,PASS
|
||||
subscriber,subscriber,Post Creation,SKIPPED (Not permitted)
|
||||
subscriber,subscriber,Post Visible,SKIPPED
|
||||
subscriber,subscriber,Post Deleted,SKIPPED
|
||||
unauthorised,fakename,Login,PASS (Login failed, as expected)
|
Can't render this file because it has a wrong number of fields in line 12.
|
12
src/csv/reports/test-report-20250405-174342.csv
Normal file
12
src/csv/reports/test-report-20250405-174342.csv
Normal file
|
@ -0,0 +1,12 @@
|
|||
Role,Username,Step,Result
|
||||
author,testuser,Login,PASS (Logged in succesfully)
|
||||
author,testuser,Post Access,PASS
|
||||
author,testuser,Post Creation,PASS
|
||||
author,testuser,Post Visible,PASS
|
||||
author,testuser,Post Deleted,PASS
|
||||
subscriber,subscriber,Login,PASS (Logged in succesfully)
|
||||
subscriber,subscriber,Post Access,PASS
|
||||
subscriber,subscriber,Post Creation,SKIPPED (Not permitted)
|
||||
subscriber,subscriber,Post Visible,SKIPPED
|
||||
subscriber,subscriber,Post Deleted,SKIPPED
|
||||
unauthorised,fakename,Login,PASS (Login failed, as expected)
|
Can't render this file because it has a wrong number of fields in line 12.
|
|
@ -43,7 +43,7 @@ public class TestPoster {
|
|||
|
||||
try {
|
||||
// Step 1: Login
|
||||
boolean loginaAllowed = (!role.equals("unauthorised"));
|
||||
boolean loginAllowed = (!role.equals("unauthorised"));
|
||||
WebElement username = driver.findElement(By.id(USERNAME_BOX_ID));
|
||||
WebElement password = driver.findElement(By.id(PASSWORD_BOX_ID));
|
||||
WebElement login = driver.findElement(By.id(LOGIN_BUTTON_ID));
|
||||
|
@ -53,67 +53,80 @@ public class TestPoster {
|
|||
login.click();
|
||||
|
||||
boolean loginSuccess = driver.getCurrentUrl().startsWith(LOGGEDIN_URL);
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Login", loginSuccess ? "PASS" : "FAIL");
|
||||
assertTrue(loginSuccess, "Login failed for user: " + usernameText);
|
||||
String LoginPassText;
|
||||
String LoginFailText;
|
||||
|
||||
if (loginAllowed) {
|
||||
LoginPassText = "PASS (Logged in succesfully)";
|
||||
LoginFailText = "FAIL (Login failed, it shouldn't have)";
|
||||
} else {
|
||||
LoginPassText = "FAIL (Should be unable to login)";
|
||||
LoginFailText = "PASS (Login failed, as expected)";
|
||||
}
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Login", loginSuccess ? LoginPassText : LoginFailText);
|
||||
if (loginAllowed) {
|
||||
assertTrue(loginSuccess, "Login failed for user: " + usernameText);
|
||||
} else {
|
||||
assertFalse(loginSuccess, "Login successfully failed for user: " + usernameText);
|
||||
}
|
||||
// Determine permission
|
||||
boolean canPost = role.equals("author");
|
||||
boolean postAccessible = true;
|
||||
if (loginAllowed) {
|
||||
// Step 2: Try accessing new post page
|
||||
try {
|
||||
WebElement postButton = driver.findElement(By.id(POST_BUTTON_NAV_ID));
|
||||
postButton.click();
|
||||
} catch (NoSuchElementException e) {
|
||||
postAccessible = false;
|
||||
}
|
||||
|
||||
// Step 2: Try accessing new post page
|
||||
try {
|
||||
WebElement postButton = driver.findElement(By.id(POST_BUTTON_NAV_ID));
|
||||
postButton.click();
|
||||
} catch (NoSuchElementException e) {
|
||||
postAccessible = false;
|
||||
if (canPost) {
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Access", postAccessible ? "PASS" : "FAIL");
|
||||
assertTrue(postAccessible, "User should be able to access post creation but can't");
|
||||
|
||||
// Step 3: Create post
|
||||
WebElement title = driver.findElement(By.id(POST_TITLE_ID));
|
||||
WebElement content = driver.findElement(By.id(POST_CONTENT_ID));
|
||||
WebElement textSwitch = driver.findElement(By.id(POST_EDITOR_SWITCH_ID));
|
||||
WebElement publishButton = driver.findElement(By.id(PUBLISH_BUTTON_ID));
|
||||
|
||||
textSwitch.click();
|
||||
title.sendKeys(POST_TITLE_TEXT);
|
||||
content.sendKeys(POST_CONTENT_TEXT);
|
||||
publishButton.click();
|
||||
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Creation", "PASS");
|
||||
|
||||
// Step 4: Verify post is visible
|
||||
String editURL = driver.getCurrentUrl();
|
||||
driver.get(POST_URL);
|
||||
String postedTitle = driver.getTitle();
|
||||
boolean postVisible = !postedTitle.startsWith("Page not found");
|
||||
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Visible", postVisible ? "PASS" : "FAIL");
|
||||
assertTrue(postVisible, "Post is not visible after publishing");
|
||||
|
||||
// Step 5: Delete post
|
||||
driver.get(editURL);
|
||||
WebElement deleteButton = driver.findElement(By.id(DELETE_BUTTON_ID));
|
||||
deleteButton.click();
|
||||
driver.get(POST_URL);
|
||||
postedTitle = driver.getTitle();
|
||||
boolean postDeleted = postedTitle.startsWith("Page not found");
|
||||
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Deleted", postDeleted ? "PASS" : "FAIL");
|
||||
assertTrue(postDeleted, "Post was not properly deleted");
|
||||
|
||||
} else {
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Access", postAccessible ? "FAIL (Should not access)" : "PASS");
|
||||
assertFalse(postAccessible, "User without permissions accessed post creation page");
|
||||
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Creation", "SKIPPED (Not permitted)");
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Visible", "SKIPPED");
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Deleted", "SKIPPED");
|
||||
}
|
||||
}
|
||||
|
||||
if (canPost) {
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Access", postAccessible ? "PASS" : "FAIL");
|
||||
assertTrue(postAccessible, "User should be able to access post creation but can't");
|
||||
|
||||
// Step 3: Create post
|
||||
WebElement title = driver.findElement(By.id(POST_TITLE_ID));
|
||||
WebElement content = driver.findElement(By.id(POST_CONTENT_ID));
|
||||
WebElement textSwitch = driver.findElement(By.id(POST_EDITOR_SWITCH_ID));
|
||||
WebElement publishButton = driver.findElement(By.id(PUBLISH_BUTTON_ID));
|
||||
|
||||
textSwitch.click();
|
||||
title.sendKeys(POST_TITLE_TEXT);
|
||||
content.sendKeys(POST_CONTENT_TEXT);
|
||||
publishButton.click();
|
||||
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Creation", "PASS");
|
||||
|
||||
// Step 4: Verify post is visible
|
||||
String editURL = driver.getCurrentUrl();
|
||||
driver.get(POST_URL);
|
||||
String postedTitle = driver.getTitle();
|
||||
boolean postVisible = !postedTitle.startsWith("Page not found");
|
||||
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Visible", postVisible ? "PASS" : "FAIL");
|
||||
assertTrue(postVisible, "Post is not visible after publishing");
|
||||
|
||||
// Step 5: Delete post
|
||||
driver.get(editURL);
|
||||
WebElement deleteButton = driver.findElement(By.id(DELETE_BUTTON_ID));
|
||||
deleteButton.click();
|
||||
driver.get(POST_URL);
|
||||
postedTitle = driver.getTitle();
|
||||
boolean postDeleted = postedTitle.startsWith("Page not found");
|
||||
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Deleted", postDeleted ? "PASS" : "FAIL");
|
||||
assertTrue(postDeleted, "Post was not properly deleted");
|
||||
|
||||
} else {
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Access", postAccessible ? "FAIL (Should not access)" : "PASS");
|
||||
assertFalse(postAccessible, "User without permissions accessed post creation page");
|
||||
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Creation", "SKIPPED (Not permitted)");
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Visible", "SKIPPED");
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Post Deleted", "SKIPPED");
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
CsvBuilder.appendTestResult(role, usernameText, "Unexpected Error", "FAIL - " + t.getMessage());
|
||||
fail("Unexpected exception: " + t.getMessage());
|
||||
|
|
Loading…
Add table
Reference in a new issue