001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 * http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.atteo.moonshine.webdriver.browsers;
015
016import java.io.IOException;
017
018import org.openqa.selenium.chrome.ChromeDriverService;
019import org.openqa.selenium.remote.DesiredCapabilities;
020import org.openqa.selenium.remote.RemoteWebDriver;
021import org.slf4j.Logger;
022import org.slf4j.LoggerFactory;
023
024public class ChromeBrowser implements Browser {
025    private static final Logger logger = LoggerFactory.getLogger(ChromeBrowser.class);
026
027    private ChromeDriverService service;
028
029    public ChromeBrowser() {
030        System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, "target/chromedriver.log");
031        try {
032            service = ChromeDriverService.createDefaultService();
033            service.start();
034        } catch (IOException e) {
035            throw new RuntimeException(e);
036        }
037    }
038
039    @Override
040    public RemoteWebDriver createDriver() {
041        return new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());
042    }
043
044    @Override
045    public void close() {
046        service.stop();
047    }
048}