package me.alb_i986.selenium.tinafw.domain;

import me.alb_i986.selenium.tinafw.pages.*;

import org.openqa.selenium.WebDriver;

/**
 * A Browser has a WebDriver.
 * 
 * A Browser may be opened and closed.
 * By opening a Browser, a WebDriver is instantiated.
 * 
 */
public class Browser {

	private WebDriverFactory driverFactory;
	private WebDriver driver;

	/**
	 * By default inject a LocalWebDriverFactory decorated with
	 * WebDriverFactoryDecoratorImplicitWait.
	 */
	public Browser() {
		this.driverFactory = new WebDriverFactoryDecoratorImplicitWait(
				new WebDriverFactoryRemote());
	}
	
	public Browser(WebDriverFactory driverFactory) {
		this.driverFactory = driverFactory;
	}

	/**
	 * Create an instance of WebDriver.
	 * 
	 * @throws IllegalStateException if this browser
	 *         has already been opened
	 * 
	 * @see WebDriverFactory#getWebDriver()
	 */
	public void open() {
		if(isOpen()) {
			throw new IllegalStateException("Browser already open: close it first");
		}
		driver = driverFactory.getWebDriver();
	}
	
	/**
	 * @see WebDriver#quit()
	 */
	public void close() {
		if(isOpen()) {
			driver.quit();
			driver = null;
		}
	}
	
	public void browseTo(String url) {
		driver.get(url);
	}

	/**
	 * @return true if driver is not null.
	 */
	public boolean isOpen() {
		return driver != null;
	}
	
	public WebDriver getWebDriver() {
		return driver;
	}

}

@@ -387,13 +387,15 @@
 t a 
-Local
+%7B@link 
 WebD
@@ -406,16 +406,22 @@
 rFactory
+Local%7D
  decorat
@@ -427,16 +427,21 @@
 ted 
-with%0A%09 *
+by%0A%09 * %7B@link
  Web
@@ -474,16 +474,17 @@
 icitWait
+%7D
 .%0A%09 */%0A%09
@@ -596,14 +596,13 @@
 tory
-Remote
+Local
 ());

fix Browser