The following code behaves differently when executed from the RFT IDE vs. the command line.
public void browserError() {
startBrowser("");
sleep (1);
TestObject[] to = find(atDescendant(".class", "Html.HtmlBrowser"));
System.out.println("Object found: " + to.length);
logMessage(MessType.INFO, "Object found: " + to.length);
}
If there is only one browser open when I run this code from the RFT IDE, the length of "to = 1". However, when I run it from the command line "to = 0".
It seems like the browser instance never gets registered so it never finds it.
What's even more puzzling is that this code works on a different machine, so I know something in my environment is messed up. I just don't know what it is.
Thanks in advance.
The problem I was experiencing was due to the JVM used by my machine vs. the JVM used by RFT. As of this writing, RFT runs on Java 1.7 and it does not support 1.8. RFT uses version 1.7 to execute all scripts. However when I run the script from the command line, it uses the computer's default JVM, which in my case was version 1.8 so when I executed the find command, it couldn't see the other browsers.
Thanks to Prakash, one of the RFT developers in IBM India for pointing this out.
So the moral of the story is this, when executing from the command line, you must explicitly use the same JVM that RFT uses, which translates into:
%IBM_RATIONAL_RFT_ECLIPSE_DIR%\jdk\bin\java.exe ... (uses the java.exe in that dir)
vs.
java ... (which uses the machine's default JVM)
I hope that helps someone in the future.