Search in sources :

Example 1 with LoggingPreferences

use of org.openqa.selenium.logging.LoggingPreferences in project Bytecoder by mirkosertic.

the class BytecoderUnitTestRunner method newDriverForTest.

private WebDriver newDriverForTest() {
    ChromeOptions theOptions = new ChromeOptions();
    theOptions.addArguments("headless");
    theOptions.addArguments("disable-gpu");
    LoggingPreferences theLoggingPreferences = new LoggingPreferences();
    theLoggingPreferences.enable(LogType.BROWSER, Level.ALL);
    theOptions.setCapability(CapabilityType.LOGGING_PREFS, theLoggingPreferences);
    DesiredCapabilities theCapabilities = DesiredCapabilities.chrome();
    theCapabilities.setCapability(ChromeOptions.CAPABILITY, theOptions);
    return new RemoteWebDriver(DRIVERSERVICE.getUrl(), theCapabilities);
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions)

Example 2 with LoggingPreferences

use of org.openqa.selenium.logging.LoggingPreferences in project jmeter-plugins by undera.

the class ChromeDriverConfig method createCapabilities.

Capabilities createCapabilities() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, createProxy());
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    if (isAndroidEnabled() || isHeadlessEnabled()) {
        // Map<String, String> chromeOptions = new HashMap<String, String>();
        // chromeOptions.put("androidPackage", "com.android.chrome");
        ChromeOptions chromeOptions = new ChromeOptions();
        if (isAndroidEnabled()) {
            chromeOptions.setExperimentalOption("androidPackage", "com.android.chrome");
        }
        if (isHeadlessEnabled()) {
            chromeOptions.addArguments("--headless");
        }
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    }
    return capabilities;
}
Also used : DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions)

Example 3 with LoggingPreferences

use of org.openqa.selenium.logging.LoggingPreferences in project selenium_java by sergueik.

the class AppTest method setupBeforeSuite.

