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

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

Run Selenium automation tests on LambdaTest cloud grid

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

copy
1package Camargo.Automacao.BDD.Utils;
2
3import io.github.bonigarcia.wdm.WebDriverManager;
4import org.junit.Assert;
5import org.openqa.selenium.PageLoadStrategy;
6import org.openqa.selenium.WebDriver;
7import org.openqa.selenium.chrome.ChromeDriver;
8import org.openqa.selenium.chrome.ChromeOptions;
9import org.openqa.selenium.firefox.FirefoxDriver;
10import org.openqa.selenium.firefox.FirefoxOptions;
11import org.openqa.selenium.ie.InternetExplorerDriver;
12import org.openqa.selenium.ie.InternetExplorerOptions;
13
14
15public class WebDriverFactory {
16	
17	static WebDriver driver;
18
19	public enum Navegador {
20
21		CHROME,
22		FIREFOX,
23		INTERNETEXPLORER,
24		SAFARI
25
26	}
27	
28	public static WebDriver CriarWebDriver(Navegador navegador, String pathWebDriver) {
29		
30		try {
31			
32			PageLoadStrategy pageLoadStrategy = PageLoadStrategy.NORMAL;
33			
34			switch (navegador) {
35			case CHROME:
36				System.setProperty("webdriver.chrome.driver", pathWebDriver);
37				ChromeOptions chromeOptions = new ChromeOptions();
38				chromeOptions.setPageLoadStrategy(pageLoadStrategy);
39				driver = new ChromeDriver(chromeOptions);
40				break;
41			case FIREFOX:
42				System.setProperty("webdriver.gecko.driver", pathWebDriver);
43				FirefoxOptions firefoxOptions = new FirefoxOptions();
44				firefoxOptions.setPageLoadStrategy(pageLoadStrategy);
45				driver = new FirefoxDriver(firefoxOptions);
46				break;
47			case INTERNETEXPLORER:
48				System.setProperty("webdriver.ie.driver", pathWebDriver);
49				InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions();
50				internetExplorerOptions.setPageLoadStrategy(pageLoadStrategy);
51				driver = new InternetExplorerDriver(internetExplorerOptions);
52				break;
53			default:
54				Assert.fail("Não foi possível iniciar o WebDriver: " + navegador.toString());
55				break;
56			}
57			
58		} catch (Exception e) {
59			Assert.fail(e.toString());
60		}
61		
62		return driver;
63	}
64	
65	
66	public static WebDriver CriarWebDriver(Navegador navegador) {
67		
68		try {
69			
70			PageLoadStrategy pageLoadStrategy = PageLoadStrategy.NORMAL;
71			
72			switch (navegador) {
73			case CHROME:
74				WebDriverManager.chromedriver().setup();
75				ChromeOptions chromeOptions = new ChromeOptions();
76				chromeOptions.setPageLoadStrategy(pageLoadStrategy);
77				driver = new ChromeDriver(chromeOptions);
78				break;
79			case FIREFOX:
80				WebDriverManager.firefoxdriver().setup();
81				FirefoxOptions firefoxOptions = new FirefoxOptions();
82				firefoxOptions.setPageLoadStrategy(pageLoadStrategy);
83				driver = new FirefoxDriver(firefoxOptions);
84				break;
85			case INTERNETEXPLORER:
86				WebDriverManager.iedriver().setup();
87				InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions();
88				internetExplorerOptions.setPageLoadStrategy(pageLoadStrategy);
89				driver = new InternetExplorerDriver(internetExplorerOptions);
90				break;
91			default:
92				Assert.fail("Não foi possível iniciar o WebDriver: " + navegador.toString());
93				break;
94			}
95			
96		} catch (Exception e) {
97			Assert.fail(e.toString());
98		}
99		
100		return driver;
101	}
102
103}
104
Full Screen
copy
1package io.github.burakkaygusuz.config;
2
3import org.openqa.selenium.PageLoadStrategy;
4import org.openqa.selenium.chrome.ChromeDriverService;
5import org.openqa.selenium.chrome.ChromeOptions;
6import org.openqa.selenium.firefox.FirefoxDriver;
7import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
8import org.openqa.selenium.firefox.FirefoxOptions;
9import org.openqa.selenium.firefox.FirefoxProfile;
10import org.openqa.selenium.logging.LogType;
11import org.openqa.selenium.logging.LoggingPreferences;
12import org.openqa.selenium.remote.AbstractDriverOptions;
13import org.openqa.selenium.remote.CapabilityType;
14import org.openqa.selenium.remote.RemoteWebDriver;
15
16import java.net.MalformedURLException;
17import java.net.URL;
18import java.util.Collections;
19import java.util.HashMap;
20import java.util.Map;
21import java.util.logging.Level;
22import java.util.logging.Logger;
23
24public enum Browsers {
25
26    CHROME {
27        @Override
28        protected RemoteWebDriver createDriver(String spec) throws MalformedURLException {
29            return new RemoteWebDriver(new URL(spec), getOptions());
30        }
31
32        @Override
33        protected ChromeOptions getOptions() {
34            Logger.getLogger("org.openqa.selenium").setLevel(Level.SEVERE);
35
36            Map<String, Object> prefs = new HashMap<>();
37            prefs.put("profile.default_content_setting_values.notifications", 2);
38            prefs.put("profile.managed_default_content_settings.javascript", 1);
39            prefs.put("credentials_enable_service", false);
40            prefs.put("profile.password_manager_enabled", false);
41
42            LoggingPreferences chromeLogPrefs = new LoggingPreferences();
43            chromeLogPrefs.enable(LogType.PERFORMANCE, Level.OFF);
44
45            ChromeOptions chromeOptions = new ChromeOptions();
46
47            chromeOptions.setCapability(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
48            chromeOptions.setCapability(ChromeDriverService.CHROME_DRIVER_VERBOSE_LOG_PROPERTY, "true");
49            chromeOptions.setCapability(CapabilityType.LOGGING_PREFS, chromeLogPrefs);
50            chromeOptions.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
51            chromeOptions.addArguments("--disable-gpu", "--disable-logging", "--disable-dev-shm-usage");
52            chromeOptions.setAcceptInsecureCerts(true);
53            chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
54            chromeOptions.setHeadless(HEADLESS);
55            chromeOptions.setExperimentalOption("prefs", prefs);
56
57            return chromeOptions;
58        }
59    },
60
61    FIREFOX {
62        @Override
63        protected RemoteWebDriver createDriver(String spec) throws MalformedURLException {
64            return new RemoteWebDriver(new URL(spec), getOptions());
65        }
66
67        @Override
68        protected FirefoxOptions getOptions() {
69            Logger.getLogger("org.openqa.selenium").setLevel(Level.SEVERE);
70
71            FirefoxOptions firefoxOptions = new FirefoxOptions();
72            FirefoxProfile firefoxProfile = new FirefoxProfile();
73
74            firefoxProfile.setPreference(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, true);
75            firefoxProfile.setAcceptUntrustedCertificates(true);
76            firefoxProfile.setAssumeUntrustedCertificateIssuer(true);
77
78            LoggingPreferences firefoxLogPrefs = new LoggingPreferences();
79            firefoxLogPrefs.enable(LogType.PERFORMANCE, Level.OFF);
80
81            firefoxOptions.setCapability(CapabilityType.LOGGING_PREFS, firefoxLogPrefs);
82            firefoxOptions.setCapability(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
83            firefoxOptions.setLogLevel(FirefoxDriverLogLevel.ERROR);
84            firefoxOptions.setProfile(firefoxProfile);
85            firefoxOptions.addPreference("dom.webnotifications.enabled", false);
86            firefoxOptions.addPreference("gfx.direct2d.disabled", true);
87            firefoxOptions.addPreference("layers.acceleration.force-enabled", true);
88            firefoxOptions.addPreference("javascript.enabled", true);
89            firefoxOptions.setHeadless(HEADLESS);
90
91            return firefoxOptions;
92        }
93    };
94
95    @Override
96    public String toString() {
97        return super.toString().toLowerCase();
98    }
99
100    private final static boolean HEADLESS = Boolean.getBoolean("headless");
101
102    protected abstract RemoteWebDriver createDriver(String spec) throws MalformedURLException;
103
104    protected abstract AbstractDriverOptions<?> getOptions();
105
106}
107
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 toString code on LambdaTest Cloud Grid

Execute automation tests with toString 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