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.

Multiple session problem in java API (ant)

vsplitvsplit Members
edited June 2013 in Sahi Pro
Hello,

I need launch multiple tests with different session with API JAVA (ant). As with the "scenario.suite"

This is my test code :
public class Run {
	static final String suiteName = "scripts/test/login.sah";
	static final String browserType = "chrome";
	static final String browserTypePath = "C:\\Users\\Vincent\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe";
	static String base = "http://localhost:8080/prod1/";
	static String threads = "3";
	static String[] args;
	static String host = "localhost";
	static String port = "9999";
	static String browserOption = "--user-data-dir=$userDir\\browser\\chrome\\profiles\\sahi$threadNo --proxy-server=localhost:9999 --disable-popup-blocking --always-authorize-plugins";
	static String browserProcessName = "chrome.exe";
	/**
	 * @param args
	 * @throws InterruptedException 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException, InterruptedException {
		Run.args = args;
		Test();
		TestUnique();
		TestMultiple();
	}
	
	
	public static void Test() throws IOException, InterruptedException{
		HashMap<String, Object> variableHashMap = new HashMap<String, Object>();
		variableHashMap.put("$n",args[0]);
		
		TestRunner testRunner = new TestRunner(suiteName, browserType, base, threads);
		testRunner.setInitJS(variableHashMap);
		String status = testRunner.execute();
		System.out.println(status);
		
		testRunner = null;
		variableHashMap = null;
	}
	
	public static void TestUnique() throws IOException, InterruptedException{
		HashMap<String, Object> variableHashMap = new HashMap<String, Object>();
		variableHashMap.put("$n",args[0]);
		
		TestRunner testRunner = new TestRunner(suiteName, browserTypePath, base, host, port, threads, browserOption, browserProcessName);	
		testRunner.setInitJS(variableHashMap);
		String status = testRunner.execute();
		System.out.println(status);
		
		testRunner = null;
		variableHashMap = null;
	}
	
	public static void TestMultiple() throws IOException, InterruptedException{
		HashMap<String, Object> variableHashMap = new HashMap<String, Object>();
		variableHashMap.put("$n",args[0]);
		
		SingleSessionTestRunner testRunnerU = new SingleSessionTestRunner("SahiAten + "+args[0], browserType, base);
		testRunnerU.start();
		testRunnerU.setInitJS(variableHashMap);
		testRunnerU.executeSingleTest(suiteName);
		String status  = testRunnerU.stop();
		System.out.println(status);
		
		testRunnerU = null;
		variableHashMap = null;
	}
}

This is the result http://img11.imageshack.us/img11/3804/loginsessionfailsahi.jpg

The expected result would be with multiple session on http://img543.imageshack.us/img543/9009/loginsessionok.jpg

Maybe he should be able to activate the variable useSingleSession in Java Code ??

Thank you in advance for your help

Regards

Vincent

Answers

  • imaginaimagina Members
    edited June 2013
    Hello,

    I have the same problem

    I try with
    java -cp ant-sahi.jar net.sf.sahi.test.TestRunner -test C:\Users\imagina\sahi_pro\userdata\scripts\test\login.sah -baseURL http://localhost:8080/x22 -browserType chrome -host localhost -port 9999 -threads 5 -useSingleSession false -initJS "var $user=guest;"
    

    impossible to have different session !!

    another test

    my butts being staggered launch threads
    (I made a small script node js to call. bat)
    This is result
    C:\Users\imagina\sahi_pro\userdata\scripts\test>node generateCommandesBat.js
    Current directory: C:\Users\imagina\sahi_pro\userdata\bin
    drunCustom.bat test\login.sah http://localhost:8080/prod1/ chrome 1
    drunCustom.bat test\login.sah http://localhost:8080/prod1/ chrome 2
    originFolder=../scripts/
    destFolder=temp/scripts/copied/
    nodes=localhost:9999
    ignorePattern=.*(svn|copied).*
    nodes=localhost:9999
    destFolder=temp/scripts/copied/
    originFolder=../scripts/
    ignorePattern=.*(svn|copied).*
    BasePath=C:/Users/imagina/sahi_pro/userdata/scripts
    localhost:9999
    http://localhost:9999/_s_/dyn/pro/Synchronizer_saveFile?destFolder=temp%2Fscripts%2Fcopied%2F
    200
    suite=temp/scripts/copied//test\login.sah
    browserType=chrome
    logsInfo=
    baseURL=http://localhost:8080/prod1/
    host=localhost
    port=9999
    nodes=localhost:9999
    initJS=var $n=2;
    failedScriptsSuite=/last_failed_scripts.suite
    chrome: SUCCESS
    
    
    originFolder=../scripts/
    destFolder=temp/scripts/copied/
    nodes=localhost:9999
    ignorePattern=.*(svn|copied).*
    nodes=localhost:9999
    destFolder=temp/scripts/copied/
    originFolder=../scripts/
    ignorePattern=.*(svn|copied).*
    BasePath=C:/Users/imagina/sahi_pro/userdata/scripts
    localhost:9999
    http://localhost:9999/_s_/dyn/pro/Synchronizer_saveFile?destFolder=temp%2Fscripts%2Fcopied%2F
    200
    suite=temp/scripts/copied//test\login.sah
    browserType=chrome
    logsInfo=
    baseURL=http://localhost:8080/prod1/
    host=localhost
    port=9999
    nodes=localhost:9999
    initJS=var $n=2;
    failedScriptsSuite=/last_failed_scripts.suite
    chrome: SUCCESS
    

    The script is for all (initJS=var $n=2) while one was initialized to 1 and the other 2?
    My objective is to launch thread shift in time. With different data contained in exel file.

Sign In or Register to comment.