package hu.pazsitz.pacuse.tests.helpers;

import hu.pazsitz.pacuse.pages.AbstractPage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;


/*
 * Base class for all the test classes

 * TestBase.java
 *
 * @author Zoltan Pazsit <pazsitz@pazsitz.hu>
 * @copyright Copyright (c) 2014, Zoltan Pazsit
 */
public class TestBase {

    protected WebDriver webDriver;

    protected String server;

    protected String websiteUrl;

    @BeforeClass
    public void init() {
        server = "";
        String weDriverGridUrl = System.getProperty("PaCuSe.WebDriver.gridUrl", "");
        if (weDriverGridUrl.isEmpty()) {
            webDriver = WebDriverFactory.getInstance(
        		WebDriverFactory.BrowserName.getBrowser(
        			System.getProperty("PaCuSe.browser")
        		)
    		);
        } else {
            webDriver = WebDriverFactory.getInstance(
                weDriverGridUrl, 
                WebDriverFactory.BrowserName.getBrowser(
                    System.getProperty("PaCuSe.browser")
                ), 
                "", ""
            );
        }
        
        Waiters.setWebDriver(webDriver);
    }

    @BeforeMethod
    public void initMethod() {
        webDriver.manage().deleteAllCookies();
    }

    @AfterSuite(alwaysRun = true)
    public void tearDown() {
        if (webDriver != null) {
            webDriver.quit();
        }
    }

    protected void loadPage(AbstractPage pageImpl) {
        String pageUrl = server + pageImpl.getUrl();
        pageImpl.getWebDriver().get(pageUrl);
        PageFactory.initElements(webDriver, pageImpl);
    }

    public WebDriver getWebDriver() {
        return webDriver;
    }


}
@@ -202,21 +202,21 @@
 ns.After
-Suite
+Class
 ;%0Aimport
@@ -659,586 +659,39 @@
     
-String weDriverGridUrl = System.getProperty(%22PaCuSe.WebDriver.gridUrl%22, %22%22);%0A        if (weDriverGridUrl.isEmpty()) %7B%0A            webDriver = WebDriverFactory.getInstance(%0A        %09%09WebDriverFactory.BrowserName.getBrowser(%0A        %09%09%09System.getProperty(%22PaCuSe.browser%22)%0A        %09%09)%0A    %09%09);%0A        %7D else %7B%0A            webDriver = WebDriverFactory.getInstance(%0A                weDriverGridUrl, %0A                WebDriverFactory.BrowserName.getBrowser(%0A                    System.getProperty(%22PaCuSe.browser%22)%0A                ), %0A                %22%22, %22%22%0A            );%0A        %7D
+webDriver = new SharedDriver();
 %0A   
@@ -861,13 +861,13 @@
 fter
-Suite
+Class
 (alw

use SharedDriver to support multiThread