
com.comcast.magicwand.drivers.AbstractPhoenixDriver Maven / Gradle / Ivy
The newest version!
/**
* Copyright 2015 Comcast Cable Communications Management, LLC
*
* 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 com.comcast.magicwand.drivers;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import com.comcast.cookie.CookieHandler;
public abstract class AbstractPhoenixDriver implements PhoenixDriver {
private static final Logger LOG = LoggerFactory.getLogger(AbstractPhoenixDriver.class);
/**
* @return Reference to a {@link CookieHandler}
*/
protected abstract CookieHandler getCookieHandler();
/**
* Wrapper for {@link FileUtils#copyFile(File, File)}
*
* @param src an existing file to copy, must not be {@code null}
* @param dst the new file, must not be {@code null}
* @throws NullPointerException if source or destination is {@code null}
* @throws IOException if source or destination is invalid
* @throws IOException if an IO error occurs during copying
*/
protected void fileUtilsCopyFile(File src, File dst) throws IOException, NullPointerException {
FileUtils.copyFile(src, dst);
}
/**
* {@inheritDoc}
*/
public void clearAllCookies() {
this.getCookieHandler().clearAllCookies(this.getDriver());
}
/**
* {@inheritDoc}
*/
public boolean takeScreenshot(String filePath) {
WebDriver driver = this.getDriver();
if (null != driver) {
try {
File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
fileUtilsCopyFile(srcFile, new File(filePath));
return true;
}
catch (IOException | WebDriverException e) {
LOG.error("Could not take screenshot", e);
return false;
}
}
return false;
}
public void close() {
WebDriver driver = this.getDriver();
if (null != driver) {
driver.close();
}
}
/**
* {@inheritDoc}
*/
public WebElement findElement(By arg0) {
WebDriver driver = this.getDriver();
WebElement element = null;
if (null != driver) {
element = driver.findElement(arg0);
}
return element;
}
/**
* {@inheritDoc}
*/
public List findElements(By arg0) {
WebDriver driver = this.getDriver();
List elements = null;
if (null != driver) {
elements = driver.findElements(arg0);
}
return elements;
}
/**
* {@inheritDoc}
*/
public void get(String arg0) {
WebDriver driver = this.getDriver();
if (null != driver) {
driver.get(arg0);
}
}
/**
* {@inheritDoc}
*/
public String getCurrentUrl() {
WebDriver driver = this.getDriver();
String currentUrl = null;
if (null != driver) {
currentUrl = driver.getCurrentUrl();
}
return currentUrl;
}
/**
* {@inheritDoc}
*/
public String getPageSource() {
WebDriver driver = this.getDriver();
String pageSource = null;
if (null != driver) {
pageSource = driver.getPageSource();
}
return pageSource;
}
/**
* {@inheritDoc}
*/
public String getTitle() {
WebDriver driver = this.getDriver();
String title = null;
if (null != driver) {
title = driver.getTitle();
}
return title;
}
/**
* {@inheritDoc}
*/
public String getWindowHandle() {
WebDriver driver = this.getDriver();
String windowHandle = null;
if (null != driver) {
windowHandle = driver.getWindowHandle();
}
return windowHandle;
}
/**
* {@inheritDoc}
*/
public Set getWindowHandles() {
WebDriver driver = this.getDriver();
Set windowHandles = null;
if (null != driver) {
windowHandles = driver.getWindowHandles();
}
return windowHandles;
}
/**
* {@inheritDoc}
*/
public Options manage() {
WebDriver driver = this.getDriver();
Options manage = null;
if (null != driver) {
manage = driver.manage();
}
return manage;
}
/**
* {@inheritDoc}
*/
public Navigation navigate() {
WebDriver driver = this.getDriver();
Navigation navigate = null;
if (null != driver) {
navigate = driver.navigate();
}
return navigate;
}
/**
* {@inheritDoc}
*/
public void quit() {
WebDriver driver = this.getDriver();
if (null != driver) {
driver.quit();
}
}
/**
* {@inheritDoc}
*/
public TargetLocator switchTo() {
WebDriver driver = this.getDriver();
TargetLocator switchTo = null;
if (null != driver) {
switchTo = driver.switchTo();
}
return switchTo;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy