Jruby: Watir Is Hanging When Launching Browser

jruby1.6.7+watir+cucumer1.2.1 on win7 can not open ff14.0.1

JRuby: Watir is hanging when launching browser

Solution is to add -Djava.net.preferIPv4Stack=true to JAVA_OPTS telling Java to prefer IPv4 over IPv6 when possible.

Connection Refused: Thrift Client on JRuby 1.7.3

Found it!

I was creating my Thrift::ServerSocket using ::1. MRI clients will work with this (doesn't matter if host is set to localhost, ::1, or 127.0.0.1. JRuby clients will not, and will complain about refused connections.

Next, I was creating my Thrift::Client using ::1. Again, JRuby doesn't like it.

Changing every thing to localhost fixed it. I don't really understand what is going on, but java is clearly using IPv6.

>lsof -i :56990
COMMAND PID USER FD TYPE SIZE/OFF NODE NAME
java 4441 codex 31u IPv6 0t0 TCP localhost:56990 (LISTEN)
java 4441 codex 36u IPv6 0t0 TCP localhost:56990->localhost:50439 (ESTABLISHED)
java 4875 codex 31u IPv6 0t0 TCP localhost:50439->localhost:56990 (ESTABLISHED)

Reload rb scripts from different locations in JRuby

The solution is to specify scope for a ScriptingContainer instance when creating it. One of the ScriptingContainer constructors takes in a parameter of type LocalContextScope, use one of the constants to define the scope. See LocalContextScope.java

To test this defect and solution I have written a small snippet. You may try it out:

public class LoadPathProblem {

public static void main(String[] args) {
// Create the first container
ScriptingContainer c1 = new ScriptingContainer();
// FIX ScriptingContainer c1 = new ScriptingContainer(LocalContextScope.SINGLETHREAD);

// Setting a load path for scripts
String path1[] = new String[] { ".\\scripts\\one" };
c1.getProvider().setLoadPaths(Arrays.asList(path1));

// Run a script that requires loading scripts in the load path above
EvalUnit unit1 = c1.parse("load 'test.rb'\n" + "testCall");
IRubyObject ret1 = unit1.run();
System.out.println(JavaEmbedUtils.rubyToJava(ret1));

// Create the second container, completely independent of the first one
ScriptingContainer c2 = new ScriptingContainer();
// FIX ScriptingContainer c2 = new ScriptingContainer(LocalContextScope.SINGLETHREAD);

// Setting a different load path for this container as compared to the first container
String path2[] = new String[] { ".\\Scripts\\two" };
c2.getProvider().setLoadPaths(Arrays.asList(path2));

// Run a script that requires loading scripts in the different path
EvalUnit unit2 = c2.parse("load 'test.rb'\n" + "testCall");
IRubyObject ret2 = unit2.run();

/*
* PROBLEM: Expected here that the function testCall will be called from
* the .\scripts\two\test.rb, but as you can see the output says that
* the function was still called from .\scripts\one\test.rb.
*/
System.out.println(JavaEmbedUtils.rubyToJava(ret2));
}
}

Test scripts to try out the above code can be in different folders but with the same filename ("test.rb" for the above example:

./scripts/one/test.rb

def testCall
"Called one"
end

./scripts/two/test.rb

def testCall
"Called two"
end

Selenium or Watir for Javascript Testing in Rails

As the founder of OpenQA and Selenium RC, I'm obviously biased towards Selenium as a good option. We recently just put out a 1.0 beta 2 release and are very close to a 1.0 final.

However, you couldn't go wrong with Watir/FireWatir either. Adam's comment that WebDriver will merge to form Selenium 2.0 is correct, but he's incorrect in implying that Watir doesn't use native hooks. If Watir were simply a Selenium clone and also used JavaScript injection, I'd say it wasn't worth looking at.

But because it has native hooks, it can do some things that Selenium currently can't. While it has fewer browsers supported, it goes a bit deeper in the main browser it does support (IE) and lets you control things outside of the page/canvas.

In summary: either is fine, Selenium is great, and if you hang on a little longer with Selenium you'll soon get the best of both worlds with WebDriver/Selenium 2.0.

Portable Runtimes?

JVM and .NET are only virtual machines, that interpret bytecode. There are a lot of language on top of them.

JVM

  • Java
  • Groovy
  • Scala
  • JRuby
  • Jython
  • JavaScript (Rhino)
  • Clojure
  • etc.

.NET

  • C#
  • VB.NET
  • Nemerle
  • J#
  • Boo
  • IronRuby
  • IronPython
  • etc.

There are another VM and script languages that can be run across the platform, i.e. Parrot that is Perl 6 VM or Lua that is X-platform script language (i.e. WoW use it). There are also project like LLVM (Low Level Virtual Machine) but this is still a little bit platform dependent.



Related Topics



Leave a reply



Submit