mirror of
https://dev.azure.com/Foster-X/CMP329%20CW2/_git/CMP329%20CW2
synced 2025-07-27 05:53:32 +00:00
Added paramaterised testing, standardised filename
This commit is contained in:
parent
6b20d593e5
commit
df611ef206
2 changed files with 39 additions and 51 deletions
39
src/test/TestLogin.java
Normal file
39
src/test/TestLogin.java
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue