本文介绍了在casperjs中启动slimerjs的正确方法是什么(具有绝对路径)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



嗯,我可以通过指定slimer.bat文件的路径来启动slimerjs:
C:\bin\slimerjs\slimerjs.bat,然后执行我的文件。



但是如果我修改casperjs文件(在bin\中)并修改默认exec使其更苗条:

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

当我执行casper命令时:

  casperjs --engine = slimerjs test.js 

它不起作用,通往slimerjs.bat的路径似乎被忽略了。



我也尝试过:




编辑:最好的解决方案:通过npm安装: npm install -g slimerjs -g随处可用。就是这样,只需选择带有casper的-engine = slimerjs 即可。此节点模块的Thx。


获得安装phantomjs + casperjs + slimerjs且没有PATH和OS兼容性头锁的最佳方法:

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

在Windows中,将在以下位置设置exe:C:\Users\UserName\AppData\Roaming\npm(您无需将它们放在PATH中,node -npm实际上是使用- -g标志)。


请记住,slimerjs存在一些相对路径问题,因此,为了保持幻像和苗条的兼容性,请使用 fs.workingDirectory ,请参见


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 :

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

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.

解决方案


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

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

这篇关于在casperjs中启动slimerjs的正确方法是什么(具有绝对路径)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:19
查看更多