diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..0fe6d5d --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/proJect/pom.xml b/proJect/pom.xml index 8427783..3bf4057 100644 --- a/proJect/pom.xml +++ b/proJect/pom.xml @@ -10,6 +10,7 @@ 11 11 + UTF-8 @@ -25,13 +26,24 @@ 5.9.2 test - org.junit.jupiter junit-jupiter-params 5.9.2 test + + org.seleniumhq.selenium + selenium-java + LATEST + test + + + io.github.bonigarcia + webdrivermanager + LATEST + test + \ No newline at end of file diff --git a/proJect/src/main/java/anlov/java/Factorial.java b/proJect/src/main/java/anlov/java/Factorial.java deleted file mode 100644 index 27a9dcf..0000000 --- a/proJect/src/main/java/anlov/java/Factorial.java +++ /dev/null @@ -1,15 +0,0 @@ -package anlov.java; - -public class Factorial { - - public static long getFactorial(int num) { - if (num < 0) { - throw new IllegalArgumentException("Число должно быть положительным"); - } - int factorial = 1; - for (int i = 1; i <= num; i++) { - factorial *= i; - } - return factorial; - } -} diff --git a/proJect/src/main/java/anlov/java/Main.java b/proJect/src/main/java/anlov/java/Main.java index c14deaa..1345a37 100644 --- a/proJect/src/main/java/anlov/java/Main.java +++ b/proJect/src/main/java/anlov/java/Main.java @@ -1,10 +1,7 @@ package anlov.java; - -import java.util.Arrays; - public class Main { public static void main(String[] args) { - System.out.println(Factorial.getFactorial(3)); + } } \ No newline at end of file diff --git a/proJect/src/test/java/FactorialTest.java b/proJect/src/test/java/FactorialTest.java deleted file mode 100644 index 618d24f..0000000 --- a/proJect/src/test/java/FactorialTest.java +++ /dev/null @@ -1,34 +0,0 @@ -import anlov.java.Factorial; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - - -class FactorialTest { - - @DisplayName("Check factorial if num equals 0") - @Test - void checkFactorial() { - assertEquals(1, Factorial.getFactorial(0)); - } - - @DisplayName("Check factorial if num more 0") - @ParameterizedTest - @ValueSource(ints = {1, 2, 3, 4}) - void checkMoreZero(int num) { - long[] numbers = {1, 2, 6, 24}; - assertEquals(numbers[num - 1], Factorial.getFactorial(num)); - - } - - @Test - void negativeInputShouldThrowException() { - assertThrows(IllegalArgumentException.class, - () -> Factorial.getFactorial(-5), "Число должно быть больше нуля"); - } -} diff --git a/proJect/src/test/java/TestClass.java b/proJect/src/test/java/TestClass.java new file mode 100644 index 0000000..d11accc --- /dev/null +++ b/proJect/src/test/java/TestClass.java @@ -0,0 +1,89 @@ +import io.github.bonigarcia.wdm.WebDriverManager; +import org.junit.jupiter.api.*; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.time.Duration; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class TestClass { + + WebDriver driver; + WebDriverWait wait; + + @BeforeAll + static void setupAll() { + WebDriverManager.chromedriver().setup(); + } + + @BeforeEach + void setup() { + ChromeOptions co = new ChromeOptions(); + co.addArguments("--start-maximized"); + driver = new ChromeDriver(co); + driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5)); + driver.get("https://www.mts.by/"); + driver.findElement(By.xpath("//button[@id='cookie-agree']")).click(); + } + + @AfterEach + void teardown() { + driver.quit(); + } + + @Test + @DisplayName("Проверить название блока") + void checkBlockName() { + WebElement nameOfBlogs = driver.findElement(By.xpath + ("//div[@class='pay__wrapper']/h2")); + assertEquals("Онлайн пополнение\nбез комиссии", nameOfBlogs.getText()); + } + + @Test + @DisplayName("Проверить наличие логотипов платёжных систем") + void checkLogos() { + List logos = driver.findElements(By.xpath + ("//div[@class='pay__partners']/ul/li/img")); + logos.forEach(l -> assertTrue(l.isDisplayed(), l.getAttribute("alt"))); + } + + @Test + @DisplayName("Проверить работу ссылки -'Подробнее о сервисе'") + void checkLink() { + String link = "https://www.mts.by/help/poryadok-oplaty-i-bezopasnost-internet-platezhey/"; + WebElement linkCheck = driver.findElement(By.xpath + ("//div[@class='pay__wrapper']/a")); + assertTrue(linkCheck.isEnabled()); + assertTrue(linkCheck.isDisplayed()); + String linkAttribute = linkCheck.getAttribute("href"); + driver.get(linkAttribute); + assertEquals(link, linkAttribute); + } + + @Test + @DisplayName("Проверить заполнение полей и работу кнопки 'Продолжить'") + void checkContinue() { + driver.findElement(By.xpath("//input[@id='connection-phone']")).sendKeys("297777777"); + driver.findElement(By.xpath("//input[@id='connection-sum']")).sendKeys("25"); + driver.findElement(By.xpath("//input[@id='connection-email']")).sendKeys("aston.777@gmai.com"); + driver.findElement(By.xpath("//form[@id='pay-connection']/button")).click(); + + wait = new WebDriverWait(driver, Duration.ofSeconds(7)); + WebElement iframe = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath + ("//iframe[@class='bepaid-iframe']"))); + driver.switchTo().frame(iframe); + WebElement payContinue = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath + ("//div[@class='app-wrapper__content']"))); + + assertTrue(payContinue.isDisplayed()); + } + +}