18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

PhantomJS 1.2+sahi => Class not found

JulianBJulianB Members
edited November -1 in Sahi - Open Source
Hello,

I'm currently trying to run headless tests with sahi under win xp. I have installed and configured the PhantomJS Browser version 1.2 for this.

Your tutorial at sahi.co.in/w/sahi-headless-execution-with-phantomjs is obsolete and does not work with PhantomJS 1.2. I seem to have suceeded in creating a working sahi.js file by piecing it together from the previous one as well as some examples. It now looks like this:
page = new WebPage();

if (phantom.args.length !== 0) {
    if (phantom.args.length !== 1) {
        console.log('Usage: phantomjs sahi.js URL');
        phantom.exit();
    }
    else {
        var address = phantom.args[0];
        console.log('Loading ' + address);
        page.open(phantom.args[0], function (status) {
            if (status !== 'success') {
                console.log('Unable to load the address!');
            } else {
                console.log(status);
                console.log('Page title is ' + page.evaluate(function () {
                        return document.title;
                    }));
            }
        });
    }
}
else {
    console.log(document.body.innerText);
    phantom.exit();
}

It seems to be working if I invokePhantomJS directly, which is why I suspect, I have a problem in my sahi configuration. I have configured my browser_types.xml as suggested in the afforementioned tutorial on sahi.co.in. However, when trying to run my testsuite, I get the following Java Warning displayed in the sahi console:

Sep 15, 2011 10:12:15 AM net.sf.sahi.command.CommandExecuter execute
Warnung: commandClass = >http%3A%2F%2Fsahi.co.in%2Fdemo< commandMethod = >execut
e<
Sep 15, 2011 10:12:15 AM net.sf.sahi.command.CommandExecuter execute
Warnung: java.lang.ClassNotFoundException: http%3A%2F%2Fsahi.co.in%2Fdemo
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at net.sf.sahi.util.ClassLoadHelper.getClass(ClassLoadHelper.java:24)
at net.sf.sahi.command.CommandExecuter.execute(CommandExecuter.java:53)
at net.sf.sahi.LocalRequestProcessor.handleDyn(LocalRequestProcessor.jav
a:67)

It seems to me, that it mistakes the url for a class name, but I just cannot figure out why. Any help is appreciated!

The problem does not show up with firefox.

OS: Windows XP
Browser: PhantomJS 1.2
Sahi Build: 2011-07-19

Regards,
Julian

Comments

  • Hi JulianB,

    The contents of sahi.js should only be :
    if (phantom.state.length === 0) {
        if (phantom.args.length === 0) {
            console.log('Usage: sahi.js <Sahi Playback Start URL>');
            phantom.exit();
        } else {
            var address = unescape(phantom.args[0]);
            phantom.state = "sahi script running";
            console.log('Loading ' + address);
            phantom.open(address);
        }
    } else {
        if (phantom.loadStatus == 'success') {
            console.log('Page title is ' + document.title);
        } else {
            console.log('FAIL to load the address');
        }
    }
    

    Also, make sure that the browser is configured as per the documentation:

    http://sahi.co.in/w/sahi-headless-execution-with-phantomjs

    Let me know if this solves this issue.

    Regards
    Sumitra
  • Hello
    I am trying to run Sahi in head less mode on linux.
    We have integrated TestNG with Sahi. The Controller mode runs fine and the tests run.

    I followed instructions on your home page for setting up in headless mode.

    Now again I run the testng runner like: java org.testng.TestNG -testclass testclass1
    I get the error:
    java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)

    Should the proxy be running in headless mode also?
    Can headless mode be configured using testng?

    regards,
    Vivek
  • Hi Sumitra,

    you posted the file from the tutorial. As I already said, your tutorial (sahi.co.in/w/sahi-headless-execution-with-phantomjs) is not compatible with PhantomJS 1.2. If you try your sahi.js with PhantomJS 1.2 it displays the error "phantom.state is undefined".

    And yes, the browser is configured as in the documentation.

    Meanwhile I have installed PhantomJS 1.1 and it works like a charm with your documentation. But you really should bring it up to date some time.

    Regards,
    Julian
Sign In or Register to comment.