avito-test/src/test/java/org/example/BaseTest.java
2024-05-06 22:58:10 +04:00

58 lines
1.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package org.example;
import java.time.Duration;
import org.aeonbits.owner.ConfigFactory;
import org.example.config.BaseCofig;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
/**
* Общий класс с настройками для всех тестов
*/
public abstract class BaseTest {
//создание экземпляра драйвера
/**
* Переменная с экземпляром драйвера
*/
protected WebDriver driver;
/**
* Экземпляр конфигурации с общими параметрами
*/
private final BaseCofig config = ConfigFactory.create(BaseCofig.class, System.getenv());
/**
* Общие настройки для всех тестов, перед выполнением каждого
*/
@BeforeMethod
public void setUp(){
//Установка настройки с путём к Google драйверу
System.setProperty(config.driverProperty(), config.driverPath());
//Создание экземпляра драйвера
driver = new ChromeDriver();
//открытие страницы Google по url
driver.get(config.url());
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2));
//разворот окна на полный экран при открытии
driver.manage().window().maximize();
}
/**
* Общие настройки для всех тестов, после выполнения каждого теста
*/
@AfterMethod
public void tearDown() throws InterruptedException {
//Остановка работы драйвера
driver.close();
}
}