@BeforeSuite(alwaysRun = true)
public void setupBeforeSuite(ITestContext context) throws InterruptedException, MalformedURLException {
    selenium_host = context.getCurrentXmlTest().getParameter("selenium.host");
    selenium_port = context.getCurrentXmlTest().getParameter("selenium.port");
    selenium_browser = context.getCurrentXmlTest().getParameter("selenium.browser");
    selenium_run = context.getCurrentXmlTest().getParameter("selenium.run");
    // Remote Configuration
    if (selenium_browser.compareToIgnoreCase("remote") == 0) {
        String hub = "http://" + selenium_host + ":" + selenium_port + "/wd/hub";
        LoggingPreferences logging_preferences = new LoggingPreferences();
        logging_preferences.enable(LogType.BROWSER, Level.ALL);
        logging_preferences.enable(LogType.CLIENT, Level.INFO);
        logging_preferences.enable(LogType.SERVER, Level.INFO);
        if (selenium_browser.compareToIgnoreCase("chrome") == 0) {
            DesiredCapabilities capabilities = new DesiredCapabilities("chrome", "", Platform.ANY);
            capabilities.setBrowserName("chrome");
            capabilities.setCapability(CapabilityType.LOGGING_PREFS, logging_preferences);
            try {
                driver = new RemoteWebDriver(new URL("http://" + selenium_host + ":" + selenium_port + "/wd/hub"), capabilities);
            } catch (MalformedURLException ex) {
            }
        } else {
            DesiredCapabilities capabilities = new DesiredCapabilities("firefox", "", Platform.ANY);
            capabilities.setBrowserName("firefox");
            FirefoxProfile profile = new ProfilesIni().getProfile("default");
            capabilities.setCapability("firefox_profile", profile);
            capabilities.setCapability(CapabilityType.LOGGING_PREFS, logging_preferences);
            try {
                driver = new RemoteWebDriver(new URL("http://" + selenium_host + ":" + selenium_port + "/wd/hub"), capabilities);
            } catch (MalformedURLException ex) {
            }
        }
    } else // standalone
    {
        if (selenium_browser.compareToIgnoreCase("chrome") == 0) {
            System.setProperty("webdriver.chrome.driver", "c:/java/selenium/chromedriver.exe");
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            LoggingPreferences logging_preferences = new LoggingPreferences();
            logging_preferences.enable(LogType.BROWSER, Level.ALL);
            capabilities.setCapability(CapabilityType.LOGGING_PREFS, logging_preferences);
            /*
			   prefs.js:user_pref("extensions.logging.enabled", true);
			   user.js:user_pref("extensions.logging.enabled", true);
			 */
            driver = new ChromeDriver(capabilities);
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        } else {
            DesiredCapabilities capabilities = DesiredCapabilities.firefox();
            LoggingPreferences logging_preferences = new LoggingPreferences();
            logging_preferences.enable(LogType.BROWSER, Level.ALL);
            capabilities.setCapability(CapabilityType.LOGGING_PREFS, logging_preferences);
            driver = new FirefoxDriver(capabilities);
        }
    }
    try {
        driver.manage().window().setSize(new Dimension(600, 800));
        driver.manage().timeouts().pageLoadTimeout(50, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    } catch (Exception ex) {
        System.out.println(ex.toString());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ProfilesIni(org.openqa.selenium.firefox.internal.ProfilesIni) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) Dimension(org.openqa.selenium.Dimension) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) URL(java.net.URL) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 4 with LoggingPreferences

use of org.openqa.selenium.logging.LoggingPreferences in project scout.rt by eclipse.

the class SeleniumDriver method setUpDriver.

public static WebDriver setUpDriver() {
    // web-driver executable
    String webdriverChromeDriver = System.getProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY);
    if (StringUtility.isNullOrEmpty(webdriverChromeDriver)) {
        webdriverChromeDriver = OS.isFamilyWindows() ? "/seleniumDrivers/chromedriver.exe" : "/seleniumDrivers/chromedriver";
    }
    File chromeDriver = new File(webdriverChromeDriver);
    if (!chromeDriver.exists()) {
        System.out.println("Chrome driver executable not found at path: " + chromeDriver);
        URL webdriverChromeDriverResource = SeleniumDriver.class.getResource(webdriverChromeDriver);
        if (webdriverChromeDriverResource != null) {
            chromeDriver = new File(webdriverChromeDriverResource.getFile());
            webdriverChromeDriver = chromeDriver.getAbsolutePath();
        }
    }
    if (!StringUtility.matches(webdriverChromeDriver, ".+\\.exe", Pattern.CASE_INSENSITIVE) && chromeDriver.exists() && !chromeDriver.canExecute()) {
        chromeDriver.setExecutable(true);
    }
    System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, webdriverChromeDriver);
    logProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, webdriverChromeDriver);
    // log-file for web-driver
    File tmpDir = new File(System.getProperty("java.io.tmpdir"));
    File logFile = new File(tmpDir, "webdriver.log");
    String logFilePath = logFile.getAbsolutePath();
    System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, logFilePath);
    logProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, logFilePath);
    // set web-driver in verbose mode
    System.setProperty(ChromeDriverService.CHROME_DRIVER_VERBOSE_LOG_PROPERTY, "true");
    logProperty(ChromeDriverService.CHROME_DRIVER_VERBOSE_LOG_PROPERTY, "true");
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    // Prepare options
    ChromeOptions options = new ChromeOptions();
    String chromeBinary = System.getProperty("chrome.binary");
    logProperty("chrome.binary", chromeBinary);
    if (StringUtility.hasText(chromeBinary)) {
        options.setBinary(chromeBinary);
    }
    options.addArguments("--lang=en");
    options.addArguments("--verbose");
    options.addArguments("--disable-infobars");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    // Set logging preferences (see BrowserLogRule)
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    // TODO [7.0] BSH Remove workaround, when Chrome bug is fixed
    // <WORKAROUND> https://bugs.chromium.org/p/chromedriver/issues/detail?id=1552
    Map<String, String> env = new HashMap<>();
    env.put("LANG", "en_US.UTF-8");
    System.out.println("Using custom environment variables for driver: " + new JSONObject(env).toString(2));
    RemoteWebDriver driver = new ChromeDriver(new ChromeDriverService.Builder().usingAnyFreePort().withEnvironment(// <--
    env).build(), capabilities);
    // RemoteWebDriver driver = new ChromeDriver(options)
    // </WORKAROUND>
    driver.manage().timeouts().setScriptTimeout(10000, TimeUnit.SECONDS);
    // Set window size roughly to the minimal supported screen size
    // (1280x1024 minus some borders for browser toolbar and windows taskbar)
    // Add extra 50 pixel height, because of yellow bar "Chrome is being controlled..." which comes up since v 65.0.3325
    // even tough the disable-infobars property is set - doesn't work anymore :-(
    driver.manage().window().setPosition(new Point(0, 0));
    driver.manage().window().setSize(new Dimension(1200, 900 + 50));
    Capabilities caps = driver.getCapabilities();
    System.out.println("Selenium driver configured with driver=" + driver.getClass().getName() + " browser.name=" + caps.getBrowserName() + " browser.version=" + caps.getVersion());
    return driver;
}
Also used : HashMap(java.util.HashMap) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) URL(java.net.URL) JSONObject(org.json.JSONObject) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File)

Example 5 with LoggingPreferences

use of org.openqa.selenium.logging.LoggingPreferences in project ghostdriver by detro.

the class LogTest method setCustomHeaders.

@BeforeClass
public static void setCustomHeaders() {
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    logPrefs.enable("har", Level.ALL);
    sCaps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
}
Also used : LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) BeforeClass(org.junit.BeforeClass)

Aggregations

LoggingPreferences (org.openqa.selenium.logging.LoggingPreferences)10 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)6 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)6 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)5 File (java.io.File)4 URL (java.net.URL)3 Dimension (org.openqa.selenium.Dimension)3 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)3 HashMap (java.util.HashMap)2 JSONObject (org.json.JSONObject)2 BeforeClass (org.junit.BeforeClass)2 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 SourceFile (com.google.javascript.jscomp.SourceFile)1 JenkinsServer (com.offbytwo.jenkins.JenkinsServer)1 ActivityPageFactory (io.blueocean.ath.factory.ActivityPageFactory)1 BranchPageFactory (io.blueocean.ath.factory.BranchPageFactory)1 ClassicPipelineFactory (io.blueocean.ath.factory.ClassicPipelineFactory)1 FreestyleJobFactory (io.blueocean.ath.factory.FreestyleJobFactory)1 MultiBranchPipelineFactory (io.blueocean.ath.factory.MultiBranchPipelineFactory)1 PullRequestsPageFactory (io.blueocean.ath.factory.PullRequestsPageFactory)1