diff --git a/pom.xml b/pom.xml index a421bff..ba0b40b 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,6 @@ 3.13.0 1.5.8 1.27.1 - 3.0.3 @@ -113,10 +112,6 @@ io.cucumber cucumber-java - - org.apache.pdfbox - pdfbox - test diff --git a/src/test/java/org/ays/browser/AysBrowser.java b/src/test/java/org/ays/browser/AysBrowser.java index 169ec76..dc95d14 100644 --- a/src/test/java/org/ays/browser/AysBrowser.java +++ b/src/test/java/org/ays/browser/AysBrowser.java @@ -60,7 +60,7 @@ public static void create(AysBrowserType browserType) { } default -> throw new IllegalArgumentException("Unimplemented browser type: " + browserType); } - + webDriver.manage().window().maximize(); log.debug("Browser has been started."); } diff --git a/src/test/java/org/ays/browser/AysPageActions.java b/src/test/java/org/ays/browser/AysPageActions.java index 4f6787a..12df669 100644 --- a/src/test/java/org/ays/browser/AysPageActions.java +++ b/src/test/java/org/ays/browser/AysPageActions.java @@ -11,7 +11,9 @@ import org.openqa.selenium.support.ui.WebDriverWait; import java.time.Duration; +import java.util.ArrayList; import java.util.List; +import java.util.Set; @Slf4j public class AysPageActions { @@ -58,7 +60,7 @@ public void clickMethod(WebElement element) { } public boolean isPresent(WebElement element) { - this.waitUntilClickable(element); + this.waitUntilVisible(element); return element.isDisplayed(); } @@ -90,4 +92,15 @@ public void waitFor(int seconds) { } } + public void openANewTab(String url) { + JavascriptExecutor javascriptExecutor = (JavascriptExecutor) webDriver; + javascriptExecutor.executeScript("window.open(arguments[0], '_blank');", url); + } + + public void switchToWindow() { + Set windowHandles = webDriver.getWindowHandles(); + List tabs = new ArrayList<>(windowHandles); + webDriver.switchTo().window(tabs.get(1)); + } + } diff --git a/src/test/java/org/ays/enums/AysLanguage.java b/src/test/java/org/ays/enums/AysLanguage.java new file mode 100644 index 0000000..79ca185 --- /dev/null +++ b/src/test/java/org/ays/enums/AysLanguage.java @@ -0,0 +1,31 @@ +package org.ays.enums; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.List; +import java.util.Locale; +import java.util.Optional; + +@Getter +@RequiredArgsConstructor +public enum AysLanguage { + + TR(new Locale("tr", "TR")), + EN(new Locale("en", "US")); + + private final Locale locale; + + public static List getLanguages() { + return List.of(AysLanguage.values()); + } + + public static AysLanguage valueOfCode(final Object languageCode) { + return Optional.ofNullable(languageCode) + .map(Object::toString) + .map(String::toUpperCase) + .map(AysLanguage::valueOf) + .orElse(EN); + } + +} diff --git a/src/test/java/org/ays/feature/Login.feature b/src/test/java/org/ays/feature/Login.feature index 493e4c3..db54bc5 100644 --- a/src/test/java/org/ays/feature/Login.feature +++ b/src/test/java/org/ays/feature/Login.feature @@ -1,8 +1,113 @@ -@Regression @Smoke +@Regression Feature: Login Functionality - Scenario: Login with a valid username and password + Background: Given Open the institution login page - When Enter the username and password - And Click the Login button - Then The user should be able to successfully log in + + @Smoke + Scenario: Login with valid email address and password + When Enter the email address and password + And Click on the Login button + Then The username should be displayed on the homepage after successful login + And accessToken and refreshToken should be stored in localStorage + + Scenario Outline: Login with unauthorized user + When Enter unauthorized "" and "" + And Click on the Login button + Then Error pop-up message should be displayed + Examples: + | emailAddress | password | + | unauthorized@email.us | password | + + Scenario Outline: Login with invalid emailAddress + When Enter invalid "" and "" + And Click on the Login button + Then User should be able to see invalid email error message + Examples: + | emailAddress | password | + | user | password | + | 123 | password | + | ..... | password | + | !'^+%&/*# | password | + | user@ays.o | password | + | user@aysorg | password | + | userays.org | password | + | @user.org | password | + + Scenario: Login with a blank email address + When Sets the email address to " " and enters "password" + And Click on the Login button + Then User should be able to see invalid email error message + + Scenario Outline: Login with invalid password + When Enter invalid "" and "" + And Click on the Login button + Then User should be able to see password errorMessage + Examples: + | emailAddress | password | + | user@email.us | pass | + + Scenario: Login with valid email address invalid password + When Enter valid emailAddress and invalid password + And Click on the Login button + Then Error pop-up message should be displayed + + Scenario: Login with invalid email address valid password + When Enter invalid emailAddress and valid password + And Click on the Login button + Then Error pop-up message should be displayed + + Scenario: Login with blank email address and password + And Click on the Login button + Then User should be able to see errorMessage under email and password input box + + @Smoke + Scenario: Password hiding checking + When Enter hiding password + And Click on the eye icon + Then The password should be displayed without being hidden + And Click on the eye icon + Then The password should be displayed hidden + + @Smoke + Scenario: Theme checking + When Click on the theme icon + Then User should be able to see dark theme + And Click on the theme icon + Then User should be able to see light theme + + @Smoke + Scenario: Language selection checking + When Click on the language button + And Select the "Turkish" option + Then The user should be able to see all texts compatible with the Turkish language + And Click on the language button + And Select the "İngilizce" option + Then The user should be able to see all texts compatible with the English language + + Scenario: Logged-in user visits login URL + + As a logged-in user, I should not see the login page again when I navigate to the login URL + Instead, I should be redirected to the dashboard page. + + When Enter the email address and password + And Click on the Login button + Then The username should be displayed on the homepage after successful login + And The user navigates to the login URL in a new tab + Then The user should be able to see dashboard page + + Scenario: Dashboard page access without login + + As a user, I should not be able to access the dashboard page without logging in + Instead, I should be redirected to the login page. + + When The user navigates to the dashboard page + Then The user should see the login page + + Scenario: Refresh Token expiration triggers logout + When Enter the email address and password + And Click on the Login button + And accessToken and refreshToken should be stored in localStorage + And The "refreshToken" expires using mock expiration + Then The user should see the login page + diff --git a/src/test/java/org/ays/feature/Logout.feature b/src/test/java/org/ays/feature/Logout.feature index 3a97e8c..8e011e8 100644 --- a/src/test/java/org/ays/feature/Logout.feature +++ b/src/test/java/org/ays/feature/Logout.feature @@ -1,10 +1,9 @@ -@Regression @Smoke Feature: Testing Logout Background: Given Open the institution login page - When Enter the username and password - And Click the Login button + When Enter the email address and password + And Click on the Login button Scenario: Validating logout functionality When Click on the profile button diff --git a/src/test/java/org/ays/pages/BasePage.java b/src/test/java/org/ays/pages/BasePage.java new file mode 100644 index 0000000..2fb4d94 --- /dev/null +++ b/src/test/java/org/ays/pages/BasePage.java @@ -0,0 +1,24 @@ +package org.ays.pages; + +import org.ays.browser.AysBrowser; +import org.ays.browser.AysPageActions; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +public class BasePage { + + private final AysPageActions actions = new AysPageActions(); + + public BasePage() { + PageFactory.initElements(AysBrowser.getWebDriver(), this); + } + + public void selectLanguage(String language) { + String locator = "//span[text()='" + language + "']"; + WebElement element = AysBrowser.getWebDriver().findElement(By.xpath(locator)); + actions.clickMethod(element); + + } + +} diff --git a/src/test/java/org/ays/pages/LoginPOM.java b/src/test/java/org/ays/pages/LoginPOM.java deleted file mode 100644 index 284fe87..0000000 --- a/src/test/java/org/ays/pages/LoginPOM.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.ays.pages; - -import lombok.Getter; -import org.ays.browser.AysBrowser; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.PageFactory; - -@Getter -public class LoginPOM { - - public LoginPOM() { - PageFactory.initElements(AysBrowser.getWebDriver(), this); - } - - @FindBy(xpath = "//input[@id='username']") - private WebElement loginUsername; - - @FindBy(xpath = "//input[@id='password']") - private WebElement loginPassword; - - @FindBy(xpath = "//button[@type='submit']") - private WebElement loginButton; - - @FindBy(xpath = "//a[.='Admins']") - private WebElement adminsHeader; - -} diff --git a/src/test/java/org/ays/pages/LoginPage.java b/src/test/java/org/ays/pages/LoginPage.java new file mode 100644 index 0000000..683c12b --- /dev/null +++ b/src/test/java/org/ays/pages/LoginPage.java @@ -0,0 +1,54 @@ +package org.ays.pages; + +import lombok.Getter; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +@Getter +public class LoginPage extends BasePage { + + + @FindBy(name = "emailAddress") + private WebElement loginEmailAddress; + + @FindBy(name = "password") + private WebElement loginPassword; + + @FindBy(xpath = "//button[@type='submit']") + private WebElement loginButton; + + @FindBy(xpath = "//div[contains(@class, 'ml-3')]") + private WebElement username; + + @FindBy(id = ":r1:-form-item-message") + private WebElement emailAddressErrorMessage; + + @FindBy(id = ":r2:-form-item-message") + private WebElement passwordErrorMessage; + + @FindBy(xpath = "//div[contains(@class,'text-sm opacity-90')]") + private WebElement popupErrorMessage; + + @FindBy(xpath = "//div[@class= 'relative']/button") + private WebElement hiddenPasswordIcon; + + @FindBy(css = "button") + private WebElement themeIcon; + + @FindBy(css = "html.light") + private WebElement lightTheme; + + @FindBy(css = "html.dark") + private WebElement darkTheme; + + @FindBy(css = "button[role='combobox']") + private WebElement languageButton; + + @FindBy(xpath = "//h3") + private WebElement welcomeHeader; + + @FindBy(xpath = "//div[@class='container']") + private WebElement allLoginText; + + +} diff --git a/src/test/java/org/ays/pages/LogoutPOM.java b/src/test/java/org/ays/pages/LogoutPage.java similarity index 71% rename from src/test/java/org/ays/pages/LogoutPOM.java rename to src/test/java/org/ays/pages/LogoutPage.java index c999107..4082160 100644 --- a/src/test/java/org/ays/pages/LogoutPOM.java +++ b/src/test/java/org/ays/pages/LogoutPage.java @@ -1,17 +1,11 @@ package org.ays.pages; import lombok.Getter; -import org.ays.browser.AysBrowser; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.PageFactory; @Getter -public class LogoutPOM { - - public LogoutPOM() { - PageFactory.initElements(AysBrowser.getWebDriver(), this); - } +public class LogoutPage extends BasePage { @FindBy(xpath = "//span[@class='ant-menu-title-content'][1]") private WebElement adminsButton; diff --git a/src/test/java/org/ays/runners/RunnerForSmokeTest.java b/src/test/java/org/ays/runners/RunnerForSmokeTest.java index 564a100..631cba1 100644 --- a/src/test/java/org/ays/runners/RunnerForSmokeTest.java +++ b/src/test/java/org/ays/runners/RunnerForSmokeTest.java @@ -2,6 +2,9 @@ import io.cucumber.testng.CucumberOptions; -@CucumberOptions(tags = "@Smoke") +@CucumberOptions( + plugin = {"pretty"}, + tags = "@Smoke", publish = true +) public class RunnerForSmokeTest extends AysAbstractTestNGCucumberTests { } diff --git a/src/test/java/org/ays/step_definitions/Common.java b/src/test/java/org/ays/step_definitions/Common.java new file mode 100644 index 0000000..e3f8286 --- /dev/null +++ b/src/test/java/org/ays/step_definitions/Common.java @@ -0,0 +1,99 @@ +package org.ays.step_definitions; + +import io.cucumber.java.en.And; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import org.ays.browser.AysPageActions; +import org.ays.pages.BasePage; +import org.ays.pages.LoginPage; +import org.ays.utilities.AysLocaleStorageUtil; +import org.ays.utilities.AysLocalizationUtil; + +import static org.ays.enums.AysLanguage.EN; +import static org.ays.enums.AysLanguage.TR; +import static org.testng.Assert.assertTrue; + +public class Common { + private final LoginPage loginPage; + private final BasePage basePage; + private final AysPageActions pageActions; + + public Common() { + + this.loginPage = new LoginPage(); + this.basePage = new BasePage(); + this.pageActions = new AysPageActions(); + + } + + @When("Click on the theme icon") + public void clickOnTheThemeIcon() { + pageActions.moveToElement(loginPage.getThemeIcon()); + pageActions.clickElementWithJavaScript(loginPage.getThemeIcon()); + } + + @Then("User should be able to see dark theme") + public void userShouldBeAbleToSeeDarkTheme() { + pageActions.waitUntilVisible(loginPage.getDarkTheme()); + assertTrue(pageActions.isPresent(loginPage.getDarkTheme())); + } + + @Then("User should be able to see light theme") + public void userShouldBeAbleToSeeLightTheme() { + pageActions.waitUntilVisible(loginPage.getLightTheme()); + assertTrue(pageActions.isPresent(loginPage.getLightTheme())); + } + + @When("Click on the language button") + public void clickOnTheLanguageButton() { + pageActions.moveToElement(loginPage.getLanguageButton()); + pageActions.clickMethod(loginPage.getLanguageButton()); + } + + @And("Select the {string} option") + public void selectTheOption(String language) { + pageActions.waitFor(1); + basePage.selectLanguage(language); + pageActions.getWebDriver().navigate().refresh(); + } + + @Then("The user should be able to see all texts compatible with the Turkish language") + public void theUserShouldBeAbleToSeeAllTextsCompatibleWithTheTurkishLanguage() { + if (AysLocaleStorageUtil.getLanguageFromLocalStorage().equals("tr")) { + AysLocalizationUtil.setLanguage(TR); + + assertTrue(loginPage.getAllLoginText().getText() + .contains(AysLocalizationUtil.getText("login.header.welcome"))); + assertTrue(loginPage.getAllLoginText().getText() + .contains(AysLocalizationUtil.getText("login.sub_title"))); + assertTrue(loginPage.getAllLoginText().getText() + .contains(AysLocalizationUtil.getText("login.input.email"))); + assertTrue(loginPage.getAllLoginText().getText() + .contains(AysLocalizationUtil.getText("login.input.password"))); + assertTrue(loginPage.getAllLoginText().getText() + .contains(AysLocalizationUtil.getText("login.button.login"))); + assertTrue(loginPage.getAllLoginText().getText() + .contains(AysLocalizationUtil.getText("login.button.forgot_password"))); + } + } + + @Then("The user should be able to see all texts compatible with the English language") + public void theUserShouldBeAbleToSeeAllTextsCompatibleWithTheEnglishLanguage() { + if (AysLocaleStorageUtil.getLanguageFromLocalStorage().equals("en")) { + AysLocalizationUtil.setLanguage(EN); + + assertTrue(loginPage.getAllLoginText().getText() + .contains(AysLocalizationUtil.getText("login.header.welcome"))); + assertTrue(loginPage.getAllLoginText().getText() + .contains(AysLocalizationUtil.getText("login.sub_title"))); + assertTrue(loginPage.getAllLoginText().getText() + .contains(AysLocalizationUtil.getText("login.input.email"))); + assertTrue(loginPage.getAllLoginText().getText() + .contains(AysLocalizationUtil.getText("login.input.password"))); + assertTrue(loginPage.getAllLoginText().getText() + .contains(AysLocalizationUtil.getText("login.button.login"))); + assertTrue(loginPage.getAllLoginText().getText() + .contains(AysLocalizationUtil.getText("login.button.forgot_password"))); + } + } +} diff --git a/src/test/java/org/ays/step_definitions/Login.java b/src/test/java/org/ays/step_definitions/Login.java index fb34521..9fa782d 100644 --- a/src/test/java/org/ays/step_definitions/Login.java +++ b/src/test/java/org/ays/step_definitions/Login.java @@ -5,36 +5,179 @@ import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import org.ays.browser.AysPageActions; -import org.ays.pages.LoginPOM; +import org.ays.pages.LoginPage; import org.ays.configuration.AysConfigurationProperty; -import org.testng.Assert; +import org.ays.utilities.AysLocalizationUtil; +import org.ays.utilities.AysLocaleStorageUtil; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + public class Login { - private final LoginPOM loginPOM = new LoginPOM(); - private final AysPageActions pageActions = new AysPageActions(); + private final LoginPage loginPage; + private final AysPageActions pageActions; + private final AysLocaleStorageUtil localeStorageUtil; + private final AysLocalizationUtil localizationUtil; + + + public Login() { + + this.loginPage = new LoginPage(); + this.pageActions = new AysPageActions(); + this.localeStorageUtil = new AysLocaleStorageUtil(); + this.localizationUtil = new AysLocalizationUtil(); + + } @Given("Open the institution login page") - public void open_the_institution_login_page() { - this.pageActions.getWebDriver().get(AysConfigurationProperty.Ui.URL); - this.pageActions.getWebDriver().manage().window().maximize(); + public void openTheInstitutionLoginPage() { + pageActions.getWebDriver().get(AysConfigurationProperty.Ui.URL); + } + + @When("Enter the email address and password") + public void enterTheEmailAddressAndPassword() { + pageActions.sendKeysMethod(loginPage.getLoginEmailAddress(), AysConfigurationProperty + .TestVolunteerFoundation.Admin.EMAIL_ADDRESS); + pageActions.sendKeysMethod(loginPage.getLoginPassword(), AysConfigurationProperty + .TestVolunteerFoundation.Admin.PASSWORD); + } + + @And("Click on the Login button") + public void clickOnTheLoginButton() { + pageActions.clickMethod(loginPage.getLoginButton()); + } + + @Then("The username should be displayed on the homepage after successful login") + public void theUsernameShouldBeDisplayedOnTheHomepageAfterSuccessfulLogin() { + pageActions.waitUntilVisible(loginPage.getUsername()); + assertTrue(pageActions.isPresent(loginPage.getUsername())); } - @When("Enter the username and password") - public void enter_the_username_and_password() { - this.pageActions.sendKeysMethod(loginPOM.getLoginUsername(), AysConfigurationProperty.TestVolunteerFoundation.Admin.EMAIL_ADDRESS); - this.pageActions.sendKeysMethod(loginPOM.getLoginPassword(), AysConfigurationProperty.TestVolunteerFoundation.Admin.PASSWORD); + @And("accessToken and refreshToken should be stored in localStorage") + public void accessTokenAndRefreshTokenShouldBeStoredInLocalStorage() { + pageActions.waitFor(2); + localeStorageUtil.assertTokensStoredInLocalStorage(); } - @And("Click the Login button") - public void click_the_Login_button() { - this.pageActions.clickMethod(loginPOM.getLoginButton()); + @When("Enter invalid {string} and {string}") + public void enterInvalidAnd(String emailAddress, String password) { + pageActions.sendKeysMethod(loginPage.getLoginEmailAddress(), emailAddress); + pageActions.sendKeysMethod(loginPage.getLoginPassword(), password); } - @Then("The user should be able to successfully log in") - public void the_user_should_be_able_to_successfully_log_in() { - this.pageActions.waitUntilVisible(loginPOM.getAdminsHeader()); - Assert.assertTrue(loginPOM.getAdminsHeader().isDisplayed()); + @When("Sets the email address to {string} and enters {string}") + public void setsTheEmailAddressToAndEnters(String emailAddress, String password) { + pageActions.sendKeysMethod(loginPage.getLoginEmailAddress(), emailAddress); + pageActions.sendKeysMethod(loginPage.getLoginPassword(), password); } + @Then("User should be able to see invalid email error message") + public void userShouldBeAbleToSeeInvalidEmailErrorMessage() { + localizationUtil.validateElementMessage("login.validation_error.email_address", + loginPage.getEmailAddressErrorMessage().getText(), + true); + } + + @Then("User should be able to see password errorMessage") + public void userShouldBeAbleToSeePasswordErrorMessage() { + localizationUtil.validateElementMessage("login.validation_error.password", + loginPage.getPasswordErrorMessage().getText(), + true); + } + + @When("Enter unauthorized {string} and {string}") + public void enterUnauthorizedAnd(String emailAddress, String password) { + pageActions.sendKeysMethod(loginPage.getLoginEmailAddress(), emailAddress); + pageActions.sendKeysMethod(loginPage.getLoginPassword(), password); + } + + @Then("Error pop-up message should be displayed") + public void errorPopUpMessageShouldBeDisplayed() { + pageActions.waitUntilVisible(loginPage.getPopupErrorMessage()); + localizationUtil.validateElementMessage("login.popup_error_message", + loginPage.getPopupErrorMessage().getText(), + true); + } + + @Then("User should be able to see errorMessage under email and password input box") + public void userShouldBeAbleToSeeErrorMessageUnderEmailAndPasswordInputBox() { + assertTrue(pageActions.isPresent(loginPage.getEmailAddressErrorMessage())); + assertTrue(pageActions.isPresent(loginPage.getPasswordErrorMessage())); + } + + @When("Enter hiding password") + public void enterHidingPassword() { + pageActions.sendKeysMethod(loginPage.getLoginPassword(), "passwordCheck"); + } + + @And("Click on the eye icon") + public void clickOnTheEyeIcon() { + pageActions.clickMethod(loginPage.getHiddenPasswordIcon()); + } + + @Then("The password should be displayed without being hidden") + public void thePasswordShouldBeDisplayedWithoutBeingHidden() { + assertEquals(loginPage.getLoginPassword().getAttribute("type"), "text"); + } + + @Then("The password should be displayed hidden") + public void thePasswordShouldBeDisplayedHidden() { + assertEquals(loginPage.getLoginPassword().getAttribute("type"), "password"); + } + + + @When("Enter valid emailAddress and invalid password") + public void enterValidEmailAddressAndInvalidPassword() { + pageActions.sendKeysMethod(loginPage.getLoginEmailAddress(), AysConfigurationProperty + .TestVolunteerFoundation.Admin.EMAIL_ADDRESS); + pageActions.sendKeysMethod(loginPage.getLoginPassword(), "password"); + } + + @When("Enter invalid emailAddress and valid password") + public void enterInvalidEmailAddressAndValidPassword() { + pageActions.sendKeysMethod(loginPage.getLoginEmailAddress(), "invalid@email.us"); + pageActions.sendKeysMethod(loginPage.getLoginPassword(), AysConfigurationProperty + .TestVolunteerFoundation.Admin.PASSWORD); + } + + @And("The user navigates to the login URL in a new tab") + public void theUserNavigatesToTheLoginURLInANewTab() { + pageActions.openANewTab(AysConfigurationProperty.Ui.URL); + pageActions.switchToWindow(); + + } + + @Then("The user should be able to see dashboard page") + public void theUserShouldBeAbleToSeeDashboardPage() { + pageActions.waitUntilVisible(loginPage.getUsername()); + assertTrue(pageActions.getWebDriver().getCurrentUrl().contains("/dashboard")); + + } + + @When("The user navigates to the dashboard page") + public void theUserNavigatesToTheDashboardPage() { + pageActions.getWebDriver().navigate().to(AysConfigurationProperty.Ui.URL + "/dashboard"); + } + + @Then("The user should see the login page") + public void theUserShouldSeeTheLoginPage() { + pageActions.waitUntilVisible(loginPage.getWelcomeHeader()); + assertTrue(pageActions.getWebDriver().getCurrentUrl().contains("/login")); + } + + @And("The {string} expires using mock expiration") + public void theExpiresUsingMockExpiration(String token) { + pageActions.waitFor(2); + localeStorageUtil.mockTokenExpiration(token); + } + + @Then("Refresh token generates a new access token and the user continues to login") + public void refreshTokenGeneratesANewAccessTokenAndTheUserContinuesToLogin() { + pageActions.waitUntilVisible(loginPage.getUsername()); + assertTrue(pageActions.getWebDriver().getCurrentUrl().contains("/dashboard")); + } + + } diff --git a/src/test/java/org/ays/step_definitions/Logout.java b/src/test/java/org/ays/step_definitions/Logout.java index 67e9d44..56ed506 100644 --- a/src/test/java/org/ays/step_definitions/Logout.java +++ b/src/test/java/org/ays/step_definitions/Logout.java @@ -1,39 +1,37 @@ package org.ays.step_definitions; import io.cucumber.java.en.And; -import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import org.ays.browser.AysPageActions; -import org.ays.pages.LogoutPOM; +import org.ays.pages.LogoutPage; import org.testng.Assert; public class Logout { - private final LogoutPOM logoutPOM; + private final LogoutPage logoutPage; private final AysPageActions pageActions; public Logout() { - this.logoutPOM = new LogoutPOM(); + this.logoutPage = new LogoutPage(); this.pageActions = new AysPageActions(); } - @When("Click on the profile button") public void clickOnTheProfileButton() { - pageActions.waitUntilVisible(logoutPOM.getProfileButton()); - pageActions.hoverOver(logoutPOM.getProfileButton()); + pageActions.waitUntilVisible(logoutPage.getProfileButton()); + pageActions.hoverOver(logoutPage.getProfileButton()); } @And("Click on the logout button") public void clickOnTheLogoutButton() { - pageActions.waitUntilVisible(logoutPOM.getLogoutButton()); - pageActions.clickMethod(logoutPOM.getLogoutButton()); + pageActions.waitUntilVisible(logoutPage.getLogoutButton()); + pageActions.clickMethod(logoutPage.getLogoutButton()); } @Then("the admin user should land on the Login page after logging out.") public void theAdminUserShouldLandOnTheLoginPageAfterLoggingOut() { - Assert.assertTrue(pageActions.isPresent(logoutPOM.getLoginButton())); + Assert.assertTrue(pageActions.isPresent(logoutPage.getLoginButton())); } } diff --git a/src/test/java/org/ays/utilities/AysLocaleStorageUtil.java b/src/test/java/org/ays/utilities/AysLocaleStorageUtil.java new file mode 100644 index 0000000..0175f70 --- /dev/null +++ b/src/test/java/org/ays/utilities/AysLocaleStorageUtil.java @@ -0,0 +1,94 @@ +package org.ays.utilities; + +import org.ays.browser.AysPageActions; +import org.ays.enums.AysLanguage; +import org.openqa.selenium.JavascriptExecutor; + +import static org.ays.enums.AysLanguage.EN; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + + +public class AysLocaleStorageUtil { + + private static AysPageActions pageActions; + + public AysLocaleStorageUtil() { + pageActions = new AysPageActions(); + } + + public void assertTokensStoredInLocalStorage() { + try { + JavascriptExecutor javascriptExecutor = (JavascriptExecutor) pageActions.getWebDriver(); + String rootData = (String) javascriptExecutor.executeScript("return localStorage.getItem('persist:root');"); + + if (rootData == null) { + throw new Exception("rootData is null. 'persist:root' data not found in localStorage."); + } + + assertTrue(rootData.contains("accessToken"), "'accessToken' not found in localStorage."); + assertTrue(rootData.contains("refreshToken"), "'refreshToken' not found in localStorage."); + + } catch (Exception exception) { + fail("An error occurred while checking tokens in localStorage: " + exception.getMessage()); + exception.printStackTrace(); + } + + } + + public void toggleLanguageInLocalStorage(String language) { + try { + JavascriptExecutor javascriptExecutor = (JavascriptExecutor) pageActions.getWebDriver(); + javascriptExecutor.executeScript("localStorage.setItem('language', arguments[0]);", language); + + pageActions.getWebDriver().navigate().refresh(); + pageActions.waitFor(2); + + } catch (Exception exception) { + fail("An error occurred while toggling language in localStorage: " + exception.getMessage()); + exception.printStackTrace(); + } + + } + + public static AysLanguage getLanguageFromLocalStorage() { + try { + JavascriptExecutor javascriptExecutor = (JavascriptExecutor) pageActions.getWebDriver(); + AysLanguage language = AysLanguage.valueOfCode( + javascriptExecutor.executeScript("return localStorage.getItem('language');") + ); + + pageActions.waitFor(2); + + return language; + } catch (Exception exception) { + fail("An error occurred while retrieving the language from localStorage: " + exception.getMessage()); + exception.printStackTrace(); + } + return EN; + } + + public void mockTokenExpiration(String token) { + try { + JavascriptExecutor javascriptExecutor = (JavascriptExecutor) pageActions.getWebDriver(); + javascriptExecutor.executeScript("let persistData = JSON.parse(localStorage.getItem('persist:root')); " + + "if (persistData) { " + + " let authData = JSON.parse(persistData.auth); " + + " if ('refreshToken' === '" + token + "') { " + + " authData.accessToken ='';" + + " authData.refreshToken = '';" + + " } " + + " persistData.auth = JSON.stringify(authData); " + + " localStorage.setItem('persist:root', JSON.stringify(persistData));" + + "} else { " + + " throw 'persist:root not found'; " + + "}"); + + pageActions.getWebDriver().navigate().refresh(); + } catch (Exception exception) { + fail("An error occurred while mocking token expiration: " + exception.getMessage()); + exception.printStackTrace(); + } + } + +} diff --git a/src/test/java/org/ays/utilities/AysLocalizationUtil.java b/src/test/java/org/ays/utilities/AysLocalizationUtil.java new file mode 100644 index 0000000..2d22c37 --- /dev/null +++ b/src/test/java/org/ays/utilities/AysLocalizationUtil.java @@ -0,0 +1,61 @@ +package org.ays.utilities; + +import org.ays.enums.AysLanguage; + +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; + +import static org.testng.Assert.assertEquals; + +public class AysLocalizationUtil { + + /** + * This utility class for managing localization in the application. + * Provides methods to set the application's language and retrieve + * localized text based on a given key. Text values are fetched from the + * corresponding language-specific properties file within the + * "ays_ui_elements" resource bundle. + *

