public WebDriver startBrowser(String browserName, String terminal, String deviceName, String remoteIP, int remotePort, String browserVersion) {
/* 驱动基本信息参数 */
this.browserName = browserName.toLowerCase();
/* 终端设备信息参数 */
this.terminal = terminal.toLowerCase();
this.deviceName = deviceName;
/* hub 信息配置 */
this.remoteIP = remoteIP;
this.remotePort = remotePort;
this.browserVersion = browserVersion;
/* 初始化驱动的责任链中各个对象 */
DriverHandler headHandler = new HeadHandler();
DriverHandler chromeDriverHandler = new ChromeDriverHandler();
DriverHandler firefoxDriverHandler = new FirefoxDriverHandler();
DriverHandler operaDriverHandler = new OperaDriverHandler();
DriverHandler edgeDriverHandler = new EdgeDriverHandler();
DriverHandler internetExplorerDriverHandler = new InternetExplorerDriverHandler();
DriverHandler tailHandler = new TailHandler();
/* 构建一条驱动初始化的完整责任链 */
headHandler.setNext(chromeDriverHandler).setNext(firefoxDriverHandler).setNext(operaDriverHandler)
.setNext(edgeDriverHandler).setNext(internetExplorerDriverHandler).setNext(tailHandler);
/* 通过责任链启动浏览器 */
this.driver = headHandler.start(browserName, terminal, deviceName, remoteIP, remotePort, browserVersion);
/* 驱动设置等待时长 */
long implicitlyWait = Long.parseLong(PropertiesReader.getKey("driver.timeouts.implicitlyWait"));
long pageLoadTimeout = Long.parseLong(PropertiesReader.getKey("driver.timeouts.pageLoadTimeout"));
long setScriptTimeout = Long.parseLong(PropertiesReader.getKey("driver.timeouts.setScriptTimeout"));
// 隐式等待
driver.manage().timeouts().implicitlyWait(implicitlyWait, TimeUnit.SECONDS);
// 页面加载等待
driver.manage().timeouts().pageLoadTimeout(pageLoadTimeout, TimeUnit.SECONDS);
// JS 等待
driver.manage().timeouts().setScriptTimeout(setScriptTimeout, TimeUnit.SECONDS);
/* 窗口最大化 */
driver.manage().window().maximize();
log.info((terminal.toLowerCase().equals("h5")) ? ("浏览器:" + browserName + " h5 成功启动!") : ("浏览器:" + browserName + " 成功启动!"));
return this.driver;
}
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/c811b2321fca4bb0b54851048e316fa5.jpeg?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit)
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/5dbe5384d4494a80a9f6c55695d4e40a.jpeg?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit)