本文整理汇总了Java中com.crawljax.browser.EmbeddedBrowser类的典型用法代码示例。如果您正苦于以下问题:Java EmbeddedBrowser类的具体用法?Java EmbeddedBrowser怎么用?Java EmbeddedBrowser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EmbeddedBrowser类属于com.crawljax.browser包,在下文中一共展示了EmbeddedBrowser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
@Override
protected void configure() {
bind(URL.class).annotatedWith(BaseUrl.class).toInstance(config.getUrl());
bind(CrawljaxConfiguration.class).toInstance(config);
bind(CrawlRules.class).toInstance(config.getCrawlRules());
bind(ProxyConfiguration.class).toInstance(config.getProxyConfiguration());
BrowserConfiguration browserConfig = config.getBrowserConfig();
bind(BrowserConfiguration.class).toInstance(browserConfig);
if (browserConfig.isDefaultBuilder()) {
bind(EmbeddedBrowser.class).toProvider(WebDriverBrowserBuilder.class);
} else {
bind(EmbeddedBrowser.class).toProvider(
Providers.guicify(browserConfig.getBrowserBuilder()));
}
}
示例2: getStrippedDom
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
/**
* @param browser
* the current browser instance
* @return the stripped dom using {@link OracleComparator}s.
*/
public String getStrippedDom(EmbeddedBrowser browser) {
String newDom = browser.getStrippedDom();
for (OracleComparator oraclePreCondition : oracleComparator) {
// use oracle if preconditions succeeds
if (allPreConditionsSucceed(oraclePreCondition, browser)) {
Comparator oracle = oraclePreCondition.getOracle();
LOGGER.debug("Using {} : {}", oracle.getClass().getSimpleName(),
oraclePreCondition.getId());
// TODO dodgy code. Is the equivalence check necessary?
boolean equivalent = oracle.isEquivalent("", newDom);
newDom = oracle.normalize(newDom);
if (equivalent) {
return newDom;
}
}
}
return newDom;
}
示例3: check
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
/**
* Check invariant.
*
* @param browser
* The browser.
* @return Whether the condition is satisfied or <code>false</code> when it it isn't or a
* {@link CrawljaxException} occurs.
*/
@Override
public boolean check(EmbeddedBrowser browser) {
String js =
"try{ if(" + expression + "){return '1';}else{" + "return '0';}}catch(e){"
+ " return '0';}";
try {
Object object = browser.executeJavaScript(js);
if (object == null) {
return false;
}
return object.toString().equals("1");
} catch (CrawljaxException e) {
// Exception is caught, check failed so return false;
return false;
}
}
示例4: getFailedConditions
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
/**
* @param browser
* The browser.
* @return a list of {@link ConditionType} where {@link Condition#check(EmbeddedBrowser)}
* failed.
*/
public ImmutableList<T> getFailedConditions(EmbeddedBrowser browser) {
LOGGER.debug("Checking {} ConditionTypes", invariants.size());
ImmutableList.Builder<T> builder = ImmutableList.builder();
for (T invariant : invariants) {
if (preConditionsHold(browser, invariant)) {
Condition invariantCondition = invariant.getCondition();
LOGGER.debug("Checking ConditionType: {}", invariant.getDescription());
if (!invariantCondition.check(browser)) {
LOGGER.debug("ConditionType '{}' failed", invariant.getDescription());
builder.add(invariant);
}
}
}
return builder.build();
}
示例5: runOnBrowserCreatedPlugins
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
/**
* Load and run the OnBrowserCreatedPlugins, this call has been made from the browserpool when a
* new browser has been created and ready to be used by the Crawler. The PreCrawling plugins are
* executed before these plugins are executed except that the precrawling plugins are only
* executed on the first created browser.
*
* @param newBrowser
* the new created browser object
*/
public void runOnBrowserCreatedPlugins(EmbeddedBrowser newBrowser) {
LOGGER.debug("Running OnBrowserCreatedPlugins...");
counters.get(OnBrowserCreatedPlugin.class).inc();
for (Plugin plugin : plugins.get(OnBrowserCreatedPlugin.class)) {
if (plugin instanceof OnBrowserCreatedPlugin) {
LOGGER.debug("Calling plugin {}", plugin);
try {
((OnBrowserCreatedPlugin) plugin)
.onBrowserCreated(newBrowser);
} catch (RuntimeException e) {
reportFailingPlugin(plugin, e);
}
}
}
}
示例6: CandidateElementExtractor
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
/**
* Create a new CandidateElementExtractor.
*
* @param checker
* the ExtractorManager to use for marking handled elements and retrieve the
* EventableConditionChecker
* @param browser
* the current browser instance used in the Crawler
* @param formHandler
* the form handler.
* @param config
* the checker used to determine if a certain frame must be ignored.
*/
@Inject
public CandidateElementExtractor(ExtractorManager checker, @Assisted EmbeddedBrowser browser,
FormHandler formHandler, CrawljaxConfiguration config) {
checkedElements = checker;
this.browser = browser;
this.formHandler = formHandler;
CrawlRules rules = config.getCrawlRules();
PreCrawlConfiguration preCrawlConfig = rules.getPreCrawlConfig();
this.excludeCrawlElements = asMultiMap(preCrawlConfig.getExcludedElements());
this.includedCrawlElements =
ImmutableList
.<CrawlElement> builder()
.addAll(preCrawlConfig.getIncludedElements())
.addAll(rules.getInputSpecification().getCrawlElements())
.build();
crawlFrames = rules.shouldCrawlFrames();
clickOnce = rules.isClickOnce();
ignoredFrameIdentifiers = rules.getIgnoredFrameIdentifiers();
}
示例7: testWaitConditionNoIndexOutOfBounceAfterFirstTry
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
@Test
public void testWaitConditionNoIndexOutOfBounceAfterFirstTry() {
WaitCondition wc = new WaitCondition("tmp", WAIT_TIME_LONG, new ExpectedCondition() {
@Override
public boolean isSatisfied(EmbeddedBrowser browser) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
Assert.fail(e.getMessage());
e.printStackTrace();
}
return true;
}
});
Assert.assertEquals("Wait timed out", WAIT_TIMEOUT, wc.testAndWait(browser));
}
示例8: testGetDocumentFromBrowser
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
/**
* Test get document from browser function.
*/
@Test
public void testGetDocumentFromBrowser() throws SAXException, IOException {
// TODO Stefan; Refactor out the direct use of FirefoxDriver
EmbeddedBrowser browser =
WebDriverBackedEmbeddedBrowser.withDriver(new FirefoxDriver(), ImmutableSortedSet.<String> of(), 200, 300);
File index = new File(INDEX);
String html = "";
browser.goToUrl(new URL("file://" + index.getAbsolutePath()));
html = browser.getStrippedDom();
assertNotNull(html);
Document doc = DomUtils.asDocument(html);
assertNotNull(doc);
browser.close();
browser = null;
}
示例9: saveScreenshot
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
private void saveScreenshot(EmbeddedBrowser browser, String name,
StateVertex vertex) {
LOG.debug("Saving screenshot for state {}", name);
File jpg = outputBuilder.newScreenShotFile(name);
File thumb = outputBuilder.newThumbNail(name);
try {
byte[] screenshot = browser.getScreenShot();
ImageWriter.writeScreenShotAndThumbnail(screenshot, jpg, thumb);
} catch (CrawljaxException | WebDriverException e) {
LOG.warn(
"Screenshots are not supported or not functioning for {}. Exception message: {}",
browser, e.getMessage());
LOG.debug("Screenshot not made because {}", e.getMessage(), e);
}
LOG.trace("Screenshot saved");
}
示例10: get
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
@Override
public EmbeddedBrowser get() {
EmbeddedBrowser browser2 = null;
if (null != CrawlPanel.Browser.getSelectedItem().toString()) {
switch (CrawlPanel.Browser.getSelectedItem().toString()) {
case "Firefox":
browser2 = newFirefoxBrowser();
break;
case "IE":
browser2 = newIEBrowser();
break;
case "Chrome":
browser2 = newChromeBrowser();
break;
case "PhantomJS":
browser2 = newPhantomBrowser();
break;
case "Remote":
browser2 = newRemoteBrowser();
break;
}
}
return browser2;
}
示例11: newFirefoxBrowser
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
private EmbeddedBrowser newFirefoxBrowser() {
FirefoxProfile profile = new FirefoxProfile();
if (CrawlPanel.manualproxy.isSelected()) {
String host = CrawlPanel.HostProxy.getText();
Integer port = Integer.parseInt(CrawlPanel.PortProxy.getText());
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http", host);
profile.setPreference("network.proxy.http_port", port);
profile.setPreference("network.proxy.ssl", host);
profile.setPreference("network.proxy.ssl_port", port);
profile.setPreference("network.proxy.socks", host);
profile.setPreference("network.proxy.socks_port", port);
profile.setPreference("network.proxy.ftp", host);
profile.setPreference("network.proxy.ftp_port", port);
}
WebDriver drivertest = new FirefoxDriver(profile);
if (CrawlPanel.burpcookie.isSelected()) {
setCookies(drivertest, "FirefoxBrowser");
}
return WebDriverBackedEmbeddedBrowser.withDriver(drivertest);
}
示例12: onNewState
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
@Override
public void onNewState(CrawlerContext arg0, StateVertex arg1) {
if ("".equals(getOutputFolder())) {
LOGGER.warn("Output folder for CSSCather has not been set. " +
"So there will be no output for CSSCatcher. " +
"Use CSSCather.setOutputFolder() before CrawljaxRunner.call()");
}
EmbeddedBrowser browser = arg0.getBrowser();
int styleSheetLength = Integer.valueOf(browser.executeJavaScript("return document.styleSheets.length").toString());
for (int i = 0; i < styleSheetLength; i++) {
Object hrefObj = browser.executeJavaScript("return document.styleSheets[" + i + "].href");
if (hrefObj != null) {
String href = hrefObj.toString();
cssHrefs.add(href);
fetchAndWriteFile(href, arg1.getName(), arg1.getUrl());
}
}
}
示例13: FormHandler
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
@Inject
public FormHandler(@Assisted EmbeddedBrowser browser, CrawlRules config) {
this.browser = browser;
this.formInputValueHelper =
new FormInputValueHelper(config.getInputSpecification(),
config.isRandomInputInForms());
}
示例14: allPreConditionsSucceed
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
private boolean allPreConditionsSucceed(OracleComparator oraclePreCondition,
EmbeddedBrowser browser) {
for (Condition preCondition : oraclePreCondition.getPreConditions()) {
LOGGER.debug("Check precondition: " + preCondition.toString());
if (!preCondition.check(browser)) {
return false;
}
}
return true;
}
示例15: check
import com.crawljax.browser.EmbeddedBrowser; //导入依赖的package包/类
@Override
public boolean check(EmbeddedBrowser browser) {
for (Condition condition : conditions) {
if (!condition.check(browser)) {
return false;
}
}
return true;
}