package com.keyword.automation.action;

import com.keyword.automation.base.browser.BrowserType;
import com.keyword.automation.base.browser.Browsers;
import com.keyword.automation.base.common.Constants;
import com.keyword.automation.base.utils.LogUtils;

/**
 * 封装浏览器操作关键字
 * 
 * @author airpy
 *
 */
public class BrowserKeyword {
	public static void browserOpen(String requestUrl) {
		BrowserType bType = BrowserType.Chrome;
		String reqUrl = verifyRequestUrl(requestUrl);
		Browsers.createDriver(bType).open(reqUrl);
	}

	public static void browserOpen(String browserType, String requestUrl) {
		BrowserType bType = verifyBrowserType(browserType);
		String reqUrl = verifyRequestUrl(requestUrl);
		Browsers.createDriver(bType).open(reqUrl);
	}

	/**
	 * 验证传入浏览器类型
	 * 
	 * @param browserType
	 *            浏览器类型
	 * @return
	 */
	private static BrowserType verifyBrowserType(String browserType) {
		BrowserType bType;
		if (browserType.equalsIgnoreCase("Chrome")) {
			bType = BrowserType.Chrome;
		} else if (browserType.equalsIgnoreCase("Firefox")) {
			bType = BrowserType.Firefox;
		} else if (browserType.equalsIgnoreCase("IE")) {
			bType = BrowserType.IE;
		} else if (browserType.equalsIgnoreCase("Opera")) {
			bType = BrowserType.Opera;
		} else if (browserType.equalsIgnoreCase("Safari")) {
			bType = BrowserType.Safari;
		} else {
			bType = BrowserType.valueOf(Constants.DEFAULT_BROWSER);
			LogUtils.warn("您输入的浏览器类型错误，已经初始化Chrome浏览器.");
		}
		return bType;
	}
	
	/**
	 * 格式化请求URL
	 * 
	 * @param requestUrl
	 *            请求的url
	 * @return
	 */
	private static String verifyRequestUrl(String requestUrl) {
		String reqUrl;
		if (requestUrl.toLowerCase().startsWith("http://") || requestUrl.toLowerCase().startsWith("https://")) {
			reqUrl = requestUrl;
		} else {
			reqUrl = "http://" + requestUrl;
		}
		return reqUrl;
	}
}

@@ -323,16 +323,95 @@
 yword %7B%0A
+%09/**%0A%09 * %E4%BD%BF%E7%94%A8%E9%BB%98%E8%AE%A4%E6%B5%8F%E8%A7%88%E5%99%A8%E6%89%93%E5%BC%80%E6%8C%87%E5%AE%9Aurl%0A%09 * %0A%09 * @param requestUrl%0A%09 *            %E8%AF%B7%E6%B1%82url%E5%9C%B0%E5%9D%80%0A%09 */%0A
 %09public 
@@ -485,30 +485,58 @@
 BrowserType.
-Chrome
+valueOf(Constants.DEFAULT_BROWSER)
 ;%0A%09%09String r
@@ -622,16 +622,141 @@
 l);%0A%09%7D%0A%0A
+%09/**%0A%09 * %E6%A0%B9%E6%8D%AE%E4%BC%A0%E5%85%A5%E6%B5%8F%E8%A7%88%E5%99%A8%E7%B1%BB%E5%9E%8B%E6%89%93%E5%BC%80%E6%8C%87%E5%AE%9Aurl%0A%09 * %0A%09 * @param browserType%0A%09 *            %E6%B5%8F%E8%A7%88%E5%99%A8%E7%B1%BB%E5%9E%8B%0A%09 * @param requestUrl%0A%09 *            %E8%AF%B7%E6%B1%82url%E5%9C%B0%E5%9D%80%0A%09 */%0A
 %09public 
@@ -1702,17 +1702,16 @@
 ype;%0A%09%7D%0A
-%09
 %0A%09/**%0A%09 

add browserOpen method