diff --git a/.gitignore b/.gitignore index e37ec00..923063f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,73 +1,187 @@ +# ========================= +# System Files +# ========================= +.DS_Store +Thumbs.db +$RECYCLE.BIN/ +Desktop.ini + +# macOS +.AppleDouble +.LSOverride + +# Windows +*.bak +*.swp +*.swo + +# Linux +*~ + +# ========================= +# Logs +# ========================= +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + +# ========================= +# Environment Variables +# ========================= +.env +.env.local +.env.*.local +*.env + +# ========================= +# Package Managers and Dependencies +# ========================= +node_modules/ +package-lock.json +yarn.lock +pnpm-lock.yaml +.npm/ + +# ========================= +# Build Directories (Common for Java, JavaScript, etc.) +# ========================= +dist/ +build/ +target/ +out/ +tmp/ +logs/ + +# ========================= +# IDEs and Editors +# ========================= + # IntelliJ IDEA .idea/ *.iws *.iml *.ipr -out/ -# VS Code -.vscode/ +# NetBeans +nbproject/private/ -# Eclipse IDE +# Eclipse .project .classpath .settings/ -bin/ -# NetBeans IDE -nbproject/private/ -nbbuild/ -dist/ -nbdist/ -.nb-gradle/ +# VSCode +.vscode/ +.history/ -# Java +# ========================= +# Java (Maven, Gradle, and General) +# ========================= *.class *.jar *.war *.ear +*.jcache +*.jfr -# NodeJS -node_modules/ -npm-debug.log -yarn-error.log - -# Gradle -.gradle/ -build/ -!gradle-wrapper.jar - -# Maven -target/ +# Maven-specific pom.xml.tag pom.xml.releaseBackup pom.xml.versionsBackup pom.xml.next release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties -# Allure Report -allure-results/ -allure-report/ +# Gradle-specific +/gradle/ +.gradle/ +gradle-app.setting +gradle/wrapper/gradle-wrapper.properties +gradle/wrapper/gradle-wrapper.jar -# TestNG -test-output/ +# ========================= +# JavaScript and Frameworks (React, Vite, etc.) +# ========================= +*.js +*.jsx +*.ts +*.tsx +*.map + +# Babel +.babelrc +.babelrc.js +.babelrc.json +.babelignore +babel.config.js +babel.config.json + +# Vite +.vite/ -# Cucumber -cucumber-report/ +# Webpack and Parcel (optional, depending on your bundler) +.cache/ +.parcel-cache/ +*.webpack/ -# Selenium +# Tailwind CSS +tailwind.config.js +tailwind.config.ts + +# ========================= +# Selenium and WebdriverIO +# ========================= +selenium-server-standalone-*.jar selenium.log +webdriverio-report/ -# General -.DS_Store -Thumbs.db -*.swp -*.swo -*.bak -*.tmp -*.log -*.out +# ========================= +# TestNG, Cucumber, and Testing Tools +# ========================= +test-output/ +.cucumber/ +rerun.txt -# Temporary files -tmp/ -temp/ +# ========================= +# Jenkins +# ========================= +*.lastStable +*.lastSuccessful +*.lastUnstable +*.lastUnsuccessful +*.buildNumbers +*.fingerprint +*.jenkins/ +workspace/ +builds/ +config.xml +jobs/*/config.xml + +# ========================= +# Allure and Extent Report +# ========================= +allure-results/ +allure-report/ +extent-report/ +extent-results/ + +# ========================= +# Coverage Reports +# ========================= +coverage/ +*.lcov +.nyc_output/ + +# ========================= +# Miscellaneous +# ========================= +# Ignore private files +secrets.yml +secret-key.txt + +# Temporary files and backups +*.tmp diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..ccb7cd4 --- /dev/null +++ b/build.gradle @@ -0,0 +1,34 @@ +plugins { + id 'java' +} + +group = 'SeleniumWebdriver' +version = '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +def allureVersion = "2.24.0" +def aspectJVersion = "1.9.20.1" + +configurations { + agent { + canBeResolved = true + canBeConsumed = true + } +} + +dependencies { + testImplementation 'org.seleniumhq.selenium:selenium-java:4.23.1' + testImplementation 'org.testng:testng:7.10.2' + testImplementation 'com.google.code.gson:gson:2.11.0' + testImplementation platform("io.qameta.allure:allure-bom:$allureVersion") + testImplementation "io.qameta.allure:allure-testng" + agent "org.aspectj:aspectjweaver:$aspectJVersion" +} + +test { + useTestNG() + jvmArgs = ["-javaagent:${configurations.agent.singleFile}"] +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..4032d24 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue Aug 13 11:40:03 BDT 2024 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/test/java/data/credentials.json b/src/test/java/data/credentials.json new file mode 100644 index 0000000..c7840fb --- /dev/null +++ b/src/test/java/data/credentials.json @@ -0,0 +1,16 @@ +{ + + "URLs": { + "BaseURL": "https://the-internet.herokuapp.com/", + "Description": "The URL of the target application" + }, + + "Users": { + "User01": { + "UserName": "admin", + "UserPassword": "admin" + }, + "User02": {} + } + +} diff --git a/src/test/java/data/timeouts.json b/src/test/java/data/timeouts.json new file mode 100644 index 0000000..8a398c5 --- /dev/null +++ b/src/test/java/data/timeouts.json @@ -0,0 +1,9 @@ +{ + + "Timeouts": { + "Minimum": 5000, + "Medium": 30000, + "Maximum": 60000 + } + +} diff --git a/src/test/java/framework/BaseElement.java b/src/test/java/framework/BaseElement.java new file mode 100644 index 0000000..c8b4520 --- /dev/null +++ b/src/test/java/framework/BaseElement.java @@ -0,0 +1,87 @@ +package framework; + +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.NoAlertPresentException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; + +import java.util.List; + +import static framework.DriverTools.*; + +public class BaseElement { + private final By EL_LOCATOR; + private final String EL_NAME; + + public BaseElement(By elLocator, String elName) { + this.EL_LOCATOR = elLocator; + this.EL_NAME = elName; + } + + public WebElement getElement() { + return getDriver().findElement(this.EL_LOCATOR); + } + + public List getElements() { + return getDriver().findElements(this.EL_LOCATOR); + } + + public String getElementName() { + return this.EL_NAME; + } + + public String elementText() { + return getElement().getText(); + } + + public BaseElement doClick() { + getActions().click(getElement()).perform(); + return this; + } + + public BaseElement clearAndType(String text) { + getActions().click().perform(); + getActions().keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL); + getActions().sendKeys(Keys.DELETE).perform(); + getActions().sendKeys(this.getElement(), text).perform(); + return this; + } + + public Boolean isVisible(Integer timeout) { + getXWait(timeout).until(ExpectedConditions.visibilityOf(getElement())); + return getElement().isDisplayed(); + } + +// public BaseElement scrollToElement() { +// getActions().scrollToElement(getElement()); +// return this; +// } + + public BaseElement scrollToElement() { + String jsScroll = "arguments[0].scrollIntoView()"; + getJS().executeScript(jsScroll, getElement()); + return this; + } + + public Boolean isAlertOpen(Integer timeout) { + try { + getXWait(timeout).until(ExpectedConditions.alertIsPresent()); + return true; + } catch (NoAlertPresentException e) { + System.out.println(e.getMessage()); + return false; + } + } + + public BaseElement selectFromDropdown(Integer item) { + new Select(this.getElement()).selectByIndex(item); + return this; + } + + public BaseElement hoverOnIt() { + getActions().moveToElement(getElement()); + return this; + } +} diff --git a/src/test/java/framework/BasePage.java b/src/test/java/framework/BasePage.java new file mode 100644 index 0000000..a1db3d1 --- /dev/null +++ b/src/test/java/framework/BasePage.java @@ -0,0 +1,90 @@ +package framework; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.NotFoundException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import static framework.DriverTools.*; + +public class BasePage { + private final String PAGE_URL; + private final By PAGE_IDENTIFIER; + private final String PAGE_NAME; + + public BasePage(String PAGE_URL, By PAGE_IDENTIFIER, String PAGE_NAME) { + this.PAGE_URL = PAGE_URL; + this.PAGE_IDENTIFIER = PAGE_IDENTIFIER; + this.PAGE_NAME = PAGE_NAME; + } + + public String getPAGE_URL() { + return PAGE_URL; + } + + public By getPAGE_IDENTIFIER() { + return PAGE_IDENTIFIER; + } + + public String getPAGE_NAME() { + return PAGE_NAME; + } + + public String pageTitle() { + return getDriver().getTitle(); + } + + public Boolean isPageOpen() { + return getDriver().getCurrentUrl().equals(getPAGE_URL()); + } + + public Boolean isPageLoaded(Integer timeout) { + try { + getXWait(timeout).until(ExpectedConditions.presenceOfElementLocated(getPAGE_IDENTIFIER())); + return true; + } catch(NotFoundException e) { + System.out.println(e.getMessage()); + return false; + } + } + + public BaseElement getByText(String text) { + return new BaseElement( + By.xpath("//a[contains(text(),'"+text+"')]"), + text+" element" + ); + } + + public BasePage navigateBack() { + getDriver().navigate().back(); + return this; + } + + public Alert selectOpenAlert() { + Alert alert = getDriver().switchTo().alert(); + return alert; + } + + public BasePage getIFrame() { + getDriver().switchTo().frame("mce_0_ifr"); + return this; + } + + public BasePage returnToDefaultContent() { + getDriver().switchTo().defaultContent(); + return this; + } + + public BasePage openInNewTab(By link) { + String jsNewTab = "window.open(arguments[0], '_blank')"; + getJS().executeScript(jsNewTab, link); + return this; + } + + public BasePage scrollBackToTop() { + String jsToTop = "window.scrollTo(0, 0)"; + getJS().executeScript(jsToTop); + return this; + } +} diff --git a/src/test/java/framework/BaseTest.java b/src/test/java/framework/BaseTest.java new file mode 100644 index 0000000..df95aa0 --- /dev/null +++ b/src/test/java/framework/BaseTest.java @@ -0,0 +1,37 @@ +package framework; + +import framework.utils.DataProcessor; +import framework.utils.Pages; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.testng.Assert; +import org.testng.annotations.*; + +import java.io.File; + +import static framework.DriverTools.*; + +public class BaseTest { + public DataProcessor getDataProcessor() { + return new DataProcessor(); + } + + public Pages getPages() { + return new Pages(); + } + + @BeforeMethod + protected void setUp() { + new DriverTools("Edge"); + getDriver().manage().window().setSize(new Dimension(1440, 900)); + getDriver().get(getPages().getHomePage().getPAGE_URL()); + Assert.assertTrue(getPages().getHomePage().isPageOpen(), "The home page is not open"); + Assert.assertTrue(getPages().getHomePage().isPageLoaded(getDataProcessor().getTimeouts().getMedium()), "The page is not loaded"); + } + + @AfterMethod + protected void tearDown() { + getDriver().close(); + } +} diff --git a/src/test/java/framework/DriverTools.java b/src/test/java/framework/DriverTools.java new file mode 100644 index 0000000..6694996 --- /dev/null +++ b/src/test/java/framework/DriverTools.java @@ -0,0 +1,61 @@ +package framework; + +import org.openqa.selenium.*; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.edge.EdgeDriver; +import org.openqa.selenium.edge.EdgeOptions; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.firefox.FirefoxOptions; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.io.File; +import java.io.IOException; +import java.time.Duration; +import java.util.Locale; + +public class DriverTools { + private static WebDriver driver; + + public DriverTools(String driverTitle) { + this.setDriver(driverTitle); + } + + private void setDriver(String driverTitle) { + switch (driverTitle.toLowerCase(Locale.ROOT)) { + case "chrome" -> driver = new ChromeDriver(); + case "firefox" -> driver = new FirefoxDriver(); + case "edge" -> driver = new EdgeDriver(); + case "chrome_hl" -> { + ChromeOptions options = new ChromeOptions().addArguments("--headless"); + driver = new ChromeDriver(options); + } + case "firefox_hl" -> { + FirefoxOptions options = new FirefoxOptions().addArguments("--headless"); + driver = new FirefoxDriver(options); + } + case "edge_hl" -> { + EdgeOptions options = new EdgeOptions().addArguments("--headless"); + driver = new EdgeDriver(options); + } + default -> throw new InvalidArgumentException("Invalid driver request"); + } + } + + public static WebDriver getDriver() { + return driver; + } + + public static WebDriverWait getXWait(Integer timeout) { + return new WebDriverWait(getDriver(), Duration.ofMillis(timeout)); + } + + public static Actions getActions() { + return new Actions(getDriver()); + } + + public static JavascriptExecutor getJS() { + return (JavascriptExecutor) getDriver(); + } +} diff --git a/src/test/java/framework/utils/DataProcessor.java b/src/test/java/framework/utils/DataProcessor.java new file mode 100644 index 0000000..136936a --- /dev/null +++ b/src/test/java/framework/utils/DataProcessor.java @@ -0,0 +1,45 @@ +package framework.utils; + +import com.google.gson.Gson; + +import java.io.*; + +public class DataProcessor { + private final Gson GSON; + private final File CREDENTIALS; + private final File TIMEOUTS; + + public DataProcessor() { + this.GSON = new Gson(); + this.CREDENTIALS = new File("./src/test/java/data/credentials.json"); + this.TIMEOUTS = new File("./src/test/java/data/timeouts.json"); + } + + public ProcessedData.URLs getURLs() { + try (Reader reader = new FileReader(this.CREDENTIALS)) { + return GSON.fromJson(reader, ProcessedData.URLs.class); + } catch (IOException e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + return null; + } + } + + public ProcessedData.Users getUsers() { + try(Reader reader = new FileReader(this.CREDENTIALS)) { + return GSON.fromJson(reader, ProcessedData.Users.class); + } catch (IOException e) { + System.out.println(e.getMessage()); + throw new RuntimeException(e); + } + } + + public ProcessedData.Timeouts getTimeouts() { + try(Reader reader = new FileReader(this.TIMEOUTS)) { + return GSON.fromJson(reader, ProcessedData.Timeouts.class); + } catch (IOException e) { + System.out.println(e.getMessage()); + throw new RuntimeException(e); + } + } +} diff --git a/src/test/java/framework/utils/Pages.java b/src/test/java/framework/utils/Pages.java new file mode 100644 index 0000000..94c7b83 --- /dev/null +++ b/src/test/java/framework/utils/Pages.java @@ -0,0 +1,68 @@ +package framework.utils; + +import org.openqa.selenium.By; +import pages.*; + +public class Pages { + private final String BASE_URL; + + public Pages() { + this.BASE_URL = new DataProcessor().getURLs().getBaseURL(); + } + + public HomePage getHomePage() { + return new HomePage( + this.BASE_URL, + By.xpath("//h1[@class='heading']"), + "Home page" + ); + } + + public ABTestingPage getABTestingPage() { + return new ABTestingPage( + this.BASE_URL+"abtest", + By.xpath("//div[@class='example']"), + "AB Testing page" + ); + } + + public AddRemoveElementsPage getAddRemoveElementsPage() { + return new AddRemoveElementsPage( + this.BASE_URL+"add_remove_elements/", + By.xpath("//h3[normalize-space()='Add/Remove Elements']"), + "Add Remove Elements page" + ); + } + + public DropdownPage getDropdownPage() { + return new DropdownPage( + BASE_URL+"dropdown", + By.xpath("//h3[text()='Dropdown List']"), + "Dropdown List page" + ); + } + + public JSAlertPage getJSAlertPage() { + return new JSAlertPage( + BASE_URL+"javascript_alerts", + By.xpath("//h3[text()='JavaScript Alerts']"), + "JS Alert page" + ); + } + + public FramesPage getFramesPage() { + return new FramesPage( + BASE_URL+"frames", + By.xpath("//h3[normalize-space()='Frames']"), + "Frames page" + ); + } + + public IFramePage getIFramePage() { + return new IFramePage( + BASE_URL+"iframe", + By.xpath("//h3[contains(normalize-space(),'An iFrame containing')]"), + "iFrame page" + ); + } +} diff --git a/src/test/java/framework/utils/ProcessedData.java b/src/test/java/framework/utils/ProcessedData.java new file mode 100644 index 0000000..1f4ffb0 --- /dev/null +++ b/src/test/java/framework/utils/ProcessedData.java @@ -0,0 +1,62 @@ +package framework.utils; + +import java.util.Map; + +public class ProcessedData { + + // URLs + public static class URLs { + private Map URLs; + + public String getBaseURL() { + return URLs.get("BaseURL"); + } + + public String getDescription() { + return URLs.get("Description"); + } + } + + // Users + public static class Users { + private Map Users; + + public User getUser01() { + return Users.get("User01"); + } + + public User getUser02() { + return Users.get("User02"); + } + + public static class User { + private String UserName; + private String UserPassword; + + public String getUserName() { + return UserName; + } + + public String getUserPassword() { + return UserPassword; + } + } + } + + // Timeouts + public static class Timeouts { + private Map Timeouts; + + public Integer getMinimum() { + return Timeouts.get("Minimum"); + } + + public Integer getMedium() { + return Timeouts.get("Medium"); + } + + public Integer getMaximum() { + return Timeouts.get("Maximum"); + } + } +} diff --git a/src/test/java/pages/ABTestingPage.java b/src/test/java/pages/ABTestingPage.java new file mode 100644 index 0000000..88749e8 --- /dev/null +++ b/src/test/java/pages/ABTestingPage.java @@ -0,0 +1,22 @@ +package pages; + +import framework.BaseElement; +import framework.BasePage; +import org.openqa.selenium.By; + +public class ABTestingPage extends BasePage { + private final BaseElement PARAGRAPH; + + public ABTestingPage(String PAGE_URL, By PAGE_IDENTIFIER, String PAGE_NAME) { + super(PAGE_URL, PAGE_IDENTIFIER, PAGE_NAME); + this.PARAGRAPH = new BaseElement( + By.xpath("//div[@class='example']/p"), + "Paragraph element" + ); + } + + public Boolean hasTargetText() { + String paragraphText = this.PARAGRAPH.elementText(); + return paragraphText.contains("split testing"); + } +} diff --git a/src/test/java/pages/AddRemoveElementsPage.java b/src/test/java/pages/AddRemoveElementsPage.java new file mode 100644 index 0000000..8b69712 --- /dev/null +++ b/src/test/java/pages/AddRemoveElementsPage.java @@ -0,0 +1,10 @@ +package pages; + +import framework.BasePage; +import org.openqa.selenium.By; + +public class AddRemoveElementsPage extends BasePage { + public AddRemoveElementsPage(String PAGE_URL, By PAGE_IDENTIFIER, String PAGE_NAME) { + super(PAGE_URL, PAGE_IDENTIFIER, PAGE_NAME); + } +} diff --git a/src/test/java/pages/DropdownPage.java b/src/test/java/pages/DropdownPage.java new file mode 100644 index 0000000..c0ae1de --- /dev/null +++ b/src/test/java/pages/DropdownPage.java @@ -0,0 +1,23 @@ +package pages; + +import framework.BaseElement; +import framework.BasePage; +import org.openqa.selenium.By; + +public class DropdownPage extends BasePage { + private BaseElement dropdownMenu; + + public DropdownPage(String PAGE_URL, By PAGE_IDENTIFIER, String PAGE_NAME) { + super(PAGE_URL, PAGE_IDENTIFIER, PAGE_NAME); + + this.dropdownMenu = new BaseElement( + By.xpath("//select[@id='dropdown']"), + "Dropdown menu" + ); + } + + public DropdownPage selectOption2() { + this.dropdownMenu.selectFromDropdown(1); + return this; + } +} diff --git a/src/test/java/pages/FramesPage.java b/src/test/java/pages/FramesPage.java new file mode 100644 index 0000000..311360f --- /dev/null +++ b/src/test/java/pages/FramesPage.java @@ -0,0 +1,23 @@ +package pages; + +import framework.BaseElement; +import framework.BasePage; +import org.openqa.selenium.By; + +public class FramesPage extends BasePage { + private BaseElement iFrameLink; + + public FramesPage(String PAGE_URL, By PAGE_IDENTIFIER, String PAGE_NAME) { + super(PAGE_URL, PAGE_IDENTIFIER, PAGE_NAME); + + this.iFrameLink = new BaseElement( + By.cssSelector("a[href='/iframe']"), + "IFrame link" + ); + } + + public FramesPage clickIFrameLink() { + this.iFrameLink.doClick(); + return this; + } +} diff --git a/src/test/java/pages/HomePage.java b/src/test/java/pages/HomePage.java new file mode 100644 index 0000000..2cf0ff2 --- /dev/null +++ b/src/test/java/pages/HomePage.java @@ -0,0 +1,242 @@ +package pages; + +import framework.BaseElement; +import framework.BasePage; +import org.openqa.selenium.By; + +public class HomePage extends BasePage { + private BaseElement typosLink; + + public HomePage(String PAGE_URL, By PAGE_IDENTIFIER, String PAGE_NAME) { + super(PAGE_URL, PAGE_IDENTIFIER, PAGE_NAME); + + this.typosLink = new BaseElement( + By.xpath("//a[normalize-space()='Typos']"), + "Typos link" + ); + } + + public BaseElement getTyposLink() { + return this.typosLink; + } + + public HomePage openABTestingPage() { + this.getByText("A/B Testing").doClick(); + return this; + } + + public HomePage openAddRemoveElementsPage() { + this.getByText("Add/Remove Elements").doClick(); + return this; + } + + public HomePage openBasicAuthPage() { + this.getByText("Basic Auth").doClick(); + return this; + } + + public HomePage openBrokenImagesPage() { + this.getByText("Broken Images").doClick(); + return this; + } + + public HomePage openChallengingDOMPage() { + this.getByText("Challenging DOM").doClick(); + return this; + } + + public HomePage openCheckboxesPage() { + this.getByText("Checkboxes").doClick(); + return this; + } + + public HomePage openContextMenuPage() { + this.getByText("Context Menu").doClick(); + return this; + } + + public HomePage openDigestAuthPage() { + this.getByText("Digest Authentication").doClick(); + return this; + } + + public HomePage openDisappearingElementsPage() { + this.getByText("Disappearing Elements").doClick(); + return this; + } + + public HomePage openDragAndDropPage() { + this.getByText("Drag and Drop").doClick(); + return this; + } + + public HomePage openDropdownPage() { + this.getByText("Dropdown").doClick(); + return this; + } + + public HomePage openDynamicContentPage() { + this.getByText("Dynamic Content").doClick(); + return this; + } + + public HomePage openDynamicControlsPage() { + this.getByText("Dynamic Controls").doClick(); + return this; + } + + public HomePage openDynamicLoadingPage() { + this.getByText("Dynamic Loading").doClick(); + return this; + } + + public HomePage openEntryAdPage() { + this.getByText("Entry Ad").doClick(); + return this; + } + + public HomePage openExitIntentPage() { + this.getByText("Exit Intent").doClick(); + return this; + } + + public HomePage openFileDownloadPage() { + this.getByText("File Download").doClick(); + return this; + } + + public HomePage openFileUploadPage() { + this.getByText("File Upload").doClick(); + return this; + } + + public HomePage openForgotPasswordPage() { + this.getByText("Forgot Password").doClick(); + return this; + } + + public HomePage openFormAuthenticationPage() { + this.getByText("Form Authentication").doClick(); + return this; + } + + public HomePage openFramesPage() { + this.getByText("Frames").doClick(); + return this; + } + + public HomePage openIFramePage() { + this.getByText("iFrame").doClick(); + return this; + } + + public HomePage openGeolocationPage() { + this.getByText("Geolocation").doClick(); + return this; + } + + public HomePage openHorizontalSliderPage() { + this.getByText("Horizontal Slider").doClick(); + return this; + } + + public HomePage openHoversPage() { + this.getByText("Hovers").doClick(); + return this; + } + + public HomePage openInfiniteScrollPage() { + this.getByText("Infinite Scroll").doClick(); + return this; + } + + public HomePage openInputsPage() { + this.getByText("Inputs").doClick(); + return this; + } + + public HomePage openJQueryUIMenusPage() { + this.getByText("JQuery UI Menus").doClick(); + return this; + } + + public HomePage openJSAlertsPage() { + this.getByText("JavaScript Alerts").doClick(); + return this; + } + + public HomePage openJSOnloadEventErrorPage() { + this.getByText("JavaScript onload event error").doClick(); + return this; + } + + public HomePage openKeyPressesPage() { + this.getByText("Key Presses").doClick(); + return this; + } + + public HomePage openLargeAndDeepDOMPage() { + this.getByText("Large & Deep DOM").doClick(); + return this; + } + + public HomePage openMultipleWindowsPage() { + this.getByText("Multiple Windows").doClick(); + return this; + } + + public HomePage openNestedFramesPage() { + this.getByText("Nested Frames").doClick(); + return this; + } + + public HomePage openNotificationMessagesPage() { + this.getByText("Notification Messages").doClick(); + return this; + } + + public HomePage openRedirectLinkPage() { + this.getByText("Redirect Link").doClick(); + return this; + } + + public HomePage openSecureFileDownloadPage() { + this.getByText("Secure File Download").doClick(); + return this; + } + + public HomePage openShadowDOMPage() { + this.getByText("Shadow DOM").doClick(); + return this; + } + + public HomePage openShiftingContentPage() { + this.getByText("Shifting Content").doClick(); + return this; + } + + public HomePage openSlowResourcesPage() { + this.getByText("Slow Resources").doClick(); + return this; + } + + public HomePage openSortableDataTablesPage() { + this.getByText("Sortable Data Tables").doClick(); + return this; + } + + public HomePage openStatusCodesPage() { + this.getByText("Status Codes").doClick(); + return this; + } + + public HomePage openTyposPage() { + this.getByText("Typos").doClick(); + return this; + } + + public HomePage openWYSIWYGEditorPage() { + this.getByText("WYSIWYG Editor").doClick(); + return this; + } +} diff --git a/src/test/java/pages/IFramePage.java b/src/test/java/pages/IFramePage.java new file mode 100644 index 0000000..78021d0 --- /dev/null +++ b/src/test/java/pages/IFramePage.java @@ -0,0 +1,22 @@ +package pages; + +import framework.BaseElement; +import framework.BasePage; +import org.openqa.selenium.By; + +public class IFramePage extends BasePage { + private BaseElement iFrameTextbox; + + public IFramePage(String PAGE_URL, By PAGE_IDENTIFIER, String PAGE_NAME) { + super(PAGE_URL, PAGE_IDENTIFIER, PAGE_NAME); + + this.iFrameTextbox = new BaseElement( + By.xpath("//body[@id=\"tinymce\"]/p"), + "" + ); + } + + public BaseElement getiFrameTextbox() { + return this.iFrameTextbox; + } +} diff --git a/src/test/java/pages/JSAlertPage.java b/src/test/java/pages/JSAlertPage.java new file mode 100644 index 0000000..435d2ff --- /dev/null +++ b/src/test/java/pages/JSAlertPage.java @@ -0,0 +1,32 @@ +package pages; + +import framework.BaseElement; +import framework.BasePage; +import org.openqa.selenium.By; + +public class JSAlertPage extends BasePage { + private BaseElement jsAlertBtn; + private BaseElement resultElement; + + public JSAlertPage(String PAGE_URL, By PAGE_IDENTIFIER, String PAGE_NAME) { + super(PAGE_URL, PAGE_IDENTIFIER, PAGE_NAME); + + this.jsAlertBtn = new BaseElement( + By.xpath("//button[@onclick='jsAlert()']"), + "JS Alert button" + ); + this.resultElement = new BaseElement( + By.xpath("//p[@id='result']"), + "Action result paragraph" + ); + } + + public JSAlertPage clickJSAlertBtn() { + this.jsAlertBtn.doClick(); + return this; + } + + public String getActionResultText() { + return this.resultElement.elementText(); + } +} diff --git a/src/test/java/tests/ABTestingPageTest.java b/src/test/java/tests/ABTestingPageTest.java new file mode 100644 index 0000000..876661a --- /dev/null +++ b/src/test/java/tests/ABTestingPageTest.java @@ -0,0 +1,16 @@ +package tests; + +import org.testng.Assert; +import org.testng.annotations.*; + +public class ABTestingPageTest extends HomePageTest { + @Test( + description = "Check if the word 'split testing' exists in the paragraph", + groups = {"ABTestingPage"}, + dependsOnMethods = {"testOpenABTestingPage"}, + priority = 1 + ) + void testTargetTextExistence() { + Assert.assertTrue(getPages().getABTestingPage().hasTargetText()); + } +} diff --git a/src/test/java/tests/DropdownPageTest.java b/src/test/java/tests/DropdownPageTest.java new file mode 100644 index 0000000..0c8d1cf --- /dev/null +++ b/src/test/java/tests/DropdownPageTest.java @@ -0,0 +1,16 @@ +package tests; + +import org.testng.annotations.Test; + +public class DropdownPageTest extends HomePageTest { + + @Test( + description = "Click an option from the dropdown menu", + groups = "DropdownPage", + dependsOnMethods = "testOpenDropdownPage", + priority = 1 + ) + void testClickAnOption() { + getPages().getDropdownPage().selectOption2(); + } +} diff --git a/src/test/java/tests/FramesPageTest.java b/src/test/java/tests/FramesPageTest.java new file mode 100644 index 0000000..c182ba9 --- /dev/null +++ b/src/test/java/tests/FramesPageTest.java @@ -0,0 +1,18 @@ +package tests; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class FramesPageTest extends HomePageTest{ + @Test( + description = "Click iFrame page link & open the page", + groups = "FramesPage", + dependsOnMethods = "testOpenFramsPage", + priority = 1 + ) + void clickIFramePageLink() { + getPages().getFramesPage().clickIFrameLink(); + Assert.assertTrue(getPages().getIFramePage().isPageOpen(), "The page is not open"); + Assert.assertTrue(getPages().getIFramePage().isPageLoaded(getDataProcessor().getTimeouts().getMedium())); + } +} diff --git a/src/test/java/tests/HomePageTest.java b/src/test/java/tests/HomePageTest.java new file mode 100644 index 0000000..35b81b0 --- /dev/null +++ b/src/test/java/tests/HomePageTest.java @@ -0,0 +1,65 @@ +package tests; + +import framework.BaseTest; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class HomePageTest extends BaseTest { + @Test( + description = "Open AB Testing page", + groups = {"ABTestingPage"}, + priority = 1, + enabled = true + ) + void testOpenABTestingPage() { + getPages().getHomePage().openABTestingPage(); + Assert.assertTrue(getPages().getABTestingPage().isPageOpen(), "The page is not open"); + Assert.assertTrue(getPages().getABTestingPage().isPageLoaded(getDataProcessor().getTimeouts().getMedium())); + } + + @Test( + description = "Open Dropdown page", + groups = "DropdownPage", + priority = 2, + enabled = true + ) + void testOpenDropdownPage() { + getPages().getHomePage().openDropdownPage(); + Assert.assertTrue(getPages().getDropdownPage().isPageOpen(), "The page is not open"); + Assert.assertTrue(getPages().getDropdownPage().isPageLoaded(getDataProcessor().getTimeouts().getMedium())); + } + + @Test( + description = "Open JS Alert page", + groups = "JSAlertPage", + priority = 3, + enabled = true + ) + void testOpenJSAlertPage() { + getPages().getHomePage().openJSAlertsPage(); + Assert.assertTrue(getPages().getJSAlertPage().isPageOpen(), "The page is not open"); + Assert.assertTrue(getPages().getJSAlertPage().isPageLoaded(getDataProcessor().getTimeouts().getMedium())); + } + + @Test( + description = "Open Frames page", + groups = "FramesPage", + priority = 4, + enabled = true + ) + void testOpenFramsPage() { + getPages().getHomePage().openFramesPage(); + Assert.assertTrue(getPages().getFramesPage().isPageOpen(), "The page is not open"); + Assert.assertTrue(getPages().getFramesPage().isPageLoaded(getDataProcessor().getTimeouts().getMedium())); + } + + @Test( + description = "Scroll to 'Typos' link", + groups = "", + priority = 5, + enabled = true + ) + void testScrollToTyposLink() { + getPages().getHomePage().getTyposLink().scrollToElement(); + } +} diff --git a/src/test/java/tests/IFramePageTest.java b/src/test/java/tests/IFramePageTest.java new file mode 100644 index 0000000..4661cdb --- /dev/null +++ b/src/test/java/tests/IFramePageTest.java @@ -0,0 +1,18 @@ +package tests; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class IFramePageTest extends FramesPageTest{ + @Test( + description = "Test actions in the iFrame", + groups = "FramesPage", + dependsOnMethods = "clickIFramePageLink", + priority = 1 + ) + void testIFrame() { + getPages().getIFramePage().getIFrame(); + Assert.assertTrue(getPages().getIFramePage().getiFrameTextbox().isVisible(getDataProcessor().getTimeouts().getMinimum()), "The textbox is not available"); + getPages().getIFramePage().getiFrameTextbox().clearAndType("Hello!"); + } +} diff --git a/src/test/java/tests/JSAlertPageTest.java b/src/test/java/tests/JSAlertPageTest.java new file mode 100644 index 0000000..bb6cf09 --- /dev/null +++ b/src/test/java/tests/JSAlertPageTest.java @@ -0,0 +1,18 @@ +package tests; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class JSAlertPageTest extends HomePageTest{ + @Test( + description = "Click & accept JS Alert", + groups = "JSAlertPage", + dependsOnMethods = "testOpenJSAlertPage", + priority = 1 + ) + void testAcceptAlert() { + getPages().getJSAlertPage().clickJSAlertBtn(); + getPages().getJSAlertPage().selectOpenAlert().accept(); + Assert.assertEquals(getPages().getJSAlertPage().getActionResultText(), "You successfully clicked an alert", "The alert is not accepted"); + } +} diff --git a/src/test/resources/allure.properties b/src/test/resources/allure.properties new file mode 100644 index 0000000..11d7624 --- /dev/null +++ b/src/test/resources/allure.properties @@ -0,0 +1,2 @@ + +allure.results.directory=target/allure-results \ No newline at end of file diff --git a/src/test/resources/testng.xml b/src/test/resources/testng.xml new file mode 100644 index 0000000..ed6dbec --- /dev/null +++ b/src/test/resources/testng.xml @@ -0,0 +1,10 @@ + + + + + + + + + +