com.htmlhifive.pitalium.it.assertion.partialpage.CompareDifferentSizeTest.java Source code

Java tutorial

Introduction

Here is the source code for com.htmlhifive.pitalium.it.assertion.partialpage.CompareDifferentSizeTest.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.it.assertion.partialpage;

import java.util.ArrayList;
import java.util.List;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.htmlhifive.pitalium.core.PtlTestBase;
import com.htmlhifive.pitalium.core.config.ExecMode;
import com.htmlhifive.pitalium.core.config.PtlTestConfig;
import com.htmlhifive.pitalium.core.model.CompareTarget;
import com.htmlhifive.pitalium.core.model.ScreenArea;
import com.htmlhifive.pitalium.core.model.SelectorType;

/**
 * ???????????????
 */
public class CompareDifferentSizeTest extends PtlTestBase {

    private static final PtlTestConfig config = PtlTestConfig.getInstance();
    private static final String BASE_URL = config.getTestAppConfig().getBaseUrl();

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    /**
     * Expected?Actual???????????????<br>
     * ??????SET_EXPECTED?1??????<br>
     * IE711/FireFox/Chrome/Android 2.3, 4.0, 4.4/iOS 8.1<br>
     * ?assertView??????????
     */
    //@Test
    public void compareDifferentWidth() {
        driver.get(BASE_URL);

        // ACTUAL??????
        if (config.getEnvironment().getExecMode() == ExecMode.RUN_TEST) {
            final int widthToShrink = 1;
            WebElement about = driver.findElement(By.id("about"));
            driver.executeJavaScript("document.getElementById('about').style.width = '"
                    + (Integer.parseInt(about.getAttribute("clientWidth")) - widthToShrink) + "';");
            thrown.expect(AssertionError.class);
        }

        List<CompareTarget> targets = new ArrayList<CompareTarget>();
        targets.add(new CompareTarget(ScreenArea.of(SelectorType.CSS_SELECTOR, "#about")));
        assertionView.assertView("compareDifferentWidth", targets);
    }

    /**
     * Expected?Actual????????????????<br>
     * ??????SET_EXPECTED?1??????<br>
     * IE711/FireFox/Chrome/Android 2.3, 4.0, 4.4/iOS 8.1<br>
     * ?assertView??????????
     */
    @Test
    public void compareDifferentHeight() {
        driver.get(BASE_URL);

        // ACTUAL??????
        if (config.getEnvironment().getExecMode() == ExecMode.RUN_TEST) {
            final int heightToShrink = 1;
            WebElement about = driver.findElement(By.id("about"));
            driver.executeJavaScript("document.getElementById('about').style.width = '"
                    + (Integer.parseInt(about.getAttribute("clientWidth")) - heightToShrink) + "';");
            thrown.expect(AssertionError.class);
        }

        List<CompareTarget> targets = new ArrayList<CompareTarget>();
        targets.add(new CompareTarget(ScreenArea.of(SelectorType.CSS_SELECTOR, "#about")));
        assertionView.assertView("compareDifferentHeight", targets);
    }
}