diff --git a/webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java b/webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java index 5940e738d..ce6383751 100644 --- a/webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java +++ b/webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java @@ -173,6 +173,7 @@ public Spider setUUID(String uuid) { * @param scheduler scheduler * @return this * @see #setScheduler(us.codecraft.webmagic.scheduler.Scheduler) + * @deprecated */ @Deprecated public Spider scheduler(Scheduler scheduler) { diff --git a/webmagic-selenium/src/main/java/us/codecraft/webmagic/downloader/selenium/WebDriverPool.java b/webmagic-selenium/src/main/java/us/codecraft/webmagic/downloader/selenium/WebDriverPool.java index e1d9dd039..d53630fe7 100644 --- a/webmagic-selenium/src/main/java/us/codecraft/webmagic/downloader/selenium/WebDriverPool.java +++ b/webmagic-selenium/src/main/java/us/codecraft/webmagic/downloader/selenium/WebDriverPool.java @@ -63,46 +63,54 @@ class WebDriverPool { * @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)); + try{ + // Read config file + sConfig = new Properties(); + String configFile = DEFAULT_CONFIG_FILE; + if (System.getProperty("selenuim_config")!=null){ + configFile = System.getProperty("selenuim_config"); } - // "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"); + FileReader configFileReader = new FileReader(configFile) + sConfig.load(configFileReader); + + // 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"); + } } + }catch(Exception e){ + throw new IOException("Can not load config file properly"); + + }finally{ + configFileReader.close(); } + + // Disable "web-security", enable all possible "ssl-protocols" and // "ignore-ssl-errors" for PhantomJSDriver // sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new