Tl: dr - How can I link to CasperJS and PhantomJS from a C # project folder?
I have working code that runs a CasperJS script from a C # project when I manually unpack the binaries for CasperJS and PhantomJS to C: drive. (See here for a simple guide and working code below, designated as a WORK Code :)
Since there is no need for installation, I thought it would be easy to move them to the C # project folder instead of \tools\casperjs and \tools\phantomjs . In addition, I need to update the PATH variable in the code using p.StartInfo.EnvironmentVariables["PATH"] = EnvPath;
The whole combination of paths that I'm trying, I keep getting the following error "Fatal: [Errno 2] No such file or directory; did you install phantomjs?"
All files, of course, were included in the file path. Am I missing something?
DOES NOT WORK Code: [filepaths \ tools \ casperjs, \ tools \ phantomjs and C: \ Python34]
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Casper { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string Cpath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
WORKING CODE: [file path C: \ casperjs, C: \ phantomjs and C: \ Python34]
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Casper { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) {
TESTcasper.js
var casper = require('casper').create(); casper.start('http://casperjs.org/', function() { this.echo(this.getTitle()); }); casper.thenOpen('http://phantomjs.org', function() { this.echo(this.getTitle()); }); casper.run();