-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
Write ui test for register page
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package ui; | ||
|
||
import com.codeborne.selenide.Configuration; | ||
import com.codeborne.selenide.Selenide; | ||
import io.github.bonigarcia.wdm.WebDriverManager; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
public abstract class BaseTest { | ||
|
||
public void setUp() { | ||
WebDriverManager.chromedriver().setup(); | ||
Configuration.browser = "chrome"; | ||
Configuration.browserSize = "2560x1440"; | ||
Configuration.webdriverLogsEnabled = true; | ||
Configuration.headless = false; | ||
} | ||
|
||
@BeforeEach | ||
public void init() { | ||
setUp(); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
Selenide.closeWebDriver(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package ui; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import ui.jdbc.Jdbc; | ||
import ui.page.RegisterPage; | ||
import ui.page.SuccessRegisterPage; | ||
|
||
import static ui.data.UserTestData.*; | ||
|
||
public class SpringUserFrameworkTest extends BaseTest { | ||
private static final String SUCCESS_MESSAGE = "Thank you for registering!"; | ||
private static final String URI = "http://localhost:8080/"; | ||
|
||
@AfterAll | ||
public static void deleteTestUser() { | ||
Jdbc.deleteTestUser(); | ||
} | ||
|
||
@Test | ||
public void successSignUp() { | ||
RegisterPage registerPage = new RegisterPage(URI + "user/register.html"); | ||
registerPage.signUp(FIRST_NAME, LAST_NAME, EMAIL, PASSWORD, CONFIRM_PASSWORD); | ||
SuccessRegisterPage successRegisterPage = new SuccessRegisterPage(); | ||
String actual = successRegisterPage.message(); | ||
Assertions.assertEquals(actual, SUCCESS_MESSAGE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ui.data; | ||
|
||
public class UserTestData { | ||
public static final String FIRST_NAME = "testUser"; | ||
public static final String LAST_NAME = "userTest"; | ||
public static final String EMAIL = "[email protected]"; | ||
public static final String PASSWORD = "testUserPassword"; | ||
public static final String CONFIRM_PASSWORD = "testUserPassword"; | ||
|
||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package ui.jdbc; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
public class ConnectionManager { | ||
|
||
static { | ||
initDriver(); | ||
} | ||
|
||
private static void initDriver() { | ||
try { | ||
Class.forName("org.mariadb.jdbc.Driver"); | ||
} catch (ClassNotFoundException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static Connection open() { | ||
try { | ||
return DriverManager.getConnection("jdbc:mariadb://127.0.0.1:3306/springuser", "springuser", "springuser"); | ||
} catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ui.jdbc; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
|
||
import static ui.data.UserTestData.EMAIL; | ||
import static ui.data.UserTestData.FIRST_NAME; | ||
|
||
/** | ||
* Using for test user data from db when it storing by UI test | ||
*/ | ||
public class Jdbc { | ||
private static final String DELETE_VERIFICATION_TOKEN_QUERY = "DELETE FROM verification_token WHERE user_id = (SELECT id FROM user_account WHERE first_name = ? AND email = ?)"; | ||
private static final String DELETE_TEST_USER_ROLE = "DELETE FROM users_roles WHERE user_id = (SELECT id FROM user_account WHERE first_name = ? AND email = ?)"; | ||
private static final String DELETE_TEST_USER_QUERY = "DELETE FROM user_account WHERE first_name = ? AND email = ?"; | ||
public static void deleteTestUser() { | ||
try(Connection connection = ConnectionManager.open()) { | ||
execute(connection, DELETE_VERIFICATION_TOKEN_QUERY); | ||
execute(connection, DELETE_TEST_USER_ROLE); | ||
execute(connection, DELETE_TEST_USER_QUERY); | ||
} catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static void execute(Connection connection, String query) throws SQLException { | ||
PreparedStatement statement = connection.prepareStatement(query); | ||
statement.setString(1, FIRST_NAME); | ||
statement.setString(2, EMAIL); | ||
statement.executeUpdate(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ui.page; | ||
|
||
import com.codeborne.selenide.Selenide; | ||
import com.codeborne.selenide.SelenideElement; | ||
|
||
/** | ||
* Register page | ||
*/ | ||
public class RegisterPage { | ||
private final SelenideElement FIRST_NAME_FIELD = Selenide.$x("//input[@id='firstName']"); | ||
private final SelenideElement LAST_NAME_FIELD = Selenide.$x("//input[@id='lastName']"); | ||
private final SelenideElement EMAIL_FIELD = Selenide.$x("//input[@id='email']"); | ||
private final SelenideElement PASSWORD_FIELD = Selenide.$x("//input[@id='password']"); | ||
private final SelenideElement CONFIRM_PASSWORD_FIELD = Selenide.$x("//input[@id='matchPassword']"); | ||
private final SelenideElement SIGN_UP_BUTTON = Selenide.$x("//button[@id='signUpButton']"); | ||
|
||
public RegisterPage(String url) { | ||
Selenide.open(url); | ||
} | ||
/** | ||
* Filling register form and click signUp button | ||
*/ | ||
public void signUp(String firstName, String lastName, String email, String password, String confirmPassword) { | ||
FIRST_NAME_FIELD.setValue(firstName); | ||
LAST_NAME_FIELD.setValue(lastName); | ||
EMAIL_FIELD.setValue(email); | ||
PASSWORD_FIELD.setValue(password); | ||
CONFIRM_PASSWORD_FIELD.setValue(confirmPassword); | ||
SIGN_UP_BUTTON.click(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ui.page; | ||
|
||
import com.codeborne.selenide.SelenideElement; | ||
|
||
import static com.codeborne.selenide.Selenide.$x; | ||
|
||
public class SuccessRegisterPage { | ||
private final SelenideElement SUCCESS_MESSAGE = $x("//section//div//h1"); | ||
|
||
public String message() { | ||
return SUCCESS_MESSAGE.text(); | ||
} | ||
} |