What’s the best way to do integration testing for a Javascript heavy UI in a rails app?

We have a web application that makes extensive use of AJAXy Javascript in the UI. We have nearly complete code coverage of our backend using Shoulda and Webrat, and would like to extend our test suite to include full integration testing through the Javascript UI.

We tried Selenium but found it brittle and temperamental. Are there more reliable options?


For those still checking this out, we ended up using Xvfb so we can run Firefox without a screen. Allows us to run the test on a headless Jenkins CI server. We still have to run tests “live” locally occasionally to debug, but it works pretty well.


Hmm I would give Capybara a look, it can use selenium-webdriver (not to be confused with selenium-RC, they are different) for javascript testing. I haven’t found it very brittle when compared with Webrat… it seems to be fairly consistent.

As Chris Rueber says, there aren’t really any headless DOM interpreters that support JS as well – for now it’s fire up a web browser for your automation or write unit tests in the javascript itself (Which isn’t really integration testing either).

When you have a lot of selenium-webdriver-backed tests they can take awhile to run sometimes, but it’s surely better than no tests at all.


Ant needs tools.jar and unable to find it

I am putting together a dev environment for a Java program and after the first try of my Ant build scripts I got this error:

Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar

While the path to the jdk is correct, the tools.jar really wasn’t there. Is it actually supposed to be there or did I get some config/installation thing wrong?


It’s there on my machine. I’m running Sun JDK 1.6.0_21 on Windows XP SP3.

Are you sure you have the JDK? Is it possible that you only have the JRE?


How to reliably hash JavaScript objects?

Is there a reliable way to JSON.stringify a JavaScript object that guarantees that the ceated JSON string is the same across all browsers, Node.js and so on, given that the JavaScript object is the same?

I want to hash JavaScript objects like

  signed_data: object_to_sign,
  signature:   md5(JSON.stringify(object_to_sign) + secret_code)

and pass them around across web applications (e.g. Python and Node.js) and the user so that the user can authenticate against one service and show the next service “signed data” for that one to check if the data is authentic.

However, I came across the problem that JSON.stringify is not really unique across the implementations:

  • In Node.js / V8, JSON.stringify returns a JSON string without unnecessary whitespace, such as ‘{“user_id”:3}.
  • Python’s simplejson.dumps leaves some whitespace, e.g. '{"user_id": 3}'
  • Probably other stringify implementations might deal differently with whitespace, the order of attributes, or whatever.

Is there a reliable cross-platform stringify method? Is there a “nomalised JSON”?

Would you recommend other ways to hash objects like this?


This is what I use as a workaround:

normalised_json_data = JSON.stringify(object_to_sign)
  signed_data: normalised_json_data,
  signature:   md5(normalised_json_data + secret_code)

So in this approach, not the object itself, but its JSON representation (which is specific to the sigining platform) is signed. This works well because what I sign now is an unambiguous string and I can easily JSON.parse the data after I have checked the signature hash.

The drawback here is that if I send the whole {signed_data, signature} object as JSON around as well, I have to call JSON.parse twice and it does not look as nice because the inner one gets escaped:

{"signature": "1c3763890298f5711c8b2ea4eb4c8833", "signed_data": "{"user_id":5}"}


You’re asking for an implementation of something across multiple languages to be the same… you’re almost certainly out of luck. You have two options:

  • check implementations to see if they might be more standardized
  • roll your own in each language (use implementations as a base and there should be VERY little work to do)

Suggestions for how to communicate from JS running in a UIWebView to the hosting obj-c app?

I plan to have a shell iphone app with a uiwebview, with the bulk of my application running through javascript in the uiwebview.

Now i know it’s easy to communicate from the obj-c environment to the javascript environment by using stringByEvaluatingJavaScriptFromString, however is there a good recommended way of communicating from the javascript environment to the obj-c world?



I always use an approach in which the app “navigates” to a special URL:

window.location = "myapp://somemessage/someargument";

And where the app catches this in the following function:

-(BOOL)webView:(UIWebView *)webView
                shouldStartLoadWithRequest:(NSURLRequest *)request
    NSURL *url = [request URL];
    if ( [[url scheme] isEqualToString:@"myapp"] )
        [self handleJSEvent:url];
        return NO;
    return YES;

Furthermore, depending on what you need, you could use some kind of event queue which you fetch using JSON.stringify(events), in response to a message sent to the app using the method described above. For communicating from app to js JSON is also very suitable.

If there is a standard or a standard way to do this, I clearly missed it.


connection pool shutdown android

I have a class for Httpclient. The same instance is used throughout the application. So if the client == null it should create one else it will return the existing instance. Everything works until i try to release the resource on exit by doing: client.getConnectionManager().shutdown();….after this i am not able to login again. It gives Sysem error saying : connection pool shutdown. Heres the class:

public class HttpClientFactory {
    private static DefaultHttpClient client;        
    public synchronized static DefaultHttpClient getThreadSafeClient() {
    if (client != null)
        return client;

    client = new DefaultHttpClient();
    SchemeRegistry schemeRegistry = new SchemeRegistry(); 
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));  
    HttpParams params = new BasicHttpParams();  
    SingleClientConnManager mgr = new SingleClientConnManager(params, schemeRegistry);  
    client = new DefaultHttpClient(mgr, params);

    return client;

After this i simply run client.getConnectionManager().shutdown(); onBackPressed(), can somebody please help me


Ok..i got the solution…I was not setting it back to null and connection shutdown is suppose to be done in the same global class…

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..