diff --git a/src/test/TestLogin.java b/src/test/TestLogin.java new file mode 100644 index 0000000..9541716 --- /dev/null +++ b/src/test/TestLogin.java @@ -0,0 +1,39 @@ +package test; + +import main.ConfigureDriver; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.By; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestLogin { + private static final String LOGIN_PAGE = "https://test.fusil.uk/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/"; + + @ParameterizedTest + @CsvSource({ + "testuser, QUBsucks&UUisBetter", + "subscriber, drewapicture(incrediblyfunnyjoke!)" + }) + void testLogin(String usernameText, String passwordText) { + WebDriver driver = ConfigureDriver.configureDriver(); + driver.manage().window().maximize(); + driver.get(LOGIN_PAGE); + + 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)); + + username.sendKeys(usernameText); + password.sendKeys(passwordText); + login.click(); + + assertEquals(EXPECTED_URL, driver.getCurrentUrl()); + driver.quit(); + } +} \ No newline at end of file diff --git a/src/test/testlogin.java b/src/test/testlogin.java deleted file mode 100644 index 50d8288..0000000 --- a/src/test/testlogin.java +++ /dev/null @@ -1,51 +0,0 @@ -package test; - -import main.ConfigureDriver; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.By; -import org.junit.jupiter.api.Test; -import java.io.File; // Import the File class -import java.io.IOException; // Import the IOException class to handle errors -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.firefox.FirefoxOptions; - -import static org.junit.jupiter.api.Assertions.assertEquals; -public class testlogin { - String usernameText = "testuser"; - String passwordText = "QUBsucks&UUisBetter"; - String loginPage = "https://test.fusil.uk/wp-login.php"; - String usernameBoxID = "user_login"; - String passwordBoxID = "user_pass"; - String loginButtonID = "wp-submit"; - String expectedUrl = "https://test.fusil.uk/wp-admin/"; - @Test - void testLogin() { - WebDriver driver = ConfigureDriver.configureDriver(); - - //end chromedriver code - driver.manage().window().maximize(); - driver.get(loginPage); - WebElement username = driver.findElement(By.id(usernameBoxID)); - WebElement password = driver.findElement(By.id(passwordBoxID)); - WebElement login = driver.findElement(By.id(loginButtonID)); - username.sendKeys(usernameText); - password.sendKeys(passwordText); - login.click(); - assertEquals(expectedUrl, driver.getCurrentUrl()); - driver.quit(); - } -// public static void main(String[] args) { -// try { -// File myObj = new File("filename.txt"); -// if (myObj.createNewFile()) { -// System.out.println("File created: " + myObj.getName()); -// } else { -// System.out.println("File already exists."); -// } -// } catch (IOException e) { -// System.out.println("An error occurred."); -// e.printStackTrace(); -// } -// } -}