com.htmlhifive.pitalium.core.selenium.PtlFirefoxDriver.java Source code

Java tutorial

Introduction

Here is the source code for com.htmlhifive.pitalium.core.selenium.PtlFirefoxDriver.java

Source

/*
 * Copyright (C) 2015-2016 NS Solutions Corporation
 *
 * 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.htmlhifive.pitalium.core.selenium;

import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.List;

import org.apache.commons.lang3.tuple.Pair;
import org.openqa.selenium.WebElement;

import com.htmlhifive.pitalium.core.model.CompareTarget;
import com.htmlhifive.pitalium.core.model.ScreenshotParams;

/**
 * Firefox??{@link org.openqa.selenium.WebDriver}
 */
class PtlFirefoxDriver extends PtlWebDriver {

    /**
     * 
     * 
     * @param remoteAddress RemoteWebDriverServer?
     * @param capabilities Capability
     */
    PtlFirefoxDriver(URL remoteAddress, PtlCapabilities capabilities) {
        super(remoteAddress, capabilities);
    }

    @Override
    protected PtlWebElement newPtlWebElement() {
        return new PtlFirefoxWebElement();
    }

    @Override
    protected void trimNonMovePadding(List<List<BufferedImage>> allTargetScreenshots,
            List<Pair<CompareTarget, ScreenshotParams>> targetParams) {
        LOG.trace("[Trim non-move elements' padding]");
        // firefox?textarea?padding?????????padding?
        for (int i = 0; i < allTargetScreenshots.size(); i++) {
            PtlWebElement targetElement = targetParams.get(i).getRight().getTarget().getElement();
            if ("textarea".equals(targetElement.getTagName()) && targetParams.get(i).getLeft().isScrollTarget()) {
                List<BufferedImage> targetScreenshots = allTargetScreenshots.get(i);
                for (int j = 0; j < targetScreenshots.size(); j++) {
                    targetScreenshots.set(j, trimTargetPadding(targetElement, targetScreenshots.get(j), j,
                            targetScreenshots.size()));
                }
            }
        }
    }

    @Override
    protected void trimMovePadding(WebElement el, List<BufferedImage> images) {
        LOG.trace("[Trim move element's padding]");
        // firefox?textarea?padding?????????padding?
        if ("textarea".equals(el.getTagName())) {
            for (int i = 0; i < images.size(); i++) {
                images.set(i, trimTargetPadding(el, images.get(i), i, images.size()));
            }
        }
    }

    @Override
    protected int calcTrimTop(int imageHeight, long scrollAmount, PtlWebElement targetElement,
            double currentScale) {
        int trimTop = super.calcTrimTop(imageHeight, scrollAmount, targetElement, currentScale);
        // firefox?textarea?padding??????paddingtrim??
        if ("textarea".equals(targetElement.getTagName())) {
            WebElementPadding padding = targetElement.getPadding();
            trimTop -= padding.getTop();
        }
        LOG.trace("(CalcTrimTop) imageHeight: {}, scrollAmount: {}, element: {} => {}", imageHeight, scrollAmount,
                targetElement, trimTop);
        return trimTop;
    }
}