Using JSAFS Project JAR Files
Updated: 2014.08.12
Some of our most recent work for SeleniumPlus has provided the ability for ALL JSAFS users (tests written in Java) to create a JAR file containing all necessary assets for the JSAFS Project and then run a test from that JAR file.
The key detail being, the JSAFS Project space and assets do NOT have to already exist in the File System before the test can be run.
The necessary assets will be extracted automatically from the JAR file at runtime.
In order for this to work:
- The JAR file must contain the Project assets in a root directory matching the Project name.
So, for example, if the Project name and root directory is "SAMPLE", then there must be a root directory with that name in the JAR file and all subdirectories containing Project assets must exist in the JAR file.
- The JAR file must contain the executable classes for the Project.
- When running a test in a JAR file, you must:
- specify on the command-line the project root.
Ex: -Dsafs.project.root=sample
- optionally specify on the command-line where to extract and create the Project.
If not specified, the Project will be extracted and created off a user-specific Temp directory using the project root name as the project subdirectory.
Ex: -Dsafs.project.extract=C:\Automation
SeleniumPlus SAMPLE Project JAR File Example:
META-INF/
META-INF/MANIFEST.MF
sample/
sample/test.ini
sample/Map.class
sample/Map$ApplicationConstants.class
sample/Map$...(all remaining classes)
sample/Actuals/
sample/Actuals/signIn.png
sample/Maps/
sample/Maps/AppMap.order
sample/Maps/SAMPLEApp.map
sample/Maps/SAMPLEApp_en.map
sample/testcases/
sample/testcases/TestCase1.class
sample/testruns/
sample/testruns/TestRun1.class
A sample Windows BAT file for creating the JAR file above from a SeleniumPlus SAMPLE Project.
The BAT file should be run from the root directory of the Project--the SAMPLE directory.
set JARDIR=%CD%
%SELENIUM_PLUS%/Java/bin/jar cf "%JARDIR%\sampleproject.jar" -C bin .
cd ..
%SELENIUM_PLUS%/Java/bin/jar uf "%JARDIR%\sampleproject.jar" SAMPLE\*.ini
%SELENIUM_PLUS%/Java/bin/jar uf "%JARDIR%\sampleproject.jar" SAMPLE\Maps\*
%SELENIUM_PLUS%/Java/bin/jar uf "%JARDIR%\sampleproject.jar" SAMPLE\Benchmarks\*
Note that only the Project directories that contain assets--the non-empty directories--are included in the JAR file. The remaining directories will automatically be provided at runtime.
To run the SeleniumPlus test from the JAR file requires:
- SeleniumPlus must be properly installed on the runtime machine.
- The JAR file must be present or available for execution.
- The user must have admin/write priviledges on the runtime machine.
- Proper command-line invocation to properly extract the Project at runtime.
So let's assume we want to run TestRun1 using the C:\Automation directory as the runtime extraction point. For optimum results and visibility, the following steps are recommended:
- Place the sampleproject.jar file in the C:\Automation directory.
The desired directory must NOT already have a working Project with test.ini file in it.
- Launch the test from that directory using the following, or a BAT file with the same:
set JARFILES=%SELENIUM_PLUS%/libs/selenium-plus-1.0.jar;%SELENIUM_PLUS%/libs/JSTAFEmbedded.jar
set JAVAEXE=%SELENIUM_PLUS%/Java/bin/java
%JAVAEXE% -cp %JARFILES%;sampleproject.jar /
-Dsafs.project.root=sample -Dsafs.project.extract=%CD% /
sample.testruns.TestRun1
Assuming everything went as expected, the c:\Automation directory should now contain these new runtime-created assets:
debuglog.txt
projectsetup.log
sample/
(all SAMPLE Project assets including Logs directory with test results.)