001/* 002 * (C) Copyright 2011-2016 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Sun Seng David TAN 016 * Florent Guillaume 017 * Benoit Delbosc 018 * Antoine Taillefer 019 * Anahide Tchertchian 020 * Guillaume Renard 021 * Mathieu Guillaume 022 * Julien Carsique 023 */ 024package org.nuxeo.functionaltests.drivers; 025 026import org.openqa.selenium.firefox.FirefoxDriver; 027import org.openqa.selenium.firefox.FirefoxProfile; 028import org.openqa.selenium.remote.DesiredCapabilities; 029import org.openqa.selenium.remote.LocalFileDetector; 030import org.openqa.selenium.remote.RemoteWebDriver; 031 032import net.jsourcerer.webdriver.jserrorcollector.JavaScriptError; 033 034/** 035 * Driver provider for firefox. 036 * 037 * @since 8.3 038 */ 039public class RemoteFirefoxDriverProvider implements DriverProvider { 040 041 public static final String WEBDRIVER_URL = System.getProperty("webdriverURL", "http://localhost:4444/wd/hub"); 042 043 protected RemoteWebDriver driver; 044 045 @Override 046 public RemoteWebDriver init(DesiredCapabilities dc) throws Exception { 047 048 FirefoxProfile profile = FirefoxDriverProvider.getProfile(); 049 050 JavaScriptError.addExtension(profile); 051 052 dc.setCapability(FirefoxDriver.PROFILE, profile); 053 driver = new RemoteWebDriver(new java.net.URL(WEBDRIVER_URL), dc); 054 driver.setFileDetector(new LocalFileDetector()); 055 return driver; 056 } 057 058 @Override 059 public RemoteWebDriver get() { 060 return driver; 061 } 062 063 @Override 064 public void quit() { 065 if (driver != null) { 066 driver.quit(); 067 driver = null; 068 } 069 } 070 071}