protected WebDriver getDriver() { if (this._driver == null) { DesiredCapabilities caps = new DesiredCapabilities(); caps.setJavascriptEnabled(true); caps.setCapability( PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "userAgent", spoofUserAgent); caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] { "--web-security=false", "--ssl-protocol=any", "--ignore-ssl-errors=true", "--webdriver-loglevel=INFO" }); PhantomJSDriverService service = new PhantomJSDriverService.Builder() .usingPort(8080) .usingPhantomJSExecutable(new File("/usr/local/bin/phantomjs")) .build(); this._driver = new PhantomJSDriver(service, caps); } return this._driver; }
/** * Generates a phantomJs webdriver. * * @return * A phantomJs webdriver * @throws TechnicalException * if an error occured when Webdriver setExecutable to true. */ private WebDriver generatePhantomJsDriver() throws TechnicalException { final String pathWebdriver = DriverFactory.getPath(Driver.PHANTOMJS); if (!new File(pathWebdriver).setExecutable(true)) { throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE)); } logger.info("Generating Phantomjs driver ({}) ...", pathWebdriver); final DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", "fr-FR"); capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, pathWebdriver); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); capabilities.setJavascriptEnabled(true); setLoggingLevel(capabilities); // Proxy configuration String proxy = ""; if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) { proxy = Context.getProxy().getHttpProxy(); } capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] { "--proxy=" + proxy, "--web-security=no", "--ignore-ssl-errors=true", "--ssl-protocol=tlsv1", "--webdriver-loglevel=NONE" }); return new PhantomJSDriver(capabilities); }
public SeleniumExtension() { handlerMap.put(ChromeDriver.class, ChromeDriverHandler.class); handlerMap.put(FirefoxDriver.class, FirefoxDriverHandler.class); handlerMap.put(EdgeDriver.class, EdgeDriverHandler.class); handlerMap.put(OperaDriver.class, OperaDriverHandler.class); handlerMap.put(SafariDriver.class, SafariDriverHandler.class); handlerMap.put(RemoteWebDriver.class, RemoteDriverHandler.class); handlerMap.put(AppiumDriver.class, AppiumDriverHandler.class); handlerMap.put(List.class, ListDriverHandler.class); handlerMap.put(PhantomJSDriver.class, OtherDriverHandler.class); templateHandlerMap.put("chrome", ChromeDriver.class); templateHandlerMap.put("firefox", FirefoxDriver.class); templateHandlerMap.put("edge", EdgeDriver.class); templateHandlerMap.put("opera", OperaDriver.class); templateHandlerMap.put("safari", SafariDriver.class); templateHandlerMap.put("appium", AppiumDriver.class); templateHandlerMap.put("phantomjs", PhantomJSDriver.class); templateHandlerMap.put("chrome-in-docker", RemoteWebDriver.class); templateHandlerMap.put("firefox-in-docker", RemoteWebDriver.class); templateHandlerMap.put("opera-in-docker", RemoteWebDriver.class); }
private static WebDriver createPhantomJSDriver(String driverPath) { DesiredCapabilities desiredCapabilities = DesiredCapabilities.phantomjs(); desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, driverPath); desiredCapabilities.setCapability(CapabilityType.ELEMENT_SCROLL_BEHAVIOR, true); desiredCapabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true); desiredCapabilities.setCapability(CapabilityType.ENABLE_PROFILING_CAPABILITY, true); desiredCapabilities.setCapability(CapabilityType.HAS_NATIVE_EVENTS, true); desiredCapabilities.setJavascriptEnabled(true); ArrayList<String> cliArgs = new ArrayList<String>(); cliArgs.add("--web-security=true"); cliArgs.add("--ignore-ssl-errors=true"); desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgs); return new PhantomJSDriver(desiredCapabilities); }
PwnBackWebDriver(PwnBackMediator mediator) { this.mediator = mediator; PhantomJSDriverService driverService = new PhantomJSDriverService.Builder() .usingPhantomJSExecutable(new File(PwnBackSettings.phatomjsLocation)) .build(); DesiredCapabilities capability = new DesiredCapabilities(); capability.setCapability("takesScreenshot", false); String[] args = new String[1]; args[0] = ""; if (checkSSLCertPathDefined()) { args[0] = "--ssl-certificates-path=" + PwnBackSettings.caBundleLocation; } capability.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, args); capability.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0"); driver = new PhantomJSDriver(driverService, capability); }
public WebDriver get() throws InterruptedException { WebDriver poll = innerQueue.poll(); if (poll != null) { return poll; } if (refCount.get() < CAPACITY) { synchronized (innerQueue) { if (refCount.get() < CAPACITY) { WebDriver mDriver = new PhantomJSDriver(caps); // 尝试性解决:https://github.com/ariya/phantomjs/issues/11526问题 mDriver.manage().timeouts() .pageLoadTimeout(60, TimeUnit.SECONDS); // mDriver.manage().window().setSize(new Dimension(1366, // 768)); innerQueue.add(mDriver); refCount.incrementAndGet(); } } } return innerQueue.take(); }
@Override public void onTrigger(ProcessContext context, ProcessSession session) { DesiredCapabilities DesireCaps = new DesiredCapabilities(); DesireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, context.getProperty(DRIVER_LOCATION).getValue()); driver = new PhantomJSDriver(DesireCaps); FlowFile flowFile = session.create(); try { driver.get(url); (new WebDriverWait(driver, timeout)).until( ExpectedConditions.visibilityOfElementLocated(getExpectedCondition(selectorType, selector)) ); final byte[] page = formatToXHtml(driver.getPageSource(), StandardCharsets.UTF_8); flowFile = session.write(flowFile, outputStream -> outputStream.write(page)); session.transfer(flowFile, REL_SUCCESS); } catch (Exception e) { flowFile = session.write(flowFile, outputStream -> outputStream.write(e.getMessage().getBytes())); session.transfer(flowFile, REL_FAILURE); } finally { driver.quit(); } session.getProvenanceReporter().create(flowFile); }
@Test public void testSeleniumGhostDriver() { File phantomjs = Phanbedder.unpack(); DesiredCapabilities dcaps = new DesiredCapabilities(); dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath()); PhantomJSDriver driver = new PhantomJSDriver(dcaps); try { driver.get("https://www.google.com"); WebElement query = driver.findElement(By.name("q")); query.sendKeys("Phanbedder"); query.submit(); Assertions.assertThat(driver.getTitle()).contains("Phanbedder"); } finally { driver.quit(); } }
@Before public void before() throws Exception { final Gauge<Long> gauge = Metrics.newGauge(metricName, new Gauge<Long>() { long current = 42; @Override public Long value() { return current; } }); server = new Server(8081); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); context.addServlet(new ServletHolder(new JimixServlet()), "/jimix/*"); server.start(); // driver = new FirefoxDriver(); driver = new PhantomJSDriver(); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); }
/** * PhantomJS bean * @param capabilities Desirercapabilities for WebDriver * @return WebDriver instance */ @Bean(name="phantomJS") @Lazy(true) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public WebDriver phantomJS(DesiredCapabilities capabilities){ DesiredCapabilities phantomJSCap = new DesiredCapabilities(); phantomJSCap.setJavascriptEnabled(true); try { phantomJSCap.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, URLDecoder.decode(getClass() .getClassLoader().getResource(".").getPath(), "UTF-8")+System.getProperty("file.separator")+"downloads"+System.getProperty("file.separator")+"phantomjs-2.0.0-windows"+System.getProperty("file" + ".separator")+"phantomjs.exe"); } catch (UnsupportedEncodingException e) { log.error("Exception occured constructing path to executable: {}", e); } phantomJSCap.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[]{ "--ignore-ssl-errors=yes", "--web-security=false", "--ssl-protocol=any"}); phantomJSCap.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX, "Y"); phantomJSCap.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"); phantomJSCap.setCapability("elementScrollBehavior",1); return new PhantomJSDriver(capabilities.merge(phantomJSCap)); }
public static WebDriver getDriver(String browserType){ if ( StringUtils.isEmpty(browserType) || FIREFOX.equals(browserType)) { return new FirefoxDriver(SeleniumBrowserFactory.getBrowserCapabilities(browserType)); } else if (CHROME.equals(browserType)) { return new ChromeDriver(SeleniumBrowserFactory.getBrowserCapabilities(browserType)); } else if (IE.equals(browserType)) { return new InternetExplorerDriver(SeleniumBrowserFactory.getBrowserCapabilities(browserType)); } else if (PHANTOMJS.equals(browserType)) { return new PhantomJSDriver(); } else if (SAFARI.equals(browserType)) { return new SafariDriver(); } else if (EDGE.equals(browserType)) { return new EdgeDriver(); } else { throw new RuntimeException(String.format("Unknown browser type: \"%s\"", browserType)); } }
@Before public void setup() throws MalformedURLException { String webAppUrl = System.getProperty(WEBAPP_URL); System.setProperty("SELENIUM_STARTING_URL", "http://127.0.0.1:8888/D3Demo.html?gwt.codesvr=127.0.0.1:9997"); // separate localhost and saucelabls/cloudbees env if (System.getProperty(RUN_SELENIUM_LOCALHOST) != null) { // ensure the Firefox with default profile is loaded // in order to use the Firefox instance with GWT dev plugin System.setProperty("webdriver.firefox.profile", "default"); driver = new FirefoxDriver(); webAppUrl = "http://127.0.0.1:8888/D3Demo.html?gwt.codesvr=127.0.0.1:9997"; } else { driver = new PhantomJSDriver(); webAppUrl = "http://127.0.0.1:8080/D3Demo.html"; } Dimension size = new Dimension(1920, 1080); driver.manage().window().setSize(size); driver.get(webAppUrl); }
@Test public void testWithHeadlessBrowsers(HtmlUnitDriver htmlUnit, PhantomJSDriver phantomjs) { htmlUnit.get("https://bonigarcia.github.io/selenium-jupiter/"); phantomjs.get("https://bonigarcia.github.io/selenium-jupiter/"); assertTrue(htmlUnit.getTitle().contains("JUnit 5 extension")); assertNotNull(phantomjs.getPageSource()); }
private PhantomJSFetcher(String phantomJsBinaryPath, int timeout, boolean loadImages, String userAgent, Collection<Cookie> cookies) { System.setProperty("phantomjs.binary.path", phantomJsBinaryPath); DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); capabilities.setCapability("phantomjs.page.settings.resourceTimeout", timeout); capabilities.setCapability("phantomjs.page.settings.loadImages", loadImages); capabilities.setCapability("phantomjs.page.settings.userAgent", userAgent); this.webDriver = new PhantomJSDriver(capabilities); this.userAgent = userAgent; this.cookies = cookies; }
private PhantomJSProcessor(String phantomJsBinaryPath, int timeout, boolean loadImages, String userAgent, Extractor<WebDriver, ?> handler, TaskFilter filter) { System.setProperty("phantomjs.binary.path", phantomJsBinaryPath); DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); capabilities.setCapability("phantomjs.page.settings.resourceTimeout", timeout); capabilities.setCapability("phantomjs.page.settings.loadImages", loadImages); capabilities.setCapability("phantomjs.page.settings.userAgent", userAgent); this.webDriver = new PhantomJSDriver(capabilities); this.handler = handler; this.filter = filter; }
/** * Simulate Enter key */ @Override @PublicAtsApi public void pressEnterKey() { new RealHtmlElementState(this).waitToBecomeExisting(); WebElement element = RealHtmlElementLocator.findElement(this); if (webDriver instanceof PhantomJSDriver) { element.sendKeys(Keys.ENTER); } else { element.sendKeys(Keys.RETURN); } }
private void highlightElement( boolean disregardConfiguration ) { if (webDriver instanceof PhantomJSDriver) { // it is headless browser return; } if (disregardConfiguration || UiEngineConfigurator.getInstance().getHighlightElements()) { try { WebElement webElement = RealHtmlElementLocator.findElement(element); String styleAttrValue = webElement.getAttribute("style"); JavascriptExecutor js = (JavascriptExecutor) webDriver; js.executeScript("arguments[0].setAttribute('style', arguments[1]);", webElement, "background-color: #ff9; border: 1px solid yellow; box-shadow: 0px 0px 10px #fa0;"); // to change text use: "color: yellow; text-shadow: 0 0 2px #f00;" Thread.sleep(500); js.executeScript("arguments[0].setAttribute('style', arguments[1]);", webElement, styleAttrValue); } catch (Exception e) { // swallow this error as highlighting is not critical } } }
/** * {@inheritDoc} */ @Override public PhantomJSDriver start(Capabilities other) { Capabilities capabilities = this.mergeCapabilities(other); if (capabilities == null) { return new PhantomJSDriver(); } return new PhantomJSDriver(capabilities); }
protected final void loadDriver(boolean quit) { if (quit) { quit(); } driver = new PhantomJSDriver(); driver.manage().window().setSize(new Dimension(1024, 768)); driver.manage().timeouts().implicitlyWait(NORMAL_WAIT_TIMEOUT, TimeUnit.SECONDS); }
public SeleniumTest(String geckoDriverPath){ //System.setProperty("webdriver.gecko.driver", geckoDriverPath); //driver = new FirefoxDriver(); System.setProperty("phantomjs.binary.path", System.getProperty("user.dir")+"/phantomjs"); driver = new PhantomJSDriver(); driver.manage().window().setSize(new Dimension(1920,1080)); baseUrl = "http://127.0.0.1:8080/#"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); wait = new WebDriverWait(driver,5); }
/** * Use phantomjs to fetch the web content. * @return */ protected WebDriver phantomJsDriver() { String phantomJsExecPath = System.getProperty("phantomjsExec"); if(phantomJsExecPath == null || "".equals(phantomJsExecPath)) { phantomJsExecPath = "/usr/local/bin/phantomjs"; } DesiredCapabilities dc = new DesiredCapabilities(); dc.setJavascriptEnabled(true); dc.setCapability( PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomJsExecPath ); return new PhantomJSDriver(dc); }
@Override public WebDriver getDefaultDriver() { if(System.getProperty("phantomjs.binary.path") != null) { return new PhantomJSDriver(); } else { return new FirefoxDriver(); } }
private static WebDriver getPhantomJsDriver() { final DesiredCapabilities caps = DesiredCapabilities.phantomjs(); caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] { "--ignore-ssl-errors=true", "--ssl-protocol=tlsv1", "--web-security=false" }); final PhantomJSDriver phantomJSDriver = new PhantomJSDriver(caps); phantomJSDriver.manage().window().setSize(new Dimension(1280, 800)); return phantomJSDriver; }
public WebDriver getPhantomDriver() { System.out.println("getting phantom driver"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setJavascriptEnabled(true); capabilities.setCapability("webSecurityEnabled", true); PhantomJSDriver driver = new PhantomJSDriver(capabilities); driver.manage().timeouts().implicitlyWait(DEFAULT_IMPLICITLY_WAIT_SECS, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(DEFAULT_PAGE_LOAD_TIMEOUT_SECS, TimeUnit.SECONDS); return driver; }
/** * Setting up PhantoJSDriver * * @return PhantomJSDriver */ public static WebDriver setUpPhantomJSDriver(String driverPath) { File phantomjs = new File(driverPath); DesiredCapabilities dcaps = new DesiredCapabilities(); dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[]{"--ignore-ssl-errors=yes", "--ssl-protocol=tlsv1", "version=2.0", "driverVersion=1.2.0"}); dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath()); return new PhantomJSDriver(dcaps); }
public static void main(String[] args) { WebDriver driver = new PhantomJSDriver(); driver.get("http://www.jan-exner.de/"); JavascriptExecutor js = (JavascriptExecutor) driver; List<Object> dcrlist = (List<Object>) js.executeScript("return _satellite.rules"); for (Iterator<Object> iterator = dcrlist.iterator(); iterator.hasNext();) { Object object = (Object) iterator.next(); Map<String, Object> map = (Map<String, Object>) object; String ruleName = (String) map.get("name"); System.out.println(ruleName); } }
@Override public WebDriver create() throws Exception { // create the web driver LOGGER.log(Level.INFO, "Creating WebDriver"); DesiredCapabilities dcap = DesiredCapabilities.phantomjs(); WebDriver driver = new PhantomJSDriver(dcap); return driver; }
/** * Screenshooter for HTMLUnit. It saves the html source to disk following the * same pattern as the screenshot path. The HTMLUnit session is transfered to * PhantomJs, which takes the screenshot, and is destroyed. The original * driver is not destroyed * * Note: Javascript events, current page changes, etc.. are not saved and are * not captured in the screenshots taken. * * @param path * - where to save the file. This assumes a png file will be * generated * @param baseUrl * - used to transfer the cookies to the phantomjs driver properly. * * @see #getPhantomJsWebDriver() */ public void saveScreenshotForHtmlUnit(String path, String baseUrl) { final WebDriver driver = this.get(); if (!(driver instanceof HtmlUnitDriver)) { LOG.warn("Wrong driver called screenshooter for HTMLUnit driver, default to regular screenshooter"); this.saveScreenshotAs(path); return; } PhantomJSDriver phantomJs = (PhantomJSDriver) getPhantomJsWebDriver(); try { phantomJs.get(baseUrl); String url = driver.getCurrentUrl(); LOG.debug("Url: {}", url); for (Cookie cookie : driver.manage().getCookies()) { LOG.debug("Cookie: {}", cookie.toString()); phantomJs.manage().addCookie(cookie); } phantomJs.get(url); // set current thread to phantomjs, and take screenshot in the default way this.set(phantomJs); LOG.debug("HTML Screenshot taken: {}", this.saveScreenshotAs(path)); } finally { // set back original driver for this thread this.set(driver); phantomJs.close(); phantomJs.quit(); } }
/** * Default implementation throws UnsupportedOperationException * @return WebDriver instance */ protected WebDriver getPhantomJsWebDriver() { String pathToBin = getOsSpecificBinaryPathFromProp(PHANTOM_JS_BIN_PROP, "phantomjs"); DesiredCapabilities capabilities = getPhantomJsCapabilities(); capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, pathToBin); return new PhantomJSDriver(capabilities); }
/** * 将带有 chart、map等动态图表的 html转换为 图片 (可以额外配置 cookie的权限控制). * * @param url 目标URL * @param addedCookie 添加 cookie * @return 图片 byte数组 */ @SuppressWarnings(value = {"unchecked"}) @Override public byte[] convert2Image(String url, Cookie addedCookie, Integer width, Integer height) { PhantomJSDriver driver = null; try { driver = HtmlExporterUtils.prepare(url, addedCookie, width, height); return driver == null ? null : driver.getScreenshotAs(OutputType.BYTES); } finally { HtmlExporterUtils.release(driver); } }
/** * 将带有 chart、map等动态图表的 html转换为 图片 (可以额外配置 cookie的权限控制). * * @param url 目标URL * @param addedCookie 添加 cookie * @return */ @SuppressWarnings(value = {"unchecked"}) @Override public String convert2Image(String url, Cookie addedCookie, Integer width, Integer height) { PhantomJSDriver driver = null; try { driver = HtmlExporterUtils.prepare(url, addedCookie, width, height); return driver == null ? "" : driver.getScreenshotAs(OutputType.BASE64); } finally { HtmlExporterUtils.release(driver); } }
/** * 将带有 chart、map等动态图表的 html转换为 图片 (可以额外配置 cookie的权限控制). * * @param url 目标URL * @param addedCookie 添加 cookie * @return 图片文件 */ @SuppressWarnings(value = {"unchecked"}) @Override public File convert2Image(String url, Cookie addedCookie, Integer width, Integer height) { PhantomJSDriver driver = null; try { driver = HtmlExporterUtils.prepare(url, addedCookie, width, height); return driver == null ? null : driver.getScreenshotAs(OutputType.FILE); } finally { HtmlExporterUtils.release(driver); } }
/** * 初始化配置 PhantomJS Driver. * * @param url 目标URL * @param addedCookie 添加 cookie * @return 初始化过的 PhantomJS Driver */ public static PhantomJSDriver prepare(String url, Cookie addedCookie, Integer width, Integer height) { // chrome driver maybe not necessary // download from https://sites.google.com/a/chromium.org/chromedriver/downloads // System.setProperty("webdriver.chrome.driver", // DirUtils.RESOURCES_PATH.concat( // PropUtils.getInstance().getProperty("html.exporter.webdriver.chrome.driver"))); DesiredCapabilities phantomCaps = DesiredCapabilities.chrome(); phantomCaps.setJavascriptEnabled(true); phantomCaps.setCapability("phantomjs.page.settings.userAgent", PropUtils.getInstance().getProperty("html.exporter.user.agent")); PhantomJSDriver driver = new PhantomJSDriver(phantomCaps); driver.manage().timeouts().implicitlyWait(Integer.valueOf(PropUtils.getInstance() .getProperty("html.exporter.driver.timeouts.implicitly.seconds")), TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(Integer.valueOf(PropUtils.getInstance() .getProperty("html.exporter.driver.timeouts.page.load.seconds")), TimeUnit.SECONDS); driver.manage().timeouts().setScriptTimeout(Integer.valueOf(PropUtils.getInstance() .getProperty("html.exporter.driver.timeouts.script.seconds")), TimeUnit.SECONDS); if (width == null || height == null) driver.manage().window().maximize(); else driver.manage().window().setSize(new Dimension(width, height)); if (addedCookie != null) driver.manage().addCookie(addedCookie); driver.get(url); // try { // // timeout is not work, so fix it by sleeping thread // Thread.sleep(Integer.valueOf(PropUtils.getInstance() // .getProperty("html.exporter.driver.timeouts.implicitly.seconds")) * 1000); // } catch (InterruptedException e) { // throw new RuntimeException(e); // } return driver; }
/** * Release those resource of phantomjs, include shutdown phantom process. * * @param driver close cannot shutdown, should do it with quit() */ public static void release(PhantomJSDriver driver) { try { if (driver != null) driver.close(); } finally { if (driver != null) driver.quit(); } }
@Override public void before() { File phantomjs = Phanbedder.unpack(); DesiredCapabilities dcaps = new DesiredCapabilities(); dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath()); driver = new PhantomJSDriver(dcaps); }
/** * 60 Max * 40 looks stable * @throws InterruptedException */ //@Test public void testLocalPhantomjs() throws InterruptedException { runMultipleThread(60, new WebDriverFactory(){ public WebDriver getDriver() { return new PhantomJSDriver(); } } ); }
public WebDriver get() { File phantomJsExe = new File("phantomjs-1.9.7-windows/phantomjs.exe"); Map<String, Object> caps = new HashMap<>(); caps.put(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomJsExe.getAbsolutePath()); DesiredCapabilities capabilities = new DesiredCapabilities(caps); WebDriver driver = new PhantomJSDriver(capabilities); Dimension DEFAULT_WINDOW_SIZE = new Dimension(1024, 768); driver.manage().window().setSize(DEFAULT_WINDOW_SIZE); return driver; }
@Override public WebDriver getWebDriver() { DesiredCapabilities caps = new DesiredCapabilities(); caps.setJavascriptEnabled(true); caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "src/test/resources/phantomjs"); caps.setCapability("takesScreenshot", true); return new PhantomJSDriver(caps); }