当前位置: 首页>>代码示例>>Java>>正文


Java PhantomJSDriver类代码示例

本文整理汇总了Java中org.openqa.selenium.phantomjs.PhantomJSDriver的典型用法代码示例。如果您正苦于以下问题:Java PhantomJSDriver类的具体用法?Java PhantomJSDriver怎么用?Java PhantomJSDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PhantomJSDriver类属于org.openqa.selenium.phantomjs包,在下文中一共展示了PhantomJSDriver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPhantomJSDriver

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
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);
	}
 
开发者ID:entelgy-brasil,项目名称:zucchini,代码行数:19,代码来源:SeleniumDriver.java

示例2: getDriver

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
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;
}
 
开发者ID:brunocvcunha,项目名称:phantranslator,代码行数:23,代码来源:PhantranslatorExecutor.java

示例3: generatePhantomJsDriver

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:33,代码来源:DriverFactory.java

示例4: SeleniumExtension

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
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);
}
 
开发者ID:bonigarcia,项目名称:selenium-jupiter,代码行数:23,代码来源:SeleniumExtension.java

示例5: PwnBackWebDriver

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
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);
}
 
开发者ID:k4ch0w,项目名称:PwnBack,代码行数:17,代码来源:PwnBackWebDriver.java

示例6: get

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
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();
}
 
开发者ID:xbynet,项目名称:crawler,代码行数:23,代码来源:PhantomjsWebDriverPool.java

示例7: onTrigger

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
@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);
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:24,代码来源:GetWebpage.java

示例8: testSeleniumGhostDriver

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
@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();
	}
}
 
开发者ID:anthavio,项目名称:phanbedder,代码行数:19,代码来源:PhanbedderTest.java

示例9: before

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
@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);
    }
 
开发者ID:manuel-woelker,项目名称:jimix,代码行数:23,代码来源:JimixServletIntegrationTest.java

示例10: phantomJS

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
/**
 * 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));
}
 
开发者ID:GiannisPapadakis,项目名称:seletest,代码行数:28,代码来源:ConfigurationDriver.java

示例11: getDriver

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
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));
    }
}
 
开发者ID:galenframework,项目名称:galen,代码行数:25,代码来源:SeleniumBrowserFactory.java

示例12: setup

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
@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);
}
 
开发者ID:gwtd3,项目名称:gwt-d3,代码行数:21,代码来源:AbstractSeleniumTest.java

示例13: testWithHeadlessBrowsers

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
@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());
}
 
开发者ID:bonigarcia,项目名称:mastering-junit5,代码行数:10,代码来源:LocalWebDriverTest.java

示例14: PhantomJSFetcher

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
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;
}
 
开发者ID:ZhangJiupeng,项目名称:Gospy,代码行数:11,代码来源:PhantomJSFetcher.java

示例15: PhantomJSProcessor

import org.openqa.selenium.phantomjs.PhantomJSDriver; //导入依赖的package包/类
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;
}
 
开发者ID:ZhangJiupeng,项目名称:Gospy,代码行数:11,代码来源:PhantomJSProcessor.java


注:本文中的org.openqa.selenium.phantomjs.PhantomJSDriver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。