init
This commit is contained in:
commit
4f4c37bc53
26 files changed
+953
No files matched your search
@@ -0,0 +1,17 @@
|
||||
import io.cucumber.junit.Cucumber;
|
||||
import io.cucumber.junit.CucumberOptions;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(Cucumber.class)
|
||||
@CucumberOptions(
|
||||
features = {"src/test/resources/features"},
|
||||
glue = {"steps"},
|
||||
plugin = {"json:target/cucumber-report/cucumber.json"},
|
||||
monochrome = false,
|
||||
stepNotifications = true,
|
||||
//ToDo change this!
|
||||
tags = "@ESET",
|
||||
snippets = CucumberOptions.SnippetType.CAMELCASE
|
||||
)
|
||||
public class TestRunner {
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package Utils;
|
||||
|
||||
public enum ColorFormatter {
|
||||
BLACK(30),
|
||||
RED(31),
|
||||
GREEN(32),
|
||||
YELLOW(33),
|
||||
BLUE(34),
|
||||
PURPLE(35),
|
||||
CYAN(36),
|
||||
WHITE(37);
|
||||
|
||||
private static final String RESET = "\u001B[0m";
|
||||
private static final String PREFIX = "\u001B[";
|
||||
private static final String SUFFIX = "m";
|
||||
private final String colorCode;
|
||||
|
||||
ColorFormatter(int code) {
|
||||
this.colorCode = PREFIX + code + SUFFIX;
|
||||
}
|
||||
|
||||
public String toConsole(String text) {
|
||||
return colorCode + text + RESET;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package Utils;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.response.Response;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
public class TempMailRestApiClient {
|
||||
private static final String TEMPMAIL_BASE_URL = "https://api.tempmail.lol/v2";
|
||||
|
||||
private static final String POST_CREATE_URI = "/inbox/create";
|
||||
private static final String GET_INBOX_URI = "/inbox";
|
||||
|
||||
public Response createInbox() {
|
||||
return RestAssured.given()
|
||||
.baseUri(TEMPMAIL_BASE_URL)
|
||||
.when()
|
||||
.post(POST_CREATE_URI)
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.response();
|
||||
}
|
||||
|
||||
public Response getInbox(String token, String emailSubject) {
|
||||
return RestAssured.given()
|
||||
.baseUri(TEMPMAIL_BASE_URL)
|
||||
.queryParam("token", token)
|
||||
.when()
|
||||
.get(GET_INBOX_URI)
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(200)
|
||||
.body("emails.size()", greaterThan(0))
|
||||
.body("emails.subject", hasItem(emailSubject))
|
||||
.extract()
|
||||
.response();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package Utils;
|
||||
|
||||
|
||||
import net.datafaker.Faker;
|
||||
|
||||
public class utils {
|
||||
|
||||
public static int getRandomValue(int min, int max) {
|
||||
return new Faker().number().numberBetween(min, max);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package frameworkContext;
|
||||
|
||||
import io.cucumber.java.Scenario;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class Context {
|
||||
|
||||
// Scenario
|
||||
private String tempEmail;
|
||||
private String tempEmailToken;
|
||||
|
||||
// Framework
|
||||
private Scenario scenario;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package frameworkContext;
|
||||
|
||||
public class ContextFactory {
|
||||
private static ThreadLocal<ContextThread> contextThread;
|
||||
|
||||
// @Before(order = 1)
|
||||
public static void instantiateContextObject() {
|
||||
contextThread = ThreadLocal.withInitial(ContextThread::new);
|
||||
}
|
||||
|
||||
public static Context getContext() {
|
||||
return contextThread.get().getContext();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package frameworkContext;
|
||||
|
||||
public class ContextThread {
|
||||
private Context Context;
|
||||
|
||||
public Context getContext() {
|
||||
if (Context == null) {
|
||||
Context = new Context();
|
||||
}
|
||||
return Context;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package pages;
|
||||
|
||||
import com.codeborne.selenide.SelenideElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
public class EsetHomePage extends Pages {
|
||||
|
||||
// FIELDS
|
||||
@FindBy(id = "email")
|
||||
public SelenideElement accountEmailField;
|
||||
|
||||
@FindBy(id = "password")
|
||||
public SelenideElement accountPasswordField;
|
||||
|
||||
// BUTTONS
|
||||
@FindBy(id = "cc-accept")
|
||||
public SelenideElement cookiesConsentAcceptButton;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package pages;
|
||||
|
||||
public class Pages {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package pojos;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Email {
|
||||
|
||||
private String to;
|
||||
private String from;
|
||||
private String subject;
|
||||
private String body;
|
||||
private long date;
|
||||
private String ip;
|
||||
private String html;
|
||||
|
||||
@JsonProperty("_id")
|
||||
private String id;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package pojos;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Emails {
|
||||
|
||||
private List<Email> emails;
|
||||
private boolean expired;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package steps;
|
||||
|
||||
import com.codeborne.selenide.Selenide;
|
||||
import io.cucumber.java.en.And;
|
||||
import org.openqa.selenium.WindowType;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static com.codeborne.selenide.Selenide.*;
|
||||
|
||||
public class CommonSteps {
|
||||
|
||||
|
||||
@And("Navigate to {string}")
|
||||
public void navigateTo(String url) {
|
||||
open(url);
|
||||
}
|
||||
|
||||
@And("CommonSteps: Open new tab in browser with url {string}")
|
||||
public void commonstepsOpenNewTabWithUrl(String url) {
|
||||
switchTo().newWindow(WindowType.TAB);
|
||||
Selenide.open(url);
|
||||
}
|
||||
|
||||
@And("CommonSteps: Got to tab number {int}")
|
||||
public void commonstepsGoToTabNumber(int tabNumber) {
|
||||
switchTo().window(tabNumber - 1);
|
||||
}
|
||||
|
||||
@And("CommonSteps: Wait {int} seconds")
|
||||
public void commonstepsWaitSeconds(int time) {
|
||||
sleep(Duration.ofSeconds(time).toMillis());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package steps;
|
||||
|
||||
import Utils.ColorFormatter;
|
||||
import com.codeborne.selenide.Condition;
|
||||
import com.codeborne.selenide.ex.ElementNotFound;
|
||||
import io.cucumber.java.en.And;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.openqa.selenium.By;
|
||||
import org.passay.CharacterData;
|
||||
import org.passay.CharacterRule;
|
||||
import org.passay.EnglishCharacterData;
|
||||
import org.passay.PasswordGenerator;
|
||||
import pages.EsetHomePage;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.codeborne.selenide.Selenide.$;
|
||||
import static com.codeborne.selenide.Selenide.page;
|
||||
import static frameworkContext.ContextFactory.getContext;
|
||||
|
||||
@Slf4j
|
||||
public class EsetHomeSteps extends Steps {
|
||||
|
||||
EsetHomePage webPage = page(EsetHomePage.class);
|
||||
|
||||
@And("EsetHomePage: Click button {string}")
|
||||
public void esethomepageClickButton(String buttonName) {
|
||||
$(By.xpath("//*[text()='%s' and not(self::b)]"
|
||||
.formatted(buttonName)))
|
||||
.scrollIntoCenter()
|
||||
.click();
|
||||
}
|
||||
|
||||
@And("EsetHomePage: Accept cookies")
|
||||
public void esethomepageAcceptCookies() {
|
||||
try {
|
||||
webPage.cookiesConsentAcceptButton
|
||||
.shouldBe(Condition.visible, Duration.ofSeconds(5))
|
||||
.scrollIntoCenter()
|
||||
.click();
|
||||
} catch (ElementNotFound e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@And("EsetHomePage: Enter saved temporary email address")
|
||||
public void esethomepageFillSavedEmail() {
|
||||
webPage.accountEmailField.scrollIntoCenter().setValue(getContext().getTempEmail());
|
||||
}
|
||||
|
||||
@And("EsetHomePage: Enter generated password")
|
||||
public void esethomepageFillGeneratedPassword() {
|
||||
String password = generatePassword(12);
|
||||
|
||||
webPage.accountPasswordField.scrollIntoCenter().setValue(password);
|
||||
|
||||
log.info("Password entered: {}", ColorFormatter.RED.toConsole(password));
|
||||
}
|
||||
|
||||
@And("EsetHomePage: Choose system {string}")
|
||||
public void esethomepageChooseSystem(String systemName) {
|
||||
$(By.xpath("//button[@data-label='device-protect-os-card-%s-button']"
|
||||
.formatted(systemName)))
|
||||
.scrollIntoCenter()
|
||||
.click();
|
||||
}
|
||||
|
||||
@And("EsetHomePage: Read ESET Smart Security activation code")
|
||||
public void esethomepageReadESETSmartSecurityActivationCode() {
|
||||
String key = $(By.xpath("//p[text()='Klucz aktywacji']/..//following-sibling::*[1]/p")).getText();
|
||||
|
||||
log.info("""
|
||||
|
||||
ESET Smart Security activation key found:
|
||||
|
||||
=---------------------------=
|
||||
{}
|
||||
=---------------------------=
|
||||
|
||||
""", ColorFormatter.GREEN.toConsole(key));
|
||||
}
|
||||
|
||||
public static String generatePassword(int length) {
|
||||
PasswordGenerator generator = new PasswordGenerator();
|
||||
List<CharacterRule> rules = Arrays.asList(
|
||||
new CharacterRule(EnglishCharacterData.LowerCase, 1),
|
||||
new CharacterRule(EnglishCharacterData.UpperCase, 1),
|
||||
new CharacterRule(EnglishCharacterData.Digit, 1),
|
||||
new CharacterRule(new CharacterData() {
|
||||
public String getErrorCode() {
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
public String getCharacters() {
|
||||
return "!@#$%^&*";
|
||||
}
|
||||
}, 1)
|
||||
);
|
||||
|
||||
return generator.generatePassword(length, rules);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package steps;
|
||||
|
||||
import com.codeborne.selenide.Configuration;
|
||||
import io.cucumber.java.After;
|
||||
import io.cucumber.java.Before;
|
||||
import io.cucumber.java.Scenario;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.openqa.selenium.chrome.ChromeOptions;
|
||||
|
||||
import static frameworkContext.ContextFactory.instantiateContextObject;
|
||||
|
||||
@Slf4j
|
||||
public class Hooks {
|
||||
|
||||
@Before
|
||||
public void setup(Scenario scenario) {
|
||||
instantiateContextObject();
|
||||
|
||||
ChromeOptions options = new ChromeOptions();
|
||||
options.addArguments("--incognito");
|
||||
Configuration.browserCapabilities = options;
|
||||
|
||||
Configuration.browser = "chrome";
|
||||
Configuration.timeout = 30000;
|
||||
Configuration.pollingInterval = 500;
|
||||
Configuration.browserSize = "1920x1080";
|
||||
Configuration.headless = true;
|
||||
|
||||
log.info("Start scenario: {}", scenario.getName());
|
||||
}
|
||||
|
||||
@After
|
||||
public void exit(Scenario scenario) {
|
||||
genericAfter(scenario);
|
||||
}
|
||||
|
||||
private void genericAfter(Scenario scenario) {
|
||||
if (scenario.isFailed()) {
|
||||
log.error("Scenario error");
|
||||
}
|
||||
|
||||
log.info("Finished scenario: {}", scenario.getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package steps;
|
||||
|
||||
public class Steps {
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package steps;
|
||||
|
||||
import Utils.ColorFormatter;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.cucumber.java.en.And;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.response.Response;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import pojos.Email;
|
||||
import pojos.Emails;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.codeborne.selenide.Selenide.open;
|
||||
import static frameworkContext.ContextFactory.getContext;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
@Slf4j
|
||||
public class TempMailAPISteps extends Steps {
|
||||
|
||||
private static final String BASE_URL = "https://api.tempmail.lol/v2";
|
||||
private static final String ESET_URL_LINK = "https://login\\.eset\\.com/link/confirmregistration\\?token=[a-zA-Z0-9-]+";
|
||||
private static final String ESET_KEY_PATTERN = "\\b[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}\\b";
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private Response response;
|
||||
|
||||
|
||||
@And("TempMailAPI: Save to context generated email and token")
|
||||
public void tempmailapiSaveToContextGeneratedEmailAndToken() {
|
||||
|
||||
response = RestAssured.given()
|
||||
.baseUri(BASE_URL)
|
||||
.when()
|
||||
.post("/inbox/create")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.response();
|
||||
|
||||
String address = response.jsonPath().getString("address");
|
||||
String token = response.jsonPath().getString("token");
|
||||
|
||||
getContext().setTempEmail(address);
|
||||
getContext().setTempEmailToken(token);
|
||||
|
||||
log.info("Temporary email address has been successfully retrieved: {}, with token: {}",
|
||||
ColorFormatter.GREEN.toConsole(address),
|
||||
ColorFormatter.GREEN.toConsole(token));
|
||||
}
|
||||
|
||||
@And("TempMailAPI: Confirm Home Eset registration")
|
||||
public void tempmailapiAgreeRegistrationInHomeEset() {
|
||||
|
||||
String emailSubject = "Potwierdzenie utworzenia konta";
|
||||
|
||||
getEmailsUntilFindEmailWithSubject(emailSubject);
|
||||
String responeJsonString = response.getBody().asString();
|
||||
|
||||
try {
|
||||
Emails emails = objectMapper.readValue(responeJsonString, Emails.class);
|
||||
|
||||
for (Email email : emails.getEmails()) {
|
||||
if (email.getSubject().equals(emailSubject)) {
|
||||
Pattern pattern = Pattern.compile(ESET_URL_LINK);
|
||||
Matcher matcher = pattern.matcher(email.getHtml());
|
||||
|
||||
if (matcher.find()) {
|
||||
String href = matcher.group();
|
||||
log.info("Activation link found: {}", href);
|
||||
open(href);
|
||||
} else {
|
||||
throw new RuntimeException("Activation link not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@And("TempMailAPI: Download ESET Smart Security activation code")
|
||||
public void tempmailapiGetActivationKeyForEset() {
|
||||
|
||||
final String emailSubject = "Thank you for your interest in ESET HOME Security Premium";
|
||||
|
||||
getEmailsUntilFindEmailWithSubject(emailSubject);
|
||||
String responeJsonString = response.getBody().asString();
|
||||
|
||||
try {
|
||||
Emails emails = objectMapper.readValue(responeJsonString, Emails.class);
|
||||
|
||||
for (Email email : emails.getEmails()) {
|
||||
if (email.getSubject().equals(emailSubject)) {
|
||||
Pattern pattern = Pattern.compile(ESET_KEY_PATTERN);
|
||||
Matcher matcher = pattern.matcher(email.getHtml());
|
||||
|
||||
if (matcher.find()) {
|
||||
log.info("""
|
||||
ESET Smart Security activation key found:
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
{}
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
""", matcher.group());
|
||||
} else {
|
||||
throw new RuntimeException("Activation key not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void getEmailsUntilFindEmailWithSubject(String emailSubject) {
|
||||
|
||||
final String token = getContext().getTempEmailToken();
|
||||
|
||||
await().atMost(60, TimeUnit.SECONDS)
|
||||
.pollInterval(1, TimeUnit.SECONDS)
|
||||
.ignoreExceptions()
|
||||
.untilAsserted(() ->
|
||||
|
||||
response = RestAssured.given()
|
||||
.baseUri(BASE_URL)
|
||||
.queryParam("token", token)
|
||||
.when()
|
||||
.get("/inbox")
|
||||
.then()
|
||||
.assertThat()
|
||||
.statusCode(200)
|
||||
.body("emails.size()", greaterThan(0))
|
||||
.body("emails.subject", hasItem(emailSubject))
|
||||
.extract()
|
||||
.response()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
@ESET
|
||||
Feature: Download ESET Smart Security license key
|
||||
|
||||
Scenario: Download ESET Smart Security license key
|
||||
Given Navigate to "https://home.eset.com"
|
||||
And TempMailAPI: Save to context generated email and token
|
||||
And EsetHomePage: Accept cookies
|
||||
And EsetHomePage: Click button "Utwórz konto"
|
||||
And EsetHomePage: Enter saved temporary email address
|
||||
And EsetHomePage: Click button "Kontynuuj za pomocą e-maila"
|
||||
And EsetHomePage: Enter generated password
|
||||
And EsetHomePage: Click button "Utwórz konto lub zaloguj się"
|
||||
And TempMailAPI: Confirm Home Eset registration
|
||||
And EsetHomePage: Click button "Pierwsze kroki"
|
||||
And EsetHomePage: Click button "Wypróbuj ESET za darmo"
|
||||
And EsetHomePage: Click button "Kontynuuj"
|
||||
And EsetHomePage: Click button "Chroń swój dom"
|
||||
And EsetHomePage: Click button "Kontynuuj"
|
||||
And EsetHomePage: Click button "Wyświetl szczegóły dotyczące wersji próbnej"
|
||||
And EsetHomePage: Click button "Kontynuuj"
|
||||
And EsetHomePage: Read ESET Smart Security activation code
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<configuration scan="false" scanPeriod="120 seconds">
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>INFO</level>
|
||||
</filter>
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} %highlight(%-5level) %cyan(%logger{36}) - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
||||
<file>${user.dir}\target\logs\logfile.log</file>
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<appender-ref ref="FILE"/>
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in new issue
Block a user