View Javadoc
1   /*
2    * #%L
3    * wcm.io
4    * %%
5    * Copyright (C) 2017 wcm.io
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package io.wcm.qa.glnm.galen.util;
21  
22  import static io.wcm.qa.glnm.configuration.GaleniumConfiguration.getMediaQueryHeight;
23  import static io.wcm.qa.glnm.webdriver.WebDriverManagement.getCurrentDriver;
24  
25  import org.openqa.selenium.Dimension;
26  
27  import com.galenframework.browser.Browser;
28  import com.galenframework.browser.SeleniumBrowser;
29  import com.galenframework.config.GalenConfig;
30  import com.galenframework.config.GalenProperty;
31  import com.galenframework.utils.GalenUtils;
32  
33  import io.wcm.qa.glnm.context.GaleniumContext;
34  
35  /**
36   * Helper methods for dealing with Galen.
37   *
38   * @since 1.0.0
39   */
40  public final class GalenHelperUtil {
41  
42    private GalenHelperUtil() {
43      // do not instantiate
44    }
45  
46    /**
47     * <p>adjustViewport.</p>
48     *
49     * @param adjustBrowserViewportSize a boolean.
50     * @since 4.0.0
51     */
52    public static void adjustViewport(boolean adjustBrowserViewportSize) {
53      GalenConfig.getConfig().setProperty(
54          GalenProperty.GALEN_BROWSER_VIEWPORT_ADJUSTSIZE,
55          Boolean.toString(adjustBrowserViewportSize));
56    }
57  
58    /**
59     * <p>getBrowser.</p>
60     *
61     * @return a {@link com.galenframework.browser.Browser} object.
62     * @since 4.0.0
63     */
64    public static Browser getBrowser() {
65      return new SeleniumBrowser(GaleniumContext.getDriver());
66    }
67  
68    /**
69     * Turn Galen syntax size string into Selenium {@link org.openqa.selenium.Dimension}.
70     *
71     * @param size to parse
72     * @return Selenium representation of size
73     * @since 4.0.0
74     */
75    public static Dimension getDimension(String size) {
76      java.awt.Dimension parsedSize = GalenUtils.readSize(size);
77      return new Dimension(parsedSize.width, parsedSize.height);
78    }
79  
80    /**
81     * Resize the viewport.
82     *
83     * @param size to set viewport to
84     * @since 5.0.0
85     */
86    public static void resizeViewport(Dimension size) {
87      GalenUtils.resizeDriver(getCurrentDriver(), size.getWidth(), size.getHeight());
88    }
89  
90    /**
91     * Resize the viewport.
92     *
93     * @param width to set viewport to
94     * @since 5.0.0
95     */
96    public static void resizeViewport(int width) {
97      resizeViewport(new Dimension(width, getMediaQueryHeight()));
98      ;
99    }
100 
101 }