package me.alb_i986.selenium.tinafw.domain;

import org.apache.log4j.Logger;

import me.alb_i986.selenium.tinafw.pages.Page;
import me.alb_i986.selenium.tinafw.tasks.CompositeWebTask;
import me.alb_i986.selenium.tinafw.tasks.WebTask;

/**
 * A User has a Browser.
 * Also, a User may have a username and a password.
 */
public class User {

	protected static final Logger logger = Logger.getLogger(User.class);
	
	private Browser browser;
	private String username = "";
	private String password = "";

	/**
	 * Create a User with nothing but a (closed) Browser.
	 */
	public User() {
		this.browser = new Browser();
	}

	public User(Browser browser) {
		this.browser = browser;
	}


	/**
	 * Open the browser but do not navigate to any page yet.
	 * Please bear in mind that it is illegal to open
	 * the browser more than once without closing it
	 * first.
	 * 
	 * @return this
	 * @see Browser#open()
	 */
	public User openBrowser() {
		browser.open();
		return this;
	}
	
	/**
	 * Run the given task (or task<i>s</i>, if it is a {@link CompositeWebTask}),
	 * with no initial page.
	 * This means that the given task (or the <i>first</> subtask if it is a
	 * {@link CompositeWebTask}) must do the navigation itself.
	 * 
	 * @param task
	 * @return this
	 * 
	 * @see #doTask(Page, WebTask)
	 */
	public User doTask(WebTask task) {
		return doTask(null, task);
	}

	/**
	 * Run the given task (or task<i>s</i>, if it is a {@link CompositeWebTask}),
	 * starting from the given initial page.
	 * 
	 * @param initialPage
	 * @param task
	 * @return this
	 */
	public User doTask(Page initialPage, WebTask task) {
		task.doTask(initialPage);
		return this;
	}

	/**
	 * Any method chain ends with this method.
	 * @see Browser#close()
	 */
	public void closeBrowser() {
		browser.close();
	}
	

	public String getUsername() {
		return username;
	}

	public User withUsername(String username) {
		if(username == null)
			this.username = "";
		else
			this.username = username;
		return this;
	}
	
	public String getPassword() {
		return password;
	}
	
	public User withPassword(String password) {
		this.password = password;
		return this;
	}


	public Browser getBrowser() {
		return browser;
	}

}

@@ -259,61 +259,716 @@
 wser
-.%0A * Also, a User may have a username and a password.
+, which he/she can open and close;%0A * can browse to a relative URL; can do tasks.%0A * Finally, a User may have a username and a password.%0A * If your user requires more information (e.g. a role),%0A * you may extend this class and add as many fields as needed.%0A * %3Cp%3E%0A * Typically, User will be the only object directly referenced in your%0A * test code (apart from WebTask's).%0A * In fact, from User you can reach Browser, and then WebDriver%0A * (which may be useful for debugging purposes).%0A * %3Cp%3E%0A * A typical use is as follows:%0A * %3Cpre%3E%0A * %7B@code%0A * new User()%0A *   .openBrowser();%0A *   .doTask(new XXXCompositeWebTask( %5B..%5D ));%0A *   .closeBrowser()%0A * ;%0A * %7D%0A * %3C/pre%3E%0A * This is how tests should look like.%0A * 
 %0A */
@@ -1617,24 +1617,370 @@
 urn this;%0A%09%7D
+%0A%0A%09/**%0A%09 * Any method chain ends with this method.%0A%09 * @see Browser#close()%0A%09 */%0A%09public void closeBrowser() %7B%0A%09%09browser.close();%0A%09%7D%0A%0A%09/**%0A%09 * @param relativeUrl a relative URL (relative to %7B@link Page#BASE_URL%7D)%0A%09 * @see Browser#browseTo(String)%0A%09 */%0A%09public User browseTo(String relativeUrl) %7B%0A%09%09browser.browseTo(relativeUrl);%0A%09%09return this;%0A%09%7D
 %0A%09%0A%09/**%0A%09 * 
@@ -2661,141 +2661,8 @@
 %09%7D%0A%0A
-%09/**%0A%09 * Any method chain ends with this method.%0A%09 * @see Browser#close()%0A%09 */%0A%09public void closeBrowser() %7B%0A%09%09browser.close();%0A%09%7D%0A%09%0A
 %0A%09pu

update User