package com.friskysoft.test.framework;

import com.friskysoft.framework.Browser;
import com.friskysoft.test.pages.*;
import com.friskysoft.test.utils.ImageUploader;
import org.openqa.selenium.remote.BrowserType;
import org.testng.ITestResult;
import org.testng.annotations.*;
import org.testng.log4testng.Logger;

import java.net.URL;
import java.util.concurrent.TimeUnit;

public class BaseTests {

    protected Browser browser;
    protected String browserType = BrowserType.PHANTOMJS;
    protected String baseUrl = null;
    protected String loginPath = "/login.html";
    protected String homePath = "/home.html";
    protected String framesPath = "/frames.html";
    protected String overlapPath = "/overlap.html";
    protected String hoverPath = "/hover.html";

    protected HomePage homePage = new HomePage();
    protected LoginPage loginPage = new LoginPage();
    protected FramesPage framesPage = new FramesPage();
    protected OverlapPage overlapPage = new OverlapPage();
    protected HoverPage hoverPage = new HoverPage();

    protected Logger getLogger() {
        return Logger.getLogger(this.getClass());
    }

    @BeforeSuite
    public void setupLogger() {
        org.apache.log4j.BasicConfigurator.configure();
    }

    @BeforeClass
    public void setupBaseUrl() {
        URL resource = this.getClass().getResource("/test-web");
        baseUrl = "file://" + resource.getPath();
    }

    @BeforeClass
    public void setupBrowser() {
        browser = Browser.newLocalDriver(browserType)
                .setPageLoadTimeout(30, TimeUnit.SECONDS)
                .setImplicitWait(5, TimeUnit.SECONDS);
    }

    @AfterMethod
    public void failureScreenshot(ITestResult result) {
        if (result.getStatus() != ITestResult.SUCCESS) {
            try {
                String screenshot = browser.takeScreenshot();
                String screenshotUrl = ImageUploader.upload(screenshot);
                getLogger().error("Test failed! Screenshot uploaded at: " + screenshotUrl);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    @AfterClass
    public void teardownBrowser() {
        browser.destroy();
    }

}

@@ -154,24 +154,135 @@
 geUploader;%0A
+import org.apache.log4j.ConsoleAppender;%0Aimport org.apache.log4j.Level;%0Aimport org.apache.log4j.PatternLayout;%0A
 import org.o
@@ -1280,32 +1280,102 @@
 setupLogger() %7B%0A
+        org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);%0A
         org.apac

set test log level to info