added the PhantomJS lib and the calls
Project: http://git-wip-us.apache.org/repos/asf/nutch/repo Commit: http://git-wip-us.apache.org/repos/asf/nutch/commit/7a7362c1 Tree: http://git-wip-us.apache.org/repos/asf/nutch/tree/7a7362c1 Diff: http://git-wip-us.apache.org/repos/asf/nutch/diff/7a7362c1 Branch: refs/heads/master Commit: 7a7362c141155d8fe163667328be204b1f592488 Parents: 5d05f28 Author: Kim Whitehall <[email protected]> Authored: Sat Apr 16 09:30:25 2016 -0700 Committer: Kim Whitehall <[email protected]> Committed: Sat Apr 16 09:30:25 2016 -0700 ---------------------------------------------------------------------- .../nutch/protocol/selenium/HttpWebClient.java | 35 +++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nutch/blob/7a7362c1/src/plugin/lib-selenium/src/java/org/apache/nutch/protocol/selenium/HttpWebClient.java ---------------------------------------------------------------------- diff --git a/src/plugin/lib-selenium/src/java/org/apache/nutch/protocol/selenium/HttpWebClient.java b/src/plugin/lib-selenium/src/java/org/apache/nutch/protocol/selenium/HttpWebClient.java index 583b840..1feb093 100644 --- a/src/plugin/lib-selenium/src/java/org/apache/nutch/protocol/selenium/HttpWebClient.java +++ b/src/plugin/lib-selenium/src/java/org/apache/nutch/protocol/selenium/HttpWebClient.java @@ -41,6 +41,7 @@ import org.openqa.selenium.io.TemporaryFilesystem; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.safari.SafariDriver; +import org.openqa.selenium.phantomjs.PhantomJSDriver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,18 +75,18 @@ public class HttpWebClient { String driverType = conf.get("selenium.driver", "firefox"); switch (driverType) { case "firefox": - String allowedHost = conf.get("selenium.firefox.allowed.hosts", "localhost"); - long firefoxBinaryTimeout = conf.getLong("selenium.firefox.binary.timeout", 45); - boolean enableFlashPlayer = conf.getBoolean("selenium.firefox.enable.flash", false); - int loadImage = conf.getInt("selenium.firefox.load.image", 1); - int loadStylesheet = conf.getInt("selenium.firefox.load.stylesheet", 1); - FirefoxProfile profile = new FirefoxProfile(); - FirefoxBinary binary = new FirefoxBinary(); - profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, allowedHost); - profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", enableFlashPlayer); - profile.setPreference("permissions.default.stylesheet", loadStylesheet); - profile.setPreference("permissions.default.image", loadImage); - binary.setTimeout(TimeUnit.SECONDS.toMillis(firefoxBinaryTimeout)); + String allowedHost = conf.get("selenium.firefox.allowed.hosts", "localhost"); + long firefoxBinaryTimeout = conf.getLong("selenium.firefox.binary.timeout", 45); + boolean enableFlashPlayer = conf.getBoolean("selenium.firefox.enable.flash", false); + int loadImage = conf.getInt("selenium.firefox.load.image", 1); + int loadStylesheet = conf.getInt("selenium.firefox.load.stylesheet", 1); + FirefoxProfile profile = new FirefoxProfile(); + FirefoxBinary binary = new FirefoxBinary(); + profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, allowedHost); + profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", enableFlashPlayer); + profile.setPreference("permissions.default.stylesheet", loadStylesheet); + profile.setPreference("permissions.default.image", loadImage); + binary.setTimeout(TimeUnit.SECONDS.toMillis(firefoxBinaryTimeout)); driver = new FirefoxDriver(binary, profile); break; case "chrome": @@ -97,6 +98,9 @@ public class HttpWebClient { case "opera": driver = new OperaDriver(); break; + case "phantomjs": + driver = new PhantomJSDriver(); + break; case "remote": String seleniumHubHost = conf.get("selenium.hub.host", "localhost"); int seleniumHubPort = Integer.parseInt(conf.get("selenium.hub.port", "4444")); @@ -114,6 +118,13 @@ public class HttpWebClient { System.setProperty("webdriver.reap_profile", "false"); driver = new RemoteWebDriver(new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath), capabilities); break; + case "phantomjs": + capabilities = DesiredCapabilities.phantomjs(); + capabilities.setBrowserName("phantomjs"); + capabilities.setJavascriptEnabled(true); + capabilities.setCapability("phantomjs_binary",seleniumGridBinary); + driver = new RemoteWebDriver(new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath), capabilities); + break; default: LOG.error("The Selenium Grid WebDriver choice {} is not available... defaulting to FirefoxDriver().", driverType); driver = new RemoteWebDriver(new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath), DesiredCapabilities.firefox());
