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.

Issue of Java unit tests by using Sahi Java Driver

sunnyYuansunnyYuan Members
edited November -1 in Sahi - Open Source
Hi all,

I created a Sahi unit test case using java. Similar to the sample java project you have provided.

part of code:
public void setUp(){
        ...        
        String browserPath = "/usr/bin/firefox";
        String browserProcessName = "firefox";
        String browserOption = "-profile /mnt/sda4/Sahi/sahi0321/sahi/userdata/browser/ff/profiles/sahi0 -no-remote";
        browser = new Browser(browserPath, browserProcessName, browserOption);        
        browser.open();
    }
    
       public void testGoogle() throws ExecutionException{
        browser.navigateTo("http://www.google.com/");
        browser.textbox("q").setValue("sahi forums");
        assertTrue(browser.submit("Google Search").exists());
        browser.submit("Google Search").click();
        browser.waitFor(1000);
        browser.link("Sahi - Web Automation and Test Tool").click();
        browser.link("Login").click();
        System.out.println("check: browser.textbox(\"req_username\").exists() = " + browser.textbox("req_username").exists());
    }

run as Junit test:
error:_click(_link("Login"))
Error: The parameter passed to _click was not found on the browser
Error("The parameter passed to _click was not found on the browser")@:0
((void 0),"_click")@http://www.google.com.hk/_s_/spr/concat.js:374
((void 0))@http://www.google.com.hk/_s_/spr/concat.js:425
()@http://www.google.com.hk/_s_/spr/concat.js:2589
()@http://www.google.com.hk/_s_/spr/concat.js:2589
@http://www.google.com.hk/_s_/spr/concat.js:2414

<a href='/_s_/dyn/Log_getBrowserScript?href=&n=374'><b>Click for browser script</b></a>
    at net.sf.sahi.client.Browser.executeStep(Browser.java:196)
    at net.sf.sahi.client.Browser.execute(Browser.java:167)
    at net.sf.sahi.client.Browser.click(Browser.java:299)
    at net.sf.sahi.client.ElementStub.click(ElementStub.java:66)
    at in.co.sahi.MyJavaClientTest.testGoogle(MyJavaClientTest.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at junit.framework.TestCase.runTest(TestCase.java:164)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:230)
    at junit.framework.TestSuite.run(TestSuite.java:225)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


I found browser will open a new window when run step
browser.link("Sahi - Web Automation and Test Tool").click();

that may be the reason which causes the above peoblem.

I want to konw how to solve this issue.how to make the browser only opens one window?

Regards,
sunny

Comments

  • narayannarayan Administrators
    Hi Sunny,

    On your system, does
    browser.link("Sahi - Web Automation and Test Tool").click();
    open a new window? or does it open in the same window where google was?

    Thanks,
    Narayan
  • On my system(linux gentoo,firefox-3.0.6)
    browser.link("Sahi - Web Automation and Test Tool").click();
    will open a new window,is not the same window where google was
  • narayannarayan Administrators
    Then the test will have to be modified. You will need to use
    // get a handle to the popup window using its title
    Browser newWin = browser.popup("Sahi - Web Automation and Test Tool"); 
    newWin.link("Login").click();
     System.out.println("check: newWin.textbox(\"req_username\").exists() = " + newWin.textbox("req_username").exists());
    
  • Hi narayan,

    I modified my test use:
                    Browser newWin = browser.popup("Sahi - Web Automation and Test Tool"); 
                    newWin.link("Login").click();
                    Browser newloginWin = browser.popup("Login to Sahi - Web Automation and Test Tool - Sahi - Web Automation and Test Tool");
                    System.out.println("check: newWin.textbox(\"req_username\").exists() = " + newloginWin.textbox("req_username").exists());
    

    Now get the right result:
    tp://sahi.example.com/_s_/dyn/Driver_start?startUrl=http%3A%2F%2Fsahi.example.com%2F_s_%2Fdyn%2FDriver_initialized__SahiAmpersandSahi__sahisid=sahi_1fab6fa104c810440f0ad3d0ccfbf61d8fe4
    PIDs: [27308, 27416, 27418]; 6776 ms
    check: newWin.textbox("req_username").exists() = true
    

    Thank you very much!

    Regards,
    sunny
This discussion has been closed.