Removed redundant color formatting for activation key logs to streamline the output. This ensures a cleaner and more straightforward log message for better readability.
105 lines
3.4 KiB
Java
105 lines
3.4 KiB
Java
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();
|
|
|
|
String keyText = """
|
|
ESET Smart Security activation key found:
|
|
|
|
=---------------------------=
|
|
%s
|
|
=---------------------------=
|
|
""".formatted(key);
|
|
|
|
getContext().getScenario().log(keyText);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|