mirror of
https://dev.azure.com/Foster-X/CMP329%20CW2/_git/CMP329%20CW2
synced 2025-07-27 10:23:31 +00:00
login test now reports back as well
This commit is contained in:
parent
bdd2209f85
commit
9314fcea8f
3 changed files with 47 additions and 15 deletions
11
src/csv/reports/test-report-20250405-153243.csv
Normal file
11
src/csv/reports/test-report-20250405-153243.csv
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
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
|
|
3
src/csv/reports/test-report-20250405-153420.csv
Normal file
3
src/csv/reports/test-report-20250405-153420.csv
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Role,Username,Step,Result
|
||||||
|
N/A,testuser,Login,PASS
|
||||||
|
N/A,subscriber,Login,PASS
|
|
|
@ -1,39 +1,57 @@
|
||||||
package test;
|
package test;
|
||||||
|
|
||||||
import main.ConfigureDriver;
|
import main.ConfigureDriver;
|
||||||
|
import main.CsvBuilder;
|
||||||
import main.DomainGrabber;
|
import main.DomainGrabber;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.CsvFileSource;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.CsvFileSource;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class TestLogin {
|
public class TestLogin {
|
||||||
private static final String domain = DomainGrabber.getDomain();
|
private static final String domain = DomainGrabber.getDomain();
|
||||||
private static final String LOGIN_PAGE = "https://"+domain+"/wp-login.php";
|
private static final String LOGIN_PAGE = "https://" + domain + "/wp-login.php";
|
||||||
private static final String USERNAME_BOX_ID = "user_login";
|
private static final String USERNAME_BOX_ID = "user_login";
|
||||||
private static final String PASSWORD_BOX_ID = "user_pass";
|
private static final String PASSWORD_BOX_ID = "user_pass";
|
||||||
private static final String LOGIN_BUTTON_ID = "wp-submit";
|
private static final String LOGIN_BUTTON_ID = "wp-submit";
|
||||||
private static final String EXPECTED_URL = "https://"+domain+"/wp-admin/";
|
private static final String EXPECTED_URL = "https://" + domain + "/wp-admin/";
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void initReport() {
|
||||||
|
CsvBuilder.createTestReportFile(); // Reuses the same report for consistency
|
||||||
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@CsvFileSource(resources = "/csv/built/all_login_credentials.csv", numLinesToSkip = 0)
|
@CsvFileSource(resources = "/csv/built/all_login_credentials.csv", numLinesToSkip = 0)
|
||||||
|
|
||||||
public void testLogin(String usernameText, String passwordText) {
|
public void testLogin(String usernameText, String passwordText) {
|
||||||
WebDriver driver = ConfigureDriver.configureDriver();
|
WebDriver driver = ConfigureDriver.configureDriver();
|
||||||
driver.manage().window().maximize();
|
driver.manage().window().maximize();
|
||||||
driver.get(LOGIN_PAGE);
|
driver.get(LOGIN_PAGE);
|
||||||
|
|
||||||
|
try {
|
||||||
WebElement username = driver.findElement(By.id(USERNAME_BOX_ID));
|
WebElement username = driver.findElement(By.id(USERNAME_BOX_ID));
|
||||||
WebElement password = driver.findElement(By.id(PASSWORD_BOX_ID));
|
WebElement password = driver.findElement(By.id(PASSWORD_BOX_ID));
|
||||||
WebElement login = driver.findElement(By.id(LOGIN_BUTTON_ID));
|
WebElement login = driver.findElement(By.id(LOGIN_BUTTON_ID));
|
||||||
|
|
||||||
username.sendKeys(usernameText);
|
username.sendKeys(usernameText);
|
||||||
System.out.println("Testing "+usernameText);
|
System.out.println("Testing " + usernameText);
|
||||||
password.sendKeys(passwordText);
|
password.sendKeys(passwordText);
|
||||||
login.click();
|
login.click();
|
||||||
|
|
||||||
assertTrue(driver.getCurrentUrl().startsWith(EXPECTED_URL));
|
boolean loginSuccessful = driver.getCurrentUrl().startsWith(EXPECTED_URL);
|
||||||
|
CsvBuilder.appendTestResult("N/A", usernameText, "Login", loginSuccessful ? "PASS" : "FAIL");
|
||||||
|
assertTrue(loginSuccessful, "Login failed for user: " + usernameText);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
CsvBuilder.appendTestResult("N/A", usernameText, "Login", "FAIL - Exception: " + e.getMessage());
|
||||||
|
fail("Exception during login test: " + e.getMessage());
|
||||||
|
} finally {
|
||||||
driver.quit();
|
driver.quit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue