當前位置: 首頁>>代碼示例>>Java>>正文


Java PhantomJSDriverService類代碼示例

本文整理匯總了Java中org.openqa.selenium.phantomjs.PhantomJSDriverService的典型用法代碼示例。如果您正苦於以下問題:Java PhantomJSDriverService類的具體用法?Java PhantomJSDriverService怎麽用?Java PhantomJSDriverService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PhantomJSDriverService類屬於org.openqa.selenium.phantomjs包,在下文中一共展示了PhantomJSDriverService類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createPhantomJSDriver

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的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.PhantomJSDriverService; //導入依賴的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: createPhantomJsDriverServiceBuilder

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的package包/類
public PhantomJSDriverService.Builder createPhantomJsDriverServiceBuilder(SiteConfig siteConfig, DriverConfig driverConfig, File driverFile) {
        PhantomJSDriverService.Builder serviceBuilder = new PhantomJSDriverService.Builder();

        serviceBuilder.usingPhantomJSExecutable(driverFile);
//        serviceBuilder.usingAnyFreePort();
//        serviceBuilder.withEnvironment(Map<String, String>);
//        serviceBuilder.withLogFile(File);
//        serviceBuilder.usingPort(int);
//
//        serviceBuilder.withProxy(Proxy);
//        serviceBuilder.usingGhostDriver(File);
//        serviceBuilder.usingCommandLineArguments(String[]);
//        serviceBuilder.usingGhostDriverCommandLineArguments(String[]);

        return serviceBuilder;
    }
 
開發者ID:brucezee,項目名稱:jspider,代碼行數:17,代碼來源:WebDriverFactory.java

示例4: generatePhantomJsDriver

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的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

示例5: PwnBackWebDriver

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的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: onTrigger

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的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

示例7: createDefaultService

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的package包/類
public static PhantomJSDriverService createDefaultService(Capabilities desiredCapabilities, Map<String, String> env) {
	Proxy proxy = null;
	if (desiredCapabilities != null) {
		proxy = Proxy.extractFrom(desiredCapabilities);
	}

	File phantomjsfile = findPhantomJS(desiredCapabilities, "https://github.com/ariya/phantomjs/wiki", "http://phantomjs.org/download.html");
	File ghostDriverfile = findGhostDriver(desiredCapabilities, "https://github.com/detro/ghostdriver/blob/master/README.md", "https://github.com/detro/ghostdriver/downloads");
	Builder builder = new Builder();
	builder.usingPhantomJSExecutable(phantomjsfile)
		.usingGhostDriver(ghostDriverfile)
		.usingAnyFreePort()
		.withProxy(proxy)
		.withLogFile(new File("phantomjsdriver.log"))
		.usingCommandLineArguments(findCLIArgumentsFromCaps(desiredCapabilities, "phantomjs.cli.args"))
		.usingGhostDriverCommandLineArguments(findCLIArgumentsFromCaps(desiredCapabilities, "phantomjs.ghostdriver.cli.args"));
	if(null != env)
		builder.withEnvironment(env);
	return builder.build();
}
 
開發者ID:fjalvingh,項目名稱:domui,代碼行數:21,代碼來源:MyPhantomDriverService.java

示例8: createService

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的package包/類
public PhantomJSDriverService createService(String... arguments) {

        List<String> argList = new ArrayList<>();
        argList.add("--web-security=false");
        argList.add("--webdriver-loglevel=TRACE");
        argList.add("--load-images=false");
        argList.add("--ignore-ssl-errors=true");
        argList.add("--ssl-protocol=any");
        argList.addAll(Arrays.asList(arguments));

        PhantomJSDriverService service = new PhantomJSDriverService.Builder()
                .usingPhantomJSExecutable(EXECUTABLE)
                .usingCommandLineArguments(argList.toArray(new String[argList.size()]))
                .usingAnyFreePort()
                .build();

        LoggingOutputStream loggingOutputStream = new LoggingOutputStream(log, LogLevel.INFO);
        service.sendOutputTo(loggingOutputStream);

        return service;
    }
 
開發者ID:lkwg82,項目名稱:de.lgohlke.selenium-webdriver,代碼行數:22,代碼來源:PhantomJSDriverServiceFactory.java

示例9: startAndStop

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的package包/類
@Test
public void startAndStop() throws IOException {
    PhantomJSDriverService driverService = factory.createService();

    driverService.start();
    try {
        WebDriver webDriver = factory.createWebDriver(driverService);
        String url = "http://localhost:" + httpServer.getAddress().getPort() + "/webdriverTest";
        webDriver.get(url);
        String currentUrl = webDriver.getCurrentUrl();

        assertThat(currentUrl).isEqualTo(url);
    } finally {
        driverService.stop();
    }
}
 
