Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stabiliced branch #3

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
src/test/resources/config.properties
target/
build
out
Expand Down
35 changes: 35 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pipeline {
agent any
environment {
CREDENTIALS = credentials('serenityCredentials')
}
tools {
maven 'Maven 3.8.1'
}
stages {
stage('Clone repository') {
steps {
git url: 'https://github.com/rperdigonTriskell/serenityBDD-triskell.git', credentialsId: 'gitCredentials'
}
}
stage('Build and execute tests') {
steps {
withMaven(maven: 'Maven 3.8.1') {
sh 'mvn clean verify'
}
}
}
}
post {
always {
publishHTML(target: [
reportName: 'Serenity Report',
reportDir: 'target/site/serenity',
reportFiles: 'index.html',
keepAll: true,
alwaysLinkToLastBuild: true
])
junit '**/target/surefire-reports/*.xml'
}
}
}
21 changes: 21 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Security Policy

## Supported Versions

Use this section to tell people about which versions of your project are
currently being supported with security updates.

| Version | Supported |
| ------- | ------------------ |
| 5.1.x | :white_check_mark: |
| 5.0.x | :x: |
| 4.0.x | :white_check_mark: |
| < 4.0 | :x: |

## Reporting a Vulnerability

Use this section to tell people how to report a vulnerability.

Tell them where to go, how often they can expect to get an update on a
reported vulnerability, what to expect if the vulnerability is accepted or
declined, etc.
29 changes: 18 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,66 +19,67 @@
<tags></tags>
<webdriver.base.url></webdriver.base.url>
</properties>

<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>secretsmanager</artifactId>
<version>2.20.6</version>
</dependency>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-screenplay</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-screenplay-webdriver</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-ensure</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit-platform-suite.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>${cucumber-junit-platform-engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>${junit-platform-suite.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-vintage-engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-vintage-engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
Expand All @@ -89,9 +90,14 @@
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand All @@ -103,6 +109,7 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<configuration>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/starter/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package starter;

public class Constants {
public final static String LOGIN = "login";
public final static String HOME_PAGE = "home page";
}
29 changes: 29 additions & 0 deletions src/main/java/starter/selectors/factory/AbstractPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package starter.selectors.factory;

import org.openqa.selenium.By;

import java.util.HashMap;
import java.util.Map;

public abstract class AbstractPage implements SelectorFactory {

/**
* Map to hold selector names and their corresponding By objects.
*/
public Map<String, By> mapSelectors = new HashMap<String, By>();

/**
* Returns a map of selector mappings.
* @return Map of selector mappings.
*/
public abstract Map<String, By> mapSelectors();

/**
* Retrieves the By object for the given selector name.
* @param selector the name of the selector.
* @return the By object corresponding to the selector name.
*/
public By getSelector(String selector) {
return mapSelectors().get(selector.toLowerCase());
}
}
122 changes: 122 additions & 0 deletions src/main/java/starter/selectors/factory/PageFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package starter.selectors.factory;

import net.serenitybdd.core.pages.PageObject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import starter.selectors.pages.*;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

import static org.openqa.selenium.support.PageFactory.initElements;
import static starter.Constants.*;

public class PageFactory extends PageObject {

/**
* Map associating page names with their corresponding instances.
*/
private static final Map<String, AbstractPage> map = new HashMap<String, AbstractPage>() {{
put(LOGIN, initElements(getDriverStatic(), LoginPage.class));
put(HOME_PAGE, initElements(getDriverStatic(), HomePage.class));
}};

/**
* The currently selected page.
*/
private static AbstractPage currentPage;

/**
* Gets the current page that is selected.
*
* @return The currently selected page.
*/
public static AbstractPage getCurrentPage() {
return currentPage;
}

/**
* Gets the name of the current page that is selected.
*
* @return The name of the currently selected page.
*/
public static String getCurrentPageName() {
for (Map.Entry<String, AbstractPage> entry : map.entrySet()) {
if (entry.getValue().equals(currentPage)) {
return entry.getKey();
}
}
return null;
}

/**
* Sets the current page based on the provided page name.
*
* @param page Name of the page to set as the current page.
*/
public static void setCurrentPage(String page) {
currentPage = map.get(page);
}

/**
* Gets a static instance of the WebDriver.
*
* @return Static instance of WebDriver.
*/
public static WebDriver getDriverStatic() {
return new PageFactory().getDriver();
}

/**
* Gets a By object from a WebElement using the information from its toString().
*
* @param element WebElement from which to obtain the By selector.
* @return By object corresponding to the WebElement's selector.
* @throws IllegalArgumentException If the toString() format is not recognized.
*/
public static By getWebElementSelector(WebElement element) {
// Get the string representation of the WebElement
String elementToString = element.toString();
String[] parts = elementToString.split(" -> ");

if (parts.length > 1) {
// Extract information about the WebElement's selector
String selectorInfo = parts[1].replace("]", "");
String[] selectorParts = selectorInfo.split(": ");

if (selectorParts.length == 2) {
// Get selector type and value, and return the corresponding By object
String selectorType = selectorParts[0].trim();
String selectorValue = selectorParts[1].trim();

Function<String, By> byFunction = LOCATOR_MAP.get(selectorType);
if (byFunction != null) {
return byFunction.apply(selectorValue);
} else {
throw new IllegalArgumentException("Unsupported locator type: " + selectorType);
}
}
}

// If the format is not recognized, throw an exception
throw new IllegalArgumentException("Unrecognized format of WebElement.toString()");
}

/**
* A map that associates locator types with functions that take a string parameter and return a By object.
*
* @see By
*/
public static final Map<String, Function<String, By>> LOCATOR_MAP = new HashMap<String, Function<String, By>>() {{
put("id", By::id);
put("xpath", By::xpath);
put("css selector", By::cssSelector);
put("tag name", By::tagName);
put("name", By::name);
put("class name", By::className);
put("link text", By::linkText);
put("partial link text", By::partialLinkText);
}};
}
13 changes: 13 additions & 0 deletions src/main/java/starter/selectors/factory/SelectorFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package starter.selectors.factory;

import org.openqa.selenium.By;

public interface SelectorFactory {
/**
* Returns a selector by name.
*
* @param name the name of the selector
* @return the selector
*/
By getSelector(String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package starter.selectors.factory;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public class SelectorFactoryProvider {

private static final Map<String, SelectorFactory> FACTORIES = new HashMap<>();
/**
* A map of SelectorFactory instances, keyed by the type of factory.
*/

static {
FACTORIES.put("yaml", new YamlFactory());
//FACTORIES.put("page", new PageFactory());
}

/**
* Returns an instance of SelectorFactory based on the type of factory requested.
*
* @param type the type of factory requested
* @return an instance of SelectorFactory
* @throws IllegalArgumentException if an unsupported factory type is requested
*/
public static SelectorFactory getFactory(String type) {
return Optional.ofNullable(FACTORIES.get(type))
.orElseThrow(() -> new IllegalArgumentException("Unsupported selector factory type: " + type));
}
}
Loading