Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Team5 Sports League application
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Haoyu Sun
Team5 Sports League application
Commits
e204c608
Commit
e204c608
authored
5 months ago
by
Xiemuqing Xiao
Browse files
Options
Downloads
Patches
Plain Diff
Merge remote-tracking branch 'origin/main'
parent
87201cea
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/uk/ac/cf/spring/demo/user/controller/RegistrationAndLoginTest.java
+87
-87
87 additions, 87 deletions
...spring/demo/user/controller/RegistrationAndLoginTest.java
with
87 additions
and
87 deletions
src/test/java/uk/ac/cf/spring/demo/user/controller/RegistrationAndLoginTest.java
+
87
−
87
View file @
e204c608
package
uk.ac.cf.spring.demo.user.controller
;
//package uk.ac.cf.spring.demo.user.controller;
//
import
org.junit.jupiter.api.AfterEach
;
//import org.junit.jupiter.api.AfterEach;
import
org.junit.jupiter.api.BeforeAll
;
//import org.junit.jupiter.api.BeforeAll;
import
org.junit.jupiter.api.BeforeEach
;
//import org.junit.jupiter.api.BeforeEach;
import
org.junit.jupiter.api.Test
;
//import org.junit.jupiter.api.Test;
//import org.junit.runner.RunWith;
////import org.junit.runner.RunWith;
import
org.junit.jupiter.api.extension.ExtendWith
;
//import org.junit.jupiter.api.extension.ExtendWith;
import
org.openqa.selenium.By
;
//import org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver
;
//import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.chrome.ChromeDriver;
////import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.chrome.ChromeOptions;
////import org.openqa.selenium.chrome.ChromeOptions;
import
org.openqa.selenium.firefox.FirefoxDriver
;
//import org.openqa.selenium.firefox.FirefoxDriver;
import
org.openqa.selenium.firefox.FirefoxOptions
;
//import org.openqa.selenium.firefox.FirefoxOptions;
import
org.openqa.selenium.support.ui.WebDriverWait
;
//import org.openqa.selenium.support.ui.WebDriverWait;
import
org.springframework.beans.factory.annotation.Autowired
;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
////import org.springframework.beans.factory.annotation.Value;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import
org.springframework.boot.test.context.SpringBootTest
;
//import org.springframework.boot.test.context.SpringBootTest;
import
org.springframework.test.context.junit.jupiter.SpringExtension
;
//import org.springframework.test.context.junit.jupiter.SpringExtension;
import
org.springframework.test.context.junit4.SpringRunner
;
//import org.springframework.test.context.junit4.SpringRunner;
import
org.springframework.test.web.servlet.MockMvc
;
//import org.springframework.test.web.servlet.MockMvc;
//import io.github.bonigarcia.wdm.WebDriverManager;
////import io.github.bonigarcia.wdm.WebDriverManager;
//
import
java.time.Duration
;
//import java.time.Duration;
//
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
//import static org.junit.jupiter.api.Assertions.assertTrue;
//
@ExtendWith
(
SpringExtension
.
class
)
//@ExtendWith(SpringExtension.class)
@AutoConfigureMockMvc
//@AutoConfigureMockMvc
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public
class
RegistrationAndLoginTest
{
//public class RegistrationAndLoginTest {
//
// @Value("${local.server.port}")
//// @Value("${local.server.port}")
// private int port;
//// private int port;
//
// an alternative really good resource: https://github.com/bonigarcia/webdrivermanager
// // an alternative really good resource: https://github.com/bonigarcia/webdrivermanager
//
@Autowired
// @Autowired
private
MockMvc
mockMvc
;
// private MockMvc mockMvc;
WebDriver
webDriver
;
// 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"
);
}
// @BeforeAll
// @BeforeAll
// static void setupClass() {
// 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
// @Test
// public void testUserRegistrationAndLogin() throws Exception {
// public void testUserRegistrationAndLogin() throws Exception {
// // Step 1: Navigate to the registration page
// // Step 1: Navigate to the registration page
...
@@ -96,7 +96,7 @@ public class RegistrationAndLoginTest {
...
@@ -96,7 +96,7 @@ public class RegistrationAndLoginTest {
// String currentUrl = webDriver.getCurrentUrl();
// String currentUrl = webDriver.getCurrentUrl();
// assert currentUrl.endsWith("/html/matchSchedule.html");
// assert currentUrl.endsWith("/html/matchSchedule.html");
// }
// }
//
// @Test
// @Test
// public void testUserRegistrationAndLogin() throws Exception {
// public void testUserRegistrationAndLogin() throws Exception {
// // Step 1: Navigate to the registration page
// // Step 1: Navigate to the registration page
...
@@ -130,23 +130,23 @@ public class RegistrationAndLoginTest {
...
@@ -130,23 +130,23 @@ public class RegistrationAndLoginTest {
// String currentUrl = webDriver.getCurrentUrl();
// String currentUrl = webDriver.getCurrentUrl();
// assertTrue(currentUrl.endsWith("/html/matchSchedule.html"));
// assertTrue(currentUrl.endsWith("/html/matchSchedule.html"));
// }
// }
//
@Test
//
@Test
public
void
testLoginWithInvalidCredentials
()
throws
Exception
{
//
public void testLoginWithInvalidCredentials() throws Exception {
// Step 1: Navigate to the login page
//
// Step 1: Navigate to the login page
webDriver
.
get
(
"http://localhost:8080/html/login.html"
);
//
webDriver.get("http://localhost:8080/html/login.html");
//
// Fill out the login form with invalid credentials
//
// Fill out the login form with invalid credentials
webDriver
.
findElement
(
By
.
id
(
"email"
)).
sendKeys
(
"invalid@example.com"
);
//
webDriver.findElement(By.id("email")).sendKeys("invalid@example.com");
webDriver
.
findElement
(
By
.
id
(
"password"
)).
sendKeys
(
"wrongpassword"
);
//
webDriver.findElement(By.id("password")).sendKeys("wrongpassword");
webDriver
.
findElement
(
By
.
cssSelector
(
"button[type='submit']"
)).
click
();
//
webDriver.findElement(By.cssSelector("button[type='submit']")).click();
//
// Wait for the error message to appear
//
// Wait for the error message to appear
Thread
.
sleep
(
2000
);
// Simple wait for demonstration purposes
//
Thread.sleep(2000); // Simple wait for demonstration purposes
//
// Verify that the error message is displayed
//
// Verify that the error message is displayed
String
errorMessage
=
webDriver
.
findElement
(
By
.
id
(
"message"
)).
getText
();
//
String errorMessage = webDriver.findElement(By.id("message")).getText();
assert
errorMessage
.
contains
(
"Invalid email or password"
);
//
assert errorMessage.contains("Invalid email or password");
}
//
}
//
}
//
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment