Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to launch slimerjs in casperjs (with an absolute path)?

slimerjs launch

Well, i can launch slimerjs by specifying the path of the slimer.bat file : C:\bin\slimerjs\slimerjs.bat and then execute my file.

But if i modify casperjs file (in bin\ ) and modify the default exec for slimer :

    'env_varname': 'SLIMERJS_EXECUTABLE',
    'default_exec' : 'C:\bin\slimerjs\slimerjs.bat'

when i execute the casper command :

    casperjs --engine=slimerjs test.js

It doesn't work, the path to slimerjs.bat seems to be ignored.

I tried this too : https://github.com/laurentj/slimerjs/blob/master/BUILD.md

But the slimerjs.exe alone isn't sufficient, i need to have application.ini and omni.ja in the current folder where i'm executing my tests, and i don't want to add some files in every folders.

What i want is just to execute slimerjs in casperjs with the engine property, whatever is the folder where i am, like in phantomjs so i need to set an absolute path (or relative path from root).

I don't want to be in the slimerjs.bat folder and specify the folder or js test i want to execute like that : casperjs test C:/bin/try/test.js --engine=slimerjs.

Here one similar issue : https://github.com/n1k0/casperjs/issues/591

Edit (thanks to Darren Cook for his answer) for more details :

set PATH=%PATH%;C:\\bin\\slimerjs

If i set a Windows PATH for slimer, when i execute casperjs test --engine=slimerjs test.js, i have this message :

fail slimerjs

But adding the two files in the test.js folder solves the problem.

path

So i think i have to modify the slimerjs bat file, to set the :callexec path from the slimerjs.bat folder, not the current test.js folder.

Here :

:callexec
if ["%HIDE_ERRORS%"]==[""] (
    %SLIMERJSLAUNCHER% -app "%SLIMERDIR%application.ini" %PROFILE% -attach-console -no-remote %__SLIMER_ARGS%
) ELSE (
    %SLIMERJSLAUNCHER% -app "%SLIMERDIR%application.ini" %PROFILE% -attach-console -no-remote %__SLIMER_ARGS% 2>NUL
)

with :

SET SLIMERDIR=%~dp0

The problem is that i'm not familiar with this syntax (batch file), it might be already correct and the problem doesn't come from here.

But what i observe is that it seems to look for application.ini and omni.ja from the current folder, not the slimerjs folder.

PS : second idea doesn't work but now i know it comes from slimerjs.

EDIT:

REM % ~ d[rive] p[ath] 0[script name] is the absolute path to this bat file, without quotes, always.
REM ~ strips quotes from the argument

So the path seems to be good, and in fact it works with slimerjs alone : slimerjs test.js works great and it doesn't ask for application.ini. So it's the combination of the two which doesn't work.

When you launch it with the casper command, the path is different (current folder) , and application.ini isn't recognized any more.

like image 547
Fanch Avatar asked Feb 26 '14 11:02

Fanch


2 Answers


Answer -> i finally found a way that suits me : like this :

SlimerArchOk

So i put slimer in PATH, and i have to have application.ini and omni.ja at the same level as my directories contening my test files. That way it's not inconvenient, and i can launch my directories or files with slimerJS.

See also Git Issue


EDIT : Here the best solution : install it via npm : npm install -g slimerjs -g to be available everywhere. And that's it, juste choose your --engine=slimerjs with casper and it works. Thx for this node module.

For the best way to install phantomjs + casperjs + slimerjs without PATH and OS compatibility headlock :

npm install -g phantomjs
npm install -g casperjs
npm install -g slimerjs

In windows the exe will be set here : C:\Users\UserName\AppData\Roaming\npm (you don't need to put them in PATH, node -npm actually- manages it with the -g flag).

Keep in mind slimerjs has some relative path problems, so to keep the compatibility between phantom and slimer, use fs.workingDirectory, see Is there a way to step in to CasperJS code and Debug step by step

like image 141
Fanch Avatar answered Nov 18 '22 23:11

Fanch


Put slimerjs into the Windows path. You can test this will work by doing:

set PATH=%PATH%;C:\bin\slimerjs
casperjs --engine=slimerjs test.js

If that is good, you can set it globally. Here is an SO question on how to do that programmatically: How to update PATH variable permanently from cmd? Windows And here is one of many pages on how to do it from the GUI: http://www.computerhope.com/issues/ch000549.htm

As another idea, I wonder if the casper script needs double backslashes, so perhaps it should look like:

'default_exec' : 'C:\\bin\\slimerjs\\slimerjs.bat'
like image 40
Darren Cook Avatar answered Nov 18 '22 23:11

Darren Cook