use of org.openqa.selenium.chrome.ChromeDriver in project chrome_page_performance_sqlite_java by sergueik.
the class ChromePagePerformanceUtilTest method beforeClass.
@SuppressWarnings("deprecation")
@BeforeClass
public static void beforeClass() throws IOException {
getOsName();
System.setProperty("webdriver.chrome.driver", osName.toLowerCase().startsWith("windows") ? new File("c:/java/selenium/chromedriver.exe").getAbsolutePath() : "/var/run/chromedriver");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
Map<String, Object> chromePrefs = new HashMap<>();
chromePrefs.put("profile.default_content_settings.popups", 0);
String downloadFilepath = System.getProperty("user.dir") + System.getProperty("file.separator") + "target" + System.getProperty("file.separator");
chromePrefs.put("download.default_directory", downloadFilepath);
chromePrefs.put("enableNetwork", "true");
options.setExperimentalOption("prefs", chromePrefs);
for (String option : (new String[] { "allow-running-insecure-content", "allow-insecure-localhost", "enable-local-file-accesses", "disable-notifications", /* "start-maximized" , */
"browser.download.folderList=2", "--browser.helperApps.neverAsk.saveToDisk=image/jpg,text/csv,text/xml,application/xml,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/excel,application/pdf", String.format("browser.download.dir=%s", downloadFilepath) /* "user-data-dir=/path/to/your/custom/profile" , */
})) {
options.addArguments(option);
}
// options for headless
if (headless) {
// headless option arguments
for (String option : (osName.toLowerCase().startsWith("windows")) ? new String[] { "headless", "disable-gpu", "disable-plugins", "window-size=1200x600", "window-position=-9999,0" } : new String[] { "headless", "disable-gpu", "remote-debugging-port=9222", "window-size=1200x600" }) {
options.addArguments(option);
}
// on Windows need ChromeDriver 2.31 / Chrome 60 to support headless
// With earlier versions of chromedriver: chrome not reachable...
// https://developers.google.com/web/updates/2017/04/headless-chrome
// https://stackoverflow.com/questions/43880619/headless-chrome-and-selenium-on-windows
}
//
if (useChromeLogging) {
LoggingPreferences loggingPreferences = new LoggingPreferences();
loggingPreferences.enable(LogType.PERFORMANCE, Level.ALL);
capabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);
}
capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver = new ChromeDriver(capabilities);
assertThat(driver, notNullValue());
}
use of org.openqa.selenium.chrome.ChromeDriver in project wechat by dllwh.
the class SeleniumHandler method getChromeDriver.
/**
* @方法描述: 获取Chrome驱动
* @return
*/
private WebDriver getChromeDriver() {
String path = genPath + props.getProperty("chromeDriver");
System.getProperties().setProperty("webdriver.chrome.driver", path);
ChromeDriver driver = new ChromeDriver();
return driver;
}
use of org.openqa.selenium.chrome.ChromeDriver in project webmagic by code4craft.
the class WebDriverPool method configure.
/**
* Configure the GhostDriver, and initialize a WebDriver instance. This part
* of code comes from GhostDriver.
* https://github.com/detro/ghostdriver/tree/master/test/java/src/test/java/ghostdriver
*
* @author bob.li.0718@gmail.com
* @throws IOException
*/
public void configure() throws IOException {
// Read config file
sConfig = new Properties();
String configFile = DEFAULT_CONFIG_FILE;
if (System.getProperty("selenuim_config") != null) {
configFile = System.getProperty("selenuim_config");
}
sConfig.load(new FileReader(configFile));
// Prepare capabilities
sCaps = new DesiredCapabilities();
sCaps.setJavascriptEnabled(true);
sCaps.setCapability("takesScreenshot", false);
String driver = sConfig.getProperty("driver", DRIVER_PHANTOMJS);
// Fetch PhantomJS-specific configuration parameters
if (driver.equals(DRIVER_PHANTOMJS)) {
// "phantomjs_exec_path"
if (sConfig.getProperty("phantomjs_exec_path") != null) {
sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, sConfig.getProperty("phantomjs_exec_path"));
} else {
throw new IOException(String.format("Property '%s' not set!", PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY));
}
// "phantomjs_driver_path"
if (sConfig.getProperty("phantomjs_driver_path") != null) {
System.out.println("Test will use an external GhostDriver");
sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY, sConfig.getProperty("phantomjs_driver_path"));
} else {
System.out.println("Test will use PhantomJS internal GhostDriver");
}
}
// Disable "web-security", enable all possible "ssl-protocols" and
// "ignore-ssl-errors" for PhantomJSDriver
// sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new
// String[] {
// "--web-security=false",
// "--ssl-protocol=any",
// "--ignore-ssl-errors=true"
// });
ArrayList<String> cliArgsCap = new ArrayList<String>();
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");
sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
// Control LogLevel for GhostDriver, via CLI arguments
sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, new String[] { "--logLevel=" + (sConfig.getProperty("phantomjs_driver_loglevel") != null ? sConfig.getProperty("phantomjs_driver_loglevel") : "INFO") });
// Start appropriate Driver
if (isUrl(driver)) {
sCaps.setBrowserName("phantomjs");
mDriver = new RemoteWebDriver(new URL(driver), sCaps);
} else if (driver.equals(DRIVER_FIREFOX)) {
mDriver = new FirefoxDriver(sCaps);
} else if (driver.equals(DRIVER_CHROME)) {
mDriver = new ChromeDriver(sCaps);
} else if (driver.equals(DRIVER_PHANTOMJS)) {
mDriver = new PhantomJSDriver(sCaps);
}
}
use of org.openqa.selenium.chrome.ChromeDriver in project structr by structr.
the class SeleniumTest method startDriver.
@Before
public void startDriver() {
switch(activeBrowser) {
case FIREFOX:
System.setProperty("webdriver.gecko.driver", getBrowserDriverLocation(activeBrowser));
final FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setHeadless(true);
driver = new FirefoxDriver(firefoxOptions);
break;
case CHROME:
System.setProperty("webdriver.chrome.driver", getBrowserDriverLocation(activeBrowser));
System.setProperty("webdriver.chrome.logfile", "/tmp/chromedriver.log");
System.setProperty("webdriver.chrome.verboseLogging", "true");
final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(true);
driver = new ChromeDriver(chromeOptions);
break;
case NONE:
// Don't create a driver in main thread, useful for parallel testing
break;
}
}
use of org.openqa.selenium.chrome.ChromeDriver in project structr by structr.
the class ParallelLoginTest method testParallelLogin.
@Test
public void testParallelLogin() {
// Wait for the backend to finish initialization
try {
Thread.sleep(10000L);
} catch (InterruptedException ex) {
}
createAdminUser();
final int numberOfRequests = 1000;
final int numberOfParallelThreads = 8;
final int waitForSec = 60;
final ExecutorService service = Executors.newFixedThreadPool(numberOfParallelThreads);
final List<Future<Exception>> results = new ArrayList<>();
for (int i = 0; i < numberOfRequests; i++) {
Future<Exception> result = service.submit(() -> {
// System.out.println(SimpleDateFormat.getDateInstance().format(new Date()) + " Login attempt from thread " + Thread.currentThread().toString());
logger.info("Login attempt from thread " + Thread.currentThread().toString());
final String menuEntry = "Pages";
System.setProperty("webdriver.chrome.driver", getBrowserDriverLocation(SupportedBrowsers.CHROME));
final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(true);
WebDriver driver = new ChromeDriver(chromeOptions);
try {
long t0 = System.currentTimeMillis();
// Wait for successful login
loginAsAdmin(menuEntry, driver, waitForSec);
long t1 = System.currentTimeMillis();
logger.info("Successful login after " + (t1 - t0) + " ms with thread " + Thread.currentThread().toString());
} catch (Exception ex) {
logger.error("Error in nested test in thread " + Thread.currentThread().toString(), ex);
return ex;
} finally {
driver.quit();
}
return null;
});
results.add(result);
}
int r = 0;
for (final Future<Exception> result : results) {
try {
long t0 = System.currentTimeMillis();
Exception res = result.get();
long t1 = System.currentTimeMillis();
r++;
if (res != null) {
logger.error(r + ": Got " + res + " from future after " + (t1 - t0) + " ms");
assertNull(result.get());
break;
}
} catch (final InterruptedException | ExecutionException ex) {
logger.error("Error while checking result of nested test", ex);
}
}
service.shutdown();
try {
// Typically, one login is done in under about 2 seconds, so we assume non-parallel execution and add the waiting time
Thread.sleep(1000L);
// Thread.sleep((numberOfRequests * 2000) + (waitForSec*1000));
} catch (InterruptedException ex) {
}
}
Aggregations