開發者ID:lkwg82,項目名稱:de.lgohlke.selenium-webdriver,代碼行數:17,代碼來源:PhantomJSDriverServiceFactoryIT.java

示例10: testProxyHTTP

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的package包/類
@Ignore
@Test
public void testProxyHTTP() throws IOException {
    String[] arguments = factory.createServiceArgumentsBuilder()
                                .httpProxyServer("http://localhost:" + proxyPortProber.getPort())
                                .build();

    PhantomJSDriverService service = factory.createService(arguments);
    service.start();
    try {
        WebDriver webDriver = factory.createWebDriver(service);
        webDriver.get("http://www.lgohlke.de");
        assertThat(webDriver.getPageSource().length()).isBetween(24000, 26000);
    } finally {
        service.stop();
    }
}
 
開發者ID:lkwg82,項目名稱:de.lgohlke.selenium-webdriver,代碼行數:18,代碼來源:PhantomJSDriverServiceFactoryIT.java

示例11: testProxyHTTPS

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的package包/類
@Ignore
@Test
public void testProxyHTTPS() throws IOException {
    String[] arguments = factory.createServiceArgumentsBuilder()
                                .httpProxyServer("http://localhost:" + proxyPortProber.getPort())
                                .build();

    PhantomJSDriverService service = factory.createService(arguments);
    service.start();
    try {
        WebDriver webDriver = factory.createWebDriver(service);
        webDriver.get("https://www.google.de");
        assertThat(webDriver.getPageSource().length()).isBetween(100000, 110000);
    } finally {
        service.stop();
    }
}
 
開發者ID:lkwg82,項目名稱:de.lgohlke.selenium-webdriver,代碼行數:18,代碼來源:PhantomJSDriverServiceFactoryIT.java

示例12: testSeleniumGhostDriver

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的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

示例13: initBrowserCapabilities

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的package包/類
private static DesiredCapabilities initBrowserCapabilities() {
    DesiredCapabilities browserCapabilities = new DesiredCapabilities();

    browserCapabilities.setJavascriptEnabled(true);
    if (StringUtils.isNotEmpty(PHANTOM_JS_PATH_PROP)) {
        System.out.printf("\n\nSetting Phantom JS path to %s\n\n%n", PHANTOM_JS_PATH_PROP);
        browserCapabilities.setCapability(
                PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                PHANTOM_JS_PATH_PROP);
    }
    browserCapabilities.setCapability("takesScreenshot", true);
    browserCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, buildPhantomJsCommandLineArguments());
    browserCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, new String[]{
            formatArgument(LOG_LEVEL_ARG, ERROR)
    });

    return browserCapabilities;
}
 
開發者ID:automated-testing,項目名稱:nitrogen,代碼行數:19,代碼來源:NitrogenPhantomJsDriver.java

示例14: phantomJS

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的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

示例15: main

import org.openqa.selenium.phantomjs.PhantomJSDriverService; //導入依賴的package包/類
public static void main(String[] args) {
    //設置相應的驅動程序的位置
    System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "F:\\selenium\\chromedriver.exe");
    System.setProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "F:\\selenium\\phantomjs.exe");

    //任務執行線程池大小
    int threadCount = 5;
    SpiderConfig spiderConfig = SpiderConfig.create("baidu", threadCount)
            .setEmptySleepMillis(1000)
            .setExitWhenComplete(true);
    SiteConfig siteConfig = SiteConfig.create()
            .setMaxConnTotal(200)
            .setMaxConnPerRoute(100);

    //定義WebDriver池
    WebDriverPool webDriverPool = new WebDriverPool(
            new WebDriverFactory(),
            new DefaultWebDriverChooser(DriverType.CHROME),
            threadCount);

    //使用WebDriverDownloader請求任務下載器
    Downloader downloader = new WebDriverDownloader(webDriverPool);

    Spider spider = Spider.create(spiderConfig, siteConfig, new BaiduPageProcessor())
            .setDownloader(downloader)          //設置請求任務下載器
            .setPipeline(new BaiduPipeline())
            .addStartRequests("https://www.baidu.com/s?wd=https");

    //監控
    SpiderMonitor.register(spider);

    //啟動
    spider.start();
}
 
開發者ID:brucezee,項目名稱:jspider,代碼行數:35,代碼來源:WebDriverSpiderSample.java


注:本文中的org.openqa.selenium.phantomjs.PhantomJSDriverService類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。