+ *

Testing Guidelines: + *
  • To check messages by language in tests, just call the validateMessage method. + *
  • Use the getText method to retrieve the expected validation message + *
  • Use the setLanguage method to changes the page language and determines the language of the "ays_ui_elements" file + */ + private static ResourceBundle bundle; + + public static void setLanguage(AysLanguage language) { + Locale locale = language.getLocale(); + bundle = ResourceBundle.getBundle("ays_ui_elements", locale); + } + + public static String getText(String key) { + if (bundle == null) { + throw new IllegalStateException("Language setting has not been applied. Please call the setLanguage() method first."); + } + return bundle.getString(key); + } + + public void validateElementMessage(String key, String actualText, boolean isLocalStorageBased) { + AysLanguage currentLanguage = AysLocaleStorageUtil.getLanguageFromLocalStorage(); + + if (isLocalStorageBased) { + setLanguage(currentLanguage); + assertEquals(actualText, getText(key)); + return; + } + + List languages = AysLanguage.getLanguages(); + + for (AysLanguage language : languages) { + // TODO: Remove this if condition when the bug in AYS-505 is resolved + if (language.equals(currentLanguage)) { + setLanguage(language); + assertEquals(actualText, getText(key)); + break; + } + } + + } + +} diff --git a/src/test/resources/ays_ui_elements_en.properties b/src/test/resources/ays_ui_elements_en.properties new file mode 100644 index 0000000..c08f203 --- /dev/null +++ b/src/test/resources/ays_ui_elements_en.properties @@ -0,0 +1,9 @@ +login.header.welcome=Welcome +login.sub_title=Please enter your E-mail and Password. +login.input.email=E-mail +login.input.password=Password +login.button.login=Login +login.button.forgot_password=Forgot password? +login.validation_error.email_address=Invalid E-mail. +login.validation_error.password=This field must be at least 6 characters. +login.popup_error_message=Invalid E-mail or Password. diff --git a/src/test/resources/ays_ui_elements_tr.properties b/src/test/resources/ays_ui_elements_tr.properties new file mode 100644 index 0000000..15adcc1 --- /dev/null +++ b/src/test/resources/ays_ui_elements_tr.properties @@ -0,0 +1,9 @@ +login.header.welcome=Hoş Geldiniz +login.sub_title=Lütfen E-postanızı ve Şifrenizi giriniz. +login.input.email=E-posta +login.input.password=Şifre +login.button.login=Oturum Aç +login.button.forgot_password=Şifrenizi mi unuttunuz? +login.validation_error.email_address=Geçersiz e-posta adresi. +login.validation_error.password=Bu alan en az 6 karakter olmalıdır. +login.popup_error_message=Geçersiz e-posta veya şifre. diff --git a/src/test/resources/testsuite/RegressionTest.xml b/src/test/resources/testsuite/RegressionTest.xml index 23cce36..e56364b 100644 --- a/src/test/resources/testsuite/RegressionTest.xml +++ b/src/test/resources/testsuite/RegressionTest.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file