Skip to content

Commit

Permalink
AYS-448 | Login Functionality Automation (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
cagla88 authored Dec 22, 2024
1 parent ce0cad3 commit c6c1b4f
Show file tree
Hide file tree
Showing 19 changed files with 683 additions and 80 deletions.
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<logback-classic.version>1.5.8</logback-classic.version>
<commons-compress.version>1.27.1</commons-compress.version>
<pdfbox.version>3.0.3</pdfbox.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -113,10 +112,6 @@
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/ays/browser/AysBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

Expand Down
15 changes: 14 additions & 1 deletion src/test/java/org/ays/browser/AysPageActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -58,7 +60,7 @@ public void clickMethod(WebElement element) {
}

public boolean isPresent(WebElement element) {
this.waitUntilClickable(element);
this.waitUntilVisible(element);
return element.isDisplayed();
}

Expand Down Expand Up @@ -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<String> windowHandles = webDriver.getWindowHandles();
List<String> tabs = new ArrayList<>(windowHandles);
webDriver.switchTo().window(tabs.get(1));
}

}
31 changes: 31 additions & 0 deletions src/test/java/org/ays/enums/AysLanguage.java
Original file line number Diff line number Diff line change
@@ -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<AysLanguage> 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);
}

}
115 changes: 110 additions & 5 deletions src/test/java/org/ays/feature/Login.feature
Original file line number Diff line number Diff line change
@@ -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 "<emailAddress>" and "<password>"
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 "<emailAddress>" and "<password>"
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 "<emailAddress>" and "<password>"
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

5 changes: 2 additions & 3 deletions src/test/java/org/ays/feature/Logout.feature
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/ays/pages/BasePage.java
Original file line number Diff line number Diff line change
@@ -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);

}

}
28 changes: 0 additions & 28 deletions src/test/java/org/ays/pages/LoginPOM.java

This file was deleted.

54 changes: 54 additions & 0 deletions src/test/java/org/ays/pages/LoginPage.java
Original file line number Diff line number Diff line change
@@ -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;


}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/org/ays/runners/RunnerForSmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import io.cucumber.testng.CucumberOptions;

@CucumberOptions(tags = "@Smoke")
@CucumberOptions(
plugin = {"pretty"},
tags = "@Smoke", publish = true
)
public class RunnerForSmokeTest extends AysAbstractTestNGCucumberTests {
}
Loading

0 comments on commit c6c1b4f

Please sign in to comment.