mirror of
https://dev.azure.com/Foster-X/CMP329%20CW2/_git/CMP329%20CW2
synced 2025-07-27 05:53:32 +00:00
Added new credential builder, moved credential builder to be it's own thing
This commit is contained in:
parent
df878e63d3
commit
9ec211197d
4 changed files with 77 additions and 6 deletions
2
src/csv/built/credentials_permissions.csv
Normal file
2
src/csv/built/credentials_permissions.csv
Normal file
|
@ -0,0 +1,2 @@
|
|||
author,testuser,QUBsucks&UUisBetter
|
||||
subscriber,subscriber,drewapicture(incrediblyfunnyjoke!)
|
|
|
@ -1,4 +1,51 @@
|
|||
package main;
|
||||
import java.io.*;
|
||||
|
||||
public class CsvCleaner {
|
||||
|
||||
public class CsvBuilder {
|
||||
|
||||
private static String inputFile = "src/csv/credentials.csv";
|
||||
public static void compileAll(String outputFile) {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(inputFile));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter("src/csv/built/"+outputFile+".csv"))) {
|
||||
|
||||
// Skip the first line
|
||||
reader.readLine();
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] parts = line.split(",", 2);
|
||||
if (parts.length > 1) {
|
||||
writer.write(parts[1]);
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("File processed successfully!");
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error processing file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
public static void compilePermissions(String outputFile) {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(inputFile));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter("src/csv/built/"+outputFile+".csv"))) {
|
||||
|
||||
// Skip the first line
|
||||
reader.readLine();
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
writer.write(line+"\n");
|
||||
}
|
||||
|
||||
System.out.println("File processed successfully!");
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error processing file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
CsvBuilder.compileAll("all_login_credentials");
|
||||
CsvBuilder.compilePermissions("credentials_permissions");
|
||||
}
|
||||
}
|
||||
|
|
21
src/main/DomainGrabber.java
Normal file
21
src/main/DomainGrabber.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package main;
|
||||
import org.junit.jupiter.params.shadow.com.univocity.parsers.csv.Csv;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class DomainGrabber {
|
||||
public static String getDomain() {
|
||||
try (InputStream inputStream = DomainGrabber.class.getResourceAsStream("/csv/credentials.csv");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
||||
return reader.readLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read domain from CSV", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package test;
|
||||
|
||||
import main.ConfigureDriver;
|
||||
import main.DomainGrabber;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.By;
|
||||
|
@ -9,16 +10,16 @@ import org.junit.jupiter.params.provider.CsvFileSource;
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestLogin {
|
||||
private static final String LOGIN_PAGE = "https://test.fusil.uk/wp-login.php";
|
||||
private static final String domain = DomainGrabber.getDomain();
|
||||
private static final String LOGIN_PAGE = "https://"+domain+"/wp-login.php";
|
||||
private static final String USERNAME_BOX_ID = "user_login";
|
||||
private static final String PASSWORD_BOX_ID = "user_pass";
|
||||
private static final String LOGIN_BUTTON_ID = "wp-submit";
|
||||
private static final String EXPECTED_URL = "https://test.fusil.uk/wp-admin/";
|
||||
|
||||
private static final String EXPECTED_URL = "https://"+domain+"/wp-admin/";
|
||||
@ParameterizedTest
|
||||
@CsvFileSource(resources = "/csv/all_login_credentials.csv", numLinesToSkip = 0)
|
||||
@CsvFileSource(resources = "/csv/built/all_login_credentials.csv", numLinesToSkip = 0)
|
||||
|
||||
void testLogin(String usernameText, String passwordText) {
|
||||
public void testLogin(String usernameText, String passwordText) {
|
||||
WebDriver driver = ConfigureDriver.configureDriver();
|
||||
driver.manage().window().maximize();
|
||||
driver.get(LOGIN_PAGE);
|
||||
|
|
Loading…
Add table
Reference in a new issue