package ag;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.AssertJUnit;
import org.testng.ITestContext;
import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.AssertJUnit;
import static org.testng.AssertJUnit.assertEquals;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;


import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Rule;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Platform;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.log.*;



import ru.stqa.selenium.factory.WebDriverFactory;
import ru.yandex.qatools.allure.annotations.Step;
import ru.yandex.qatools.allure.annotations.Title;

import ag.pages.MainPage;
import ag.pages.NoAutch;
import ag.util.PropertyLoader;


/**
 * Base class for all the TestNG-based test classes
 */
public class TestBase {

	
	public WebDriver driver;

	

	public static String baseUrl;
	protected String login;
	protected String passworld;
	protected String platform;


	public WebDriver getDriver() {
        return driver;
	}
	
	
	
	@Title("Инициализация ")
	@BeforeClass
	public void init() {
		baseUrl = PropertyLoader.loadProperty("site.url");
		login = PropertyLoader.loadProperty("user.username");
		passworld = PropertyLoader.loadProperty("user.password");
		
		DesiredCapabilities capabilities = new DesiredCapabilities();
		//capabilities.setCapability(CapabilityType.PAGE_LOAD_STRATEGY, "eager");
		capabilities.setBrowserName(PropertyLoader.loadProperty("browser.name"));
		capabilities.setVersion(PropertyLoader.loadProperty("browser.version"));
		String platform = PropertyLoader.loadProperty("browser.platform");
		if (!(null == platform || "".equals(platform))) {
			capabilities.setPlatform(Platform.valueOf(PropertyLoader.loadProperty("browser.platform")));
		}

		//System.setProperty("webdriver.gecko.driver","drivers/geckodriver");
		driver = WebDriverFactory.getDriver(capabilities);
		    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		    driver.manage().window().maximize();

		
	}

	
	@Title("Закрыть браузер")
	@AfterClass(alwaysRun = true)
	public void closeBrowser() {    
		if (driver != null) {
			WebDriverFactory.dismissDriver(driver);
		}
	}
	
 
	@Step("Перейти на главную страницу ")
	public void toMainPage(){ 
		 
		driver.get("http://ag.mos.ru/"); // после теста - вернутся на главную страницу	
		 
	}


}
