Installing CasperJS on Windows: How to do it correctly?

前端 未结 8 1311
天命终不由人
天命终不由人 2020-12-28 13:52

I know there is a documentation from CasperJS website about how to install CasperJS on Windows, but bear with me these guys only explained for the pros only.

If you

相关标签:
8条回答
  • 2020-12-28 14:33

    after a 3days work, i managed to get it work the problem was with the path and the installation of phantom. i had made the path to a folder but the installation was pointing to the exe file all i had to do was to put the exe file into a folder phantomjs and that was it thank for your help all.

    0 讨论(0)
  • 2020-12-28 14:34

    Fast forward to 2015... 5-steps win7 howto:

    1. choco: PS me> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
    2. git: choco install git -y
    3. phantomjs 2.0: choco install phantomjs -y
    4. casperjs source: git clone https://github.com/n1k0/casperjs -b phantomjs-2
    5. Add the location of casperjs/bin to PATH

    Done. You can now casperjs --version and live happily ever after.

    0 讨论(0)
  • 2020-12-28 14:35

    Ok guys. So I think this thread needs refreshing for 2018!

    So with npm, the effort is reduced significantly. Given that you have npm installed, open terminal and go to your project:

    cd your_project_name

    Now install casperjs. Use --save-dev, --save, -g or none as needed:

    npm install --save-dev casperjs

    Now install phantomjs. To do this, you should install phantomjs-prebuilt, because PhantomJS team changed their package name:

    npm install --save-dev phantomjs-prebuilt

    Run your spec:

    casperjs your_spec_name.js

    0 讨论(0)
  • 2020-12-28 14:36

    As of CasperJS 1.1.0-DEV Beta 3 you should use this PATH: C:\casperjs\batchbin even though the documentation found here states you need to use C:\casperjs\bin

    The reason to this is because C:\casperjs\batchbin includes a .BAT which C:\casperjs\bin does not include anything except some.js files.

    0 讨论(0)
  • 2020-12-28 14:40

    Just in case you're using a notebook with dual graphic cards like I do: choose one of them to prevent issues. This article helped me out:

    casperJS not finishing on windows

    the casperJS documentation is pretty clear about it but I had no clue what to do until I read the notice above.

    0 讨论(0)
  • 2020-12-28 14:46

    I itemize below the method that has served my needs on both my personal Windows and Ubuntu work PC. DO note that my method doesn't fiddle with PATH settings but involves a command you could save somewhere & copy and paste as needed:

    Step 1: Gather the prerequisites

    • Download the casperjs and phantomjs versions you want to use
    • Make a directory to contain the things I want to list
    • Extract the downloaded phantomjs & copy its executable into the directory of step b
    • Extract casperjs and rename its folder to casperjs
    • Copy the renamed casperjs folder to the directory of step b
    • Create and save a file config.json to the directory of step b
    • config.json should contain phantomjs configurations as found here: http://phantomjs.org/api/command-line.html

    Step 2: Running your script

    • Whenever you want to work with a file, follow the Step 1 details above
    • The next step assumes that you are in the directory created in step b of Step 1 also have a file named first.js
    • On Windows: phantomjs.exe --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs --cli first.js
    • On Ubuntu: ./phantomjs --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs --cli first.js

    Experimental config.js and first.js are listed below:

    config.json

    {"sslProtocol": "any", "cookiesFile": "biscuit", "maxDiskCacheSize": 1000, "diskCache": true}

    first.js

    var casper = require('casper').create({
        pageSettings: {
            loadImages: false,
            loadPlugins: true,
            userAgent: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'
        }
    });
    var url = "http://casperjs.org/";
    
    casper.start(url).wait(60 * 1000 * 1, function() {
         casper.echo('1 min has passed');
         casper.capture('casperjs.png');
         casper.exit();
    });
    
    casper.run();
    

    Addendum: download and save the details of screenshots.js and run it as

    phantomjs.exe --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs --cli screenshots.js http://phantomjs.org

    Run Tests: download & save the details of picturefill-test.js and run it as

    phantomjs.exe --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs test --cli picturefill-test.js

    0 讨论(0)
提交回复
热议问题