package com.selflearning.webdriver;

import junit.framework.Assert;
import org.junit.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;

import java.io.File;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: billxin
 * Date: 11/28/12
 * Time: 8:01 PM
 * To change this template use File | Settings | File Templates.
 */
public class ChromeDriverTest {

    private static ChromeDriverService service;
    private WebDriver driver;
    //private String path = "C:\\Tools\\Selenium\\ChromeDriver\\chromedriver_win_23.0.1240.0\\chromedriver.exe";
    private static String path = "C:\\Tools\\Selenium\\ChromeDriver\\chromedriver_win_23.0.1240.0\\chromedriver.exe";

    @BeforeClass
    public static void createAndStartService() throws IOException {
        service = new ChromeDriverService.Builder().usingDriverExecutable(new File(path)).usingAnyFreePort().build();
        service.start();
    }

    /**
     * add comment template
     */
    @AfterClass
    public static void createAndStopService() {
        service.stop();
    }

    @Before
    public void setup() {
        System.setProperty("webdriver.chrome.driver", "C:\\Tools\\Selenium\\ChromeDriver\\chromedriver.exe");
        //System.setProperty("webdriver.ie.driver","C:\\Tools\\Selenium\\IEDriver\\IEDriverServer.exe");
    }

    @Test
    public void googleTest() {
        driver = new ChromeDriver();
        //driver = new InternetExplorerDriver();
        //driver = new FirefoxDriver();
        driver.navigate().to("http://www.news.com.au");
        Assert.assertTrue(driver.getTitle().contains("News.com.au | News Online from Australia and the World | NewsComAu"));
        driver.close();
    }

    @After
    public void clear(){
        driver.quit();

    }
    //File file = new File("C:/Selenium/iexploredriver.exe");
    //System.setProperty()
    //System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
    //WebDriver driver = new InternetExplorerDriver();

}
