All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mark59.selenium.drivers.SeleniumDriverBuilder Maven / Gradle / Ivy

There is a newer version: 5.7
Show newest version
/*
 *  Copyright 2019 Insurance Australia Group Limited
 *  
 *  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.mark59.selenium.drivers;

import java.nio.file.Path;

import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.remote.service.DriverService;

import com.mark59.core.factories.DriverBuilder;
import com.mark59.selenium.corejmeterimpl.SeleniumAbstractJavaSamplerClient;

/**
 * Base builder class for configuring Selenium web drivers.
 * 
 * 

* Specifies configurable capabilities that the SeleniumDriverFactory knows how * to use *

* @author Michael Cohen * @author Philip Webb * Written: Australian Winter 2019 */ public abstract class SeleniumDriverBuilder implements DriverBuilder { protected static final String HEADLESS = "HEADLESS"; protected static final String ALTERNATE = "ALTERNATE"; protected static final String VERBOSE = "VERBOSE"; protected static final String NORMALLOAD = "NORMALLOAD"; protected DriverService.Builder serviceBuilder; protected O options; /** * Sets the path to the WebDriver executable that is being configured. * * @param of T * @param driverPath driver path to the WebDriver executable * @return this */ public abstract > T setDriverExecutable(Path driverPath); /** * Sets whether or not the Selenium WebDriver will start in headless mode, * meaning that no GUI browser will be used. * *

By default, headless mode will be set to 'TRUE' by the factory.

* * @param of T * @param isHeadless indicates if the driver should start in headless mode * @return this */ public abstract > T setHeadless(boolean isHeadless); /** * Sets the page load strategy to be used by the WebDriver * *

Page load strategy determines when the WebDriver will consider a page "loaded"

* *

* Possible page load strategies are: *

    *
  • normal : WebDriver will wait for the page load event to fire
  • *
  • eager : WebDriver will wait for DOMContentLoaded event to fire
  • *
  • none : WebDriver will wait for the initial html load to complete
  • *
* *

* Not all load strategies are implemented for all WebDrivers. In particular, at time of * writing ChromeDriver only implements none and normal. *

* Therefore when setting the PAGE_LOAD_STRATEGY parameter for a selenium script, the values to use will be: *

    *
  • PageLoadStrategy.NORMAL.toString() - this is the default, or *
  • PageLoadStrategy.NONE.toString() *
*

* It is recommended that the "normal" page load strategy be used in most cases. * For more advanced/difficult web pages,the "none" strategy will need to be paired with a check to verify a desired * element has loaded (else it will likely return in just a few milliseconds).
*

* * @see PageLoadStrategy * @param of T * @param strategy type of wait strategy the WebDriver will adopt * @return this */ public abstract > T setPageLoadStrategy(PageLoadStrategy strategy); /** * Sets the page load strategy used by the WebDriver to "none". * @see #setPageLoadStrategy * @param of T * @return this */ public abstract > T setPageLoadStrategyNone(); /** * Sets the page load strategy used by the WebDriver to "normal". (current default) * @see #setPageLoadStrategy * @param of T * @return this */ public abstract > T setPageLoadStrategyNormal(); /** *

Caters for the direct setting of the browser size via script argument BROWSER_DIMENSIONS.

* * The argument value needs to be two integers, comma separated, otherwise a default of 1920,1080 will be used. * *

For example to set a browser width x height of 800 x 600 (which incidentally, is the Chrome Headless 'maximize' default value * being overridden with 1920,1080 in Mark59 ) you specify: *

800,600

* *

Note that --start-maximized is not available - as just noted you can use "800,600" if you want to achieve the same * effect in headless mode * * @see org.openqa.selenium.chrome.ChromeOptions#addArguments(java.util.List) * @see SeleniumAbstractJavaSamplerClient * @see org.openqa.selenium.Dimension * * @param of T * @param width of the browser * @param height of the browser * @return this */ public abstract > T setSize(int width, int height); /** *

Overrides the proxy to be used by the selenium WebDriver, and can passed via the 'PROXY' parameter. * The proxy settings need to be passed as a set of comma-delimited key-value pairs, * and are passed directly to the selenium's proxy class constructor (strings values only)

* *

For example, defining a proxy pac url: *
     proxyType=PAC,proxyAutoconfigUrl=http://myawesomecompany.corp/proxy.pac

* *

Another example. Defining a http / https(ssl) proxy vai the proxy host name *
     httpProxy=http://myawesomecompany.corp:8080,sslProxy=http://myawesomecompany.corp:8080

*      Note: for Chrome at time of writing server user/password entry is not catered for with http and ssl proxy server setup.

* *

Hint: To not use a proxy server and always make direct connections, use chrome option argument "--no-proxy-server" in the ADDITIONAL_OPTIONS * parameter

*

Hint: To reset the value to blank in the Java Request PROXY option in Jmeter (ie, no proxy override), just type a space into the PROXY value field.

* * @param of T * @param proxy comma delimited list of proxy settings for WebDriver * * @see org.openqa.selenium.Proxy * @see #setAdditionalOptions(java.util.List) * @see SeleniumAbstractJavaSamplerClient * @return this */ public abstract > T setProxy(Proxy proxy); /** *

Caters for the direct setting of any additional driver options from the jmeter additional parameters. * Intended for use with the Chrome Driver.

* *

The input string needs to be a comma delimited list for multiple options. * For example, to set a proxy pac url and activate the disable extensions option, the "ADDITIONAL OPTIONS" parameter * for the SeleniumAbstractJavaSamplerClient based test script can be entered as : *

--proxy-pac-url=http://myawesomecompany.corp/proxy.pac,--disable-extensions

* *

(note that a proxy override can be set using the "PROXY" parameter, just shown here as an example)
* * Another example would be to run Chrome in incognito mode, set the "ADDITIONAL OPTIONS" parameter as : *

--incognito

* * @see org.openqa.selenium.chrome.ChromeOptions#addArguments(java.util.List) * @see SeleniumAbstractJavaSamplerClient * * @param of T * @param arguments options * @return this */ public abstract > T setAdditionalOptions(java.util.List arguments); /** * *

Only implemented for Firefox. Primary purpose is to redirect gekodriver's copious error logging off the console..

*

From a selenium script, the only implemented jmeter parameter is 'WRITE_FFOX_BROWSER_LOGFILE'. Values are: *

    *
  • false : suppresses Firefox error logging (the default)
  • *
  • true : depending on log setting, logs may to written to a log directory (refer to FireFoxDriverBuilder) *
* @param of T * @param isWriteBrowserLogFile see above * @return this */ public abstract > T setWriteBrowserLogfile(boolean isWriteBrowserLogFile); /** * Sets the path to an alternate version of the target browser, such as a * development version of chrome. * *

* If not set, will use the main installation of the expected browser *

* @param of T * @param browserExecutablePath executable path to the browser executable to be used * @return this */ public abstract > T setAlternateBrowser(Path browserExecutablePath); /** * Sets whether or not the Selenium WebDriver will have performance logging * turned on. * *

By default, WebDriver performance logging is turned off.

* * @param of T * @param isVerbose indicates if more detailed Webdriver performance logs are * required, such as requests sent and received. * @return this */ public abstract > T setVerbosePerformanceLoggingLogging(boolean isVerbose); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy