diff --git a/src/test/java/uk/ac/cf/spring/demo/user/controller/RegistrationAndLoginTest.java b/src/test/java/uk/ac/cf/spring/demo/user/controller/RegistrationAndLoginTest.java index dbe9ac87f4f09eaea44d1e6fb1dee96e75ac955a..f62ab78346002f004d3c7edeca5278042550a34b 100644 --- a/src/test/java/uk/ac/cf/spring/demo/user/controller/RegistrationAndLoginTest.java +++ b/src/test/java/uk/ac/cf/spring/demo/user/controller/RegistrationAndLoginTest.java @@ -1,72 +1,72 @@ -package uk.ac.cf.spring.demo.user.controller; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -//import org.junit.runner.RunWith; -import org.junit.jupiter.api.extension.ExtendWith; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -//import org.openqa.selenium.chrome.ChromeDriver; -//import org.openqa.selenium.chrome.ChromeOptions; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.firefox.FirefoxOptions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -//import io.github.bonigarcia.wdm.WebDriverManager; - -import java.time.Duration; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -@ExtendWith(SpringExtension.class) -@AutoConfigureMockMvc -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class RegistrationAndLoginTest { - -// @Value("${local.server.port}") -// private int port; - - // an alternative really good resource: https://github.com/bonigarcia/webdrivermanager - - @Autowired - private MockMvc mockMvc; - WebDriver webDriver; - - @BeforeAll - static void setupClass() { - // set the path of geckodriver - System.setProperty("webdriver.gecko.driver", "C:\\UniProjects\\geckodriver-v0.35.0-win64\\geckodriver.exe"); - } - +//package uk.ac.cf.spring.demo.user.controller; +// +//import org.junit.jupiter.api.AfterEach; +//import org.junit.jupiter.api.BeforeAll; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.Test; +////import org.junit.runner.RunWith; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.openqa.selenium.By; +//import org.openqa.selenium.WebDriver; +////import org.openqa.selenium.chrome.ChromeDriver; +////import org.openqa.selenium.chrome.ChromeOptions; +//import org.openqa.selenium.firefox.FirefoxDriver; +//import org.openqa.selenium.firefox.FirefoxOptions; +//import org.openqa.selenium.support.ui.WebDriverWait; +//import org.springframework.beans.factory.annotation.Autowired; +////import org.springframework.beans.factory.annotation.Value; +//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +//import org.springframework.boot.test.context.SpringBootTest; +//import org.springframework.test.context.junit.jupiter.SpringExtension; +//import org.springframework.test.context.junit4.SpringRunner; +//import org.springframework.test.web.servlet.MockMvc; +////import io.github.bonigarcia.wdm.WebDriverManager; +// +//import java.time.Duration; +// +//import static org.junit.jupiter.api.Assertions.assertTrue; +// +//@ExtendWith(SpringExtension.class) +//@AutoConfigureMockMvc +//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +//public class RegistrationAndLoginTest { +// +//// @Value("${local.server.port}") +//// private int port; +// +// // an alternative really good resource: https://github.com/bonigarcia/webdrivermanager +// +// @Autowired +// private MockMvc mockMvc; +// WebDriver webDriver; +// // @BeforeAll // static void setupClass() { -// WebDriverManager.firefoxdriver().setup(); +// // set the path of geckodriver +// System.setProperty("webdriver.gecko.driver", "C:\\UniProjects\\geckodriver-v0.35.0-win64\\geckodriver.exe"); +// } +// +//// @BeforeAll +//// static void setupClass() { +//// WebDriverManager.firefoxdriver().setup(); +//// } +// +// @BeforeEach +// void setupTest() { +// FirefoxOptions options = new FirefoxOptions(); +//// options.addArguments("--remote-debugging-port=42227"); +// options.addArguments("--headless"); +// webDriver = new FirefoxDriver(options); +// } +// +// @AfterEach +// void teardown() { +// // Close the browser after each test +// if (webDriver != null) { +// webDriver.quit(); +// } // } - - @BeforeEach - void setupTest() { - FirefoxOptions options = new FirefoxOptions(); -// options.addArguments("--remote-debugging-port=42227"); - options.addArguments("--headless"); - webDriver = new FirefoxDriver(options); - } - - @AfterEach - void teardown() { - // Close the browser after each test - if (webDriver != null) { - webDriver.quit(); - } - } - +// // @Test // public void testUserRegistrationAndLogin() throws Exception { // // Step 1: Navigate to the registration page @@ -96,7 +96,7 @@ public class RegistrationAndLoginTest { // String currentUrl = webDriver.getCurrentUrl(); // assert currentUrl.endsWith("/html/matchSchedule.html"); // } - +// // @Test // public void testUserRegistrationAndLogin() throws Exception { // // Step 1: Navigate to the registration page @@ -130,23 +130,23 @@ public class RegistrationAndLoginTest { // String currentUrl = webDriver.getCurrentUrl(); // assertTrue(currentUrl.endsWith("/html/matchSchedule.html")); // } - - @Test - public void testLoginWithInvalidCredentials() throws Exception { - // Step 1: Navigate to the login page - webDriver.get("http://localhost:8080/html/login.html"); - - // Fill out the login form with invalid credentials - webDriver.findElement(By.id("email")).sendKeys("invalid@example.com"); - webDriver.findElement(By.id("password")).sendKeys("wrongpassword"); - webDriver.findElement(By.cssSelector("button[type='submit']")).click(); - - // Wait for the error message to appear - Thread.sleep(2000); // Simple wait for demonstration purposes - - // Verify that the error message is displayed - String errorMessage = webDriver.findElement(By.id("message")).getText(); - assert errorMessage.contains("Invalid email or password"); - } - -} +// +// @Test +// public void testLoginWithInvalidCredentials() throws Exception { +// // Step 1: Navigate to the login page +// webDriver.get("http://localhost:8080/html/login.html"); +// +// // Fill out the login form with invalid credentials +// webDriver.findElement(By.id("email")).sendKeys("invalid@example.com"); +// webDriver.findElement(By.id("password")).sendKeys("wrongpassword"); +// webDriver.findElement(By.cssSelector("button[type='submit']")).click(); +// +// // Wait for the error message to appear +// Thread.sleep(2000); // Simple wait for demonstration purposes +// +// // Verify that the error message is displayed +// String errorMessage = webDriver.findElement(By.id("message")).getText(); +// assert errorMessage.contains("Invalid email or password"); +// } +// +//}