How to use values method of org.openqa.selenium.Enum PageLoadStrategy class

Best Selenium code snippet using org.openqa.selenium.Enum PageLoadStrategy.values

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package com.sss.testing.utils.webdriver;
2
3import com.codeborne.selenide.Configuration;
4import org.openqa.selenium.chrome.ChromeOptions;
5import org.openqa.selenium.firefox.FirefoxDriver;
6import org.openqa.selenium.firefox.FirefoxProfile;
7import org.openqa.selenium.remote.CapabilityType;
8import org.openqa.selenium.remote.DesiredCapabilities;
9
10import javax.annotation.Nonnull;
11import java.util.HashMap;
12
13import static com.codeborne.selenide.Configuration.pageLoadStrategy;
14
15/**
16 * Created by sshtubey on 03.03.2017.
17 */
18public enum WDType {
19
20    /**
21     * Firefox capabilities settings
22     */
23    Firefox("firefox") {
24        @Override
25        public DesiredCapabilities capabilities(WDSettings wdSettings) {
26            FirefoxProfile firefoxProfile = new FirefoxProfile();
27            firefoxProfile.setPreference("security.warn_viewing_mixed", false);
28            firefoxProfile.setPreference("security.mixed_content.block_active_content", false);
29            firefoxProfile.setPreference("plugins.update.url", "null");
30            firefoxProfile.setPreference("plugins.update.notifyUser", false);
31            firefoxProfile.setPreference("intl.accept_languages", "ru");
32
33            /*
34             * Never ask for proxy
35             */
36            firefoxProfile.setPreference("network.proxy.type", 0);
37
38            /*
39             * Set Location to store files after downloading.
40             */
41            String downloadPath = wdSettings.getDownloadPath();
42            firefoxProfile.setPreference("browser.download.dir", downloadPath);
43            firefoxProfile.setPreference("browser.download.folderList", 2);
44
45            /*
46             * Set Preference to not show file download confirmation dialogue
47             * using MIME types Of different file extension types.
48             */
49            firefoxProfile.setPreference(
50                    "browser.helperApps.neverAsk.saveToDisk",
51                    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;"//MIME types Of MS Excel File.
52                            + "application/pdf;"
53                            + "application/vnd.openxmlformats-officedocument.wordprocessingml.document;" //MIME types Of MS doc File.
54                            + "text/plain;"
55                            + "text/csv"
56            );
57            firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
58            firefoxProfile.setPreference("pdfjs.disabled", true);
59
60            DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
61            desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
62            desiredCapabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);
63            desiredCapabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
64            return desiredCapabilities;
65        }
66    },
67
68    /**
69     * Chrome capabilities settings
70     */
71    Chrome("chrome") {
72        @Override
73        public DesiredCapabilities capabilities(WDSettings wdSettings) {
74            ChromeOptions options = new ChromeOptions();
75            options.addArguments(String.format("--lang=%s", wdSettings.getLanguageSettings()));
76            options.addArguments("--start-maximized");
77
78            String downloadPath = wdSettings.getDownloadPath();
79            HashMap<String, Object> chromePrefs = new HashMap<>();
80            chromePrefs.put("profile.default_content_settings.popups", 0);
81            chromePrefs.put("download.default_directory", downloadPath);
82            chromePrefs.put("download.prompt_for_download", false);
83            chromePrefs.put("download.directory_upgrade", true);
84            chromePrefs.put("savefile.default_directory", downloadPath);
85            chromePrefs.put("savefile.type", 1);
86            chromePrefs.put("plugins.always_open_pdf_externally", true); /* Disable PDF viewer */
87            if (Configuration.remote != null) {
88                chromePrefs.put("profile.default_content_setting_values.popups", 1);
89            }
90            options.setExperimentalOption("prefs", chromePrefs);
91
92            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
93            capabilities.setCapability(CapabilityType.PAGE_LOAD_STRATEGY, pageLoadStrategy);
94            capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
95            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
96            return capabilities;
97        }
98    },
99
100    /**
101     * Opera capabilities settings
102     */
103    Opera("opera") {
104        @Override
105        public DesiredCapabilities capabilities(WDSettings wdSettings) {
106            DesiredCapabilities capabilities = DesiredCapabilities.operaBlink();
107            capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
108            return capabilities;
109        }
110    };
111
112    ////////////////////////////////////////////////////////////////
113    // ATTRIBUTES
114
115    private final String browserType;
116    private final boolean remoteSupported;
117
118    ////////////////////////////////////////////////////////////////
119    // CONSTRUCTORS
120
121    private WDType(String browserType) {
122        this(browserType, true);
123    }
124
125    private WDType(String browserType, boolean remoteSupported) {
126        this.browserType = browserType;
127        this.remoteSupported = remoteSupported;
128    }
129
130    ////////////////////////////////////////////////////////////////
131    // METHODS
132
133    /**
134     * @return capabilities
135     */
136    public abstract DesiredCapabilities capabilities(WDSettings wdSettings);
137
138    /**
139     * @param browserType browser type
140     * @return webdriver type
141     */
142    public static WDType forBrowserType(@Nonnull String browserType) {
143        String type = browserType.toLowerCase();
144        for (WDType driverType : values()) {
145            if (driverType.browserType.equals(type)) {
146                return driverType;
147            }
148        }
149        throw new IllegalArgumentException("Unknown browser type '" + browserType + "'");
150    }
151
152    /**
153     * @param browserType browser type
154     * @return is know browser type
155     */
156    public static boolean isKnownBrowserType(@Nonnull String browserType) {
157        try {
158            if (forBrowserType(browserType) != null) {
159                return true;
160            }
161        } catch (IllegalArgumentException e) {
162            // ignore the exception
163        }
164        return false;
165    }
166
167    ////////////////////////////////////////////////////////////////
168    // GETTERS AND SETTERS
169
170    public String getBrowserType() {
171        return browserType;
172    }
173
174    public boolean isRemoteSupported() {
175        return remoteSupported;
176    }
177}
178
Full Screen
copy
1// Licensed to the Software Freedom Conservancy (SFC) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The SFC licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18package org.openqa.selenium;
19
20public enum PageLoadStrategy {
21
22  NONE ("none"),
23  EAGER ("eager"),
24  NORMAL ("normal")
25  ;
26
27  private String text;
28
29  private PageLoadStrategy(String text) {
30    this.text = text;
31  }
32
33  @Override
34  public String toString() {
35    return String.valueOf(text);
36  }
37
38  public static PageLoadStrategy fromString(String text) {
39    if (text != null) {
40      for (PageLoadStrategy b : PageLoadStrategy.values()) {
41        if (text.equalsIgnoreCase(b.text)) {
42          return b;
43        }
44      }
45    }
46    return null;
47  }
48}
49
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in Enum-PageLoadStrategy

Trigger values code on LambdaTest Cloud Grid

Execute automation tests with values on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie