ch.exense.step.library.selenium.DriverWrapper Maven / Gradle / Ivy
/*******************************************************************************
* Copyright 2021 exense GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package ch.exense.step.library.selenium;
import java.io.Closeable;
import org.openqa.selenium.WebDriver;
/**
* Wrapper class for WebDriver instance.
* The class implements the Closeable interface in order to easily manage the browser instance closing.
*
*/
public class DriverWrapper implements Closeable {
/**
* The WebDriver instance to be wrapped.
*/
final WebDriver driver;
/**
* Constructor for DriverWrapper
* @param driver the WebDriver instance to be wrapped
*/
public DriverWrapper(WebDriver driver) {
super();
this.driver = driver;
}
/**
* Method to automatically and properly close the wrapped WebDriver when not used anymore
*/
@Override
public void close() {
driver.quit();
}
/**
* Getter to retrieve the wrapped driver
* @return the wrapped WebDriver instance
*/
public WebDriver getDriver() {
return driver;
}
}