Java Code Examples for com.gargoylesoftware.htmlunit.BrowserVersion.FIREFOX_24

The following are Jave code examples for showing how to use FIREFOX_24 of the com.gargoylesoftware.htmlunit.BrowserVersion class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: reviki   File: WebTestSupport.java   View Source Code Vote up 6 votes
private WebClient setupClient(final String username, final String password) {
  final WebClient client = new WebClient(BrowserVersion.FIREFOX_24);
  final WebClientOptions options = client.getOptions();
  DefaultCredentialsProvider credentials = new DefaultCredentialsProvider();
  credentials.addCredentials(username, password);
  client.setCredentialsProvider(credentials);
  options.setRedirectEnabled(true);
  options.setThrowExceptionOnFailingStatusCode(true);
  client.addWebWindowListener(new ValidateOnContentChange());
  client.getCookieManager().setCookiesEnabled(false);

  // Try to log only "interesting" things:
  // Don't log errors we can't fix due to browser bugs etc.
  client.setIncorrectnessListener(new SuppressingIncorrectnessListener());

  return client;
}
 
Example 2
Project: MALSignatureDesigner   File: Http.java   View Source Code Vote up 6 votes
/**
 * Returns the Url of image for the animeId provided. The file type extension is not included.
 * @param animeId
 * @return null if not found
 * @throws FailingHttpStatusCodeException
 * @throws MalformedURLException
 * @throws IOException
 */
public static String getAnimeImageUrl(int animeId) throws FailingHttpStatusCodeException, MalformedURLException, IOException{
	String theReturn = null;
	final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);
	webClient.getOptions().setThrowExceptionOnScriptError(false);//Will give alot of errors
	new IgnoreRandomJScripts(webClient);
	java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.SEVERE);//to ignore those errors
	try{
		Page page = webClient.getPage("http://myanimelist.net/anime.php?id="+animeId);
		if(page.isHtmlPage()){
			Pattern p = Pattern.compile("http://cdn.myanimelist.net/images/anime/([0-9]+)/([0-9]+).jpg");
			Matcher m = p.matcher(page.getWebResponse().getContentAsString());
			if(m.find()){
				if(m.groupCount() == 2){
					theReturn = "http://cdn.myanimelist.net/images/anime/"+m.group(1)+"/"+m.group(2);
				}
			}
		}
	}
	catch(com.gargoylesoftware.htmlunit.ScriptException e){}
	webClient.closeAllWindows();
	java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.ALL);
	return theReturn;
}
 
Example 3
Project: MALSignatureDesigner   File: Http.java   View Source Code Vote up 6 votes
/**
 * Downloads and saves Jpeg from url and stores as file
 * @param url
 * @param saveLoc
 * @return true on success
 * @throws FailingHttpStatusCodeException
 * @throws MalformedURLException
 * @throws IOException
 */
public static boolean downloadImage(String url, String saveLoc) throws FailingHttpStatusCodeException, MalformedURLException, IOException{
	if(url != null && saveLoc != null){
		if(!url.isEmpty() && !saveLoc.isEmpty()){
			final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);
			Page page = webClient.getPage(url);
			webClient.closeAllWindows();
			if(page.getWebResponse().getContentType().equals("image/jpeg")){//grabbed the xml file
				InputStream in = page.getWebResponse().getContentAsStream();
				OutputStream out; out = new FileOutputStream(new File(System.getProperty("user.dir") + saveLoc));
				IOUtils.copy(in,out);
				return true;
			}
		}
	}
	return false;
}
 
Example 4
Project: MALSignatureDesigner   File: Http.java   View Source Code Vote up 5 votes
/**
	 * Retrieves the anime history for inputted user
	 * @param username
	 * @param rssType rw
	 * @return XML as String
	 * @throws FailingHttpStatusCodeException
	 * @throws MalformedURLException
	 * @throws IOException
	 */
	public static String getAnimeList(String username, String rssType) throws FailingHttpStatusCodeException, MalformedURLException, IOException{
	final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);
	Page page = webClient.getPage("http://myanimelist.net/rss.php?type="+rssType+"&u="+username);
	//System.out.println(page.getWebResponse().getContentAsString());
	String content = page.getWebResponse().getContentAsString();
	webClient.closeAllWindows();
	if(content.startsWith("<?xml") && content.length() > 350){//grabbed the xml file
		return content;
	}
	return null;
}
 
Example 5
Project: elpaaso-core   File: GuiStoriesContext.java   View Source Code Vote up 4 votes
@Bean
@Scope(value = "prototype")
public CommonHtmlUnitDriverStepHelper commonHtmlUnitDriverStepHelper() throws MalformedURLException {

    return new CommonHtmlUnitDriverStepHelper(new HtmlUnitDriver(BrowserVersion.FIREFOX_24), webappUrl(), populatePageUrl());
}
 
Example 6
Project: mamute   File: AcceptanceTestBase.java   View Source Code Vote up 4 votes
@SuppressWarnings("unused")
private static WebDriver htmlUnitDriver() {
	HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_24);
	driver.setJavascriptEnabled(true);
	return driver;
}