0

I have to automate a test case in which a list in a particular dashboard is created. We decided to use PhantomJS headless browser. Since I am new to it, I tried creating test myself. Following are the steps I followed just to open the target website.

  1. Created directory phantoms
  2. cd phantoms and installed phantom module using command npm install phantom --save
  3. Created file createlist.js:

createlist.js contents:

var phantom = require('phantom');
var page = require('webpage');
page.open('http://facebook.com', function(status) {
  console.log("Status: " + status);
  if(status === "success") {
    page.render('example.png');
  }
  phantom.exit();
});

When i execute command node create_list.js, I am getting the following error:

page.open('interact2.responsys.net/interact/jsp/jindex.jsp&#‌​39;, function(st atus) { ^ TypeError: page.open is not a function at Object.<anonymous> (C:\Users\shilshet\New folder\phantom\create_list.js:3 :6) at Module._compile (module.js:413:34)

If I try to execute command like

phantomjs  C:/Users/shilshet/New folder/phantom/create_list.js

I am getting this error

bash: phantomjs: command not found

Note: I am using cygwin to execute commands

What I am going wrong? I installed phantomjs module also in the same folder as my node.js.

Could anyone let me know apart from using headless browser, how does one create a profile list in Oracle responsys via REST API call?

Vaviloff
  • 16,282
  • 6
  • 48
  • 56
Shilpa
  • 103
  • 1
  • 9
  • Sorry ,small correction . when i execute command node create_list.js ,I am getting error as page.open('https://interact2.responsys.net/interact/jsp/jindex.jsp', function(st atus) { ^ TypeError: page.open is not a function at Object. (C:\Users\shilshet\New folder\phantom\create_list.js:3 :6) at Module._compile (module.js:413:34) – Shilpa Nov 21 '16 at 14:25
  • If you want to ask about Oracle responsys you should open another question solely for that purpose. – Vaviloff Nov 21 '16 at 16:10

2 Answers2

1

While the first answer here should work, it's not the best way to accomplish what you need. The cleaner way to solve your issue is to add the location of your phantomjs executable to your PATH variable defined in a file such as ~/.bash_history.

The file may not be defined, so you may need to create the file, and then add PATH="/path/to/phantomjs/executable"

If you prefer to edit your PATH var via a GUI: Edit PATH variable via Windows GUI

The reason you need to do this, is that your system natively iterates over paths defined in the 'PATH' variable in order to determine where executable files are. Since phantomjs is not included in the PATH variable (nonexistent in the environment), and you try to run 'phantomjs', your system simply does not know which executable to call (or rather it doesn't know it exists)

The reason this is the better approach is:

  1. You don't need to explicitly write out the path of where phantomjs is located every time you want to run it (it's just cleaner looking too)
  2. What happens if you you call phantomjs from multiple files, and the location of where phantomjs is stored changes? If you explicitly typed phantomjs' absolute path everywhere, then you need to change EVERY place you typed it! Nightmare! With this approach, you simply change it in one place; the file that defines your PATH variable
  3. It's pretty conventional to add new file paths to your PATH env variable. You shouldn't clutter it, but it makes sense in this case to add it

For this: "Could anyone let me know apart from using headless browser, how does one create a profile list in Oracle responsys via REST API call?"... I would recommend asking a separate question. I personally don't know, but if you raise the new question, you may get support from someone who does.

Hope this helps! If you need any help whatsoever, let me know.

sramzan
  • 96
  • 8
  • Thank you for looking into issue. – Shilpa Nov 22 '16 at 06:52
  • Thank you for looking into the issue.But still I am facing issue I tried setting path in windows machine ,But after setting path "C:\Users\shilshet\phantom\node_modules\phantomjs-prebuilt\bin" ,Its failing $ phantomjs --version module.js:341 throw err; ^ Error: Cannot find module 'C:\cygdrive\c\Users\shilshet\phantom\node_modules\ph ntomjs-prebuilt\bin\phantomjs' at Function.Module._resolveFilename (module.js:339:15) at Function.Module._load (module.js:290:25) at Function.Module.runMain (module.js:447:10) at startup (node.js:140:18) at node.js:1001:3 – Shilpa Nov 22 '16 at 07:04
  • One more observation ,If i set path to C:\Users\shilshet\phantom\node_modules\phantomjs-prebuilt\bin\phantomjs and try to get version" phantomjs --version" I am getting error "bash: phantomjs: command not found" – Shilpa Nov 22 '16 at 07:09
  • You should set path to C:/path/to/phantomjs.exe - They key here is to point your path to the .exe file so that when your system tries to execute phantomjs (when you type 'phantomjs param1 param2 ...') it calls the executable file. Please try that and let me know if works @Shilpa – sramzan Nov 22 '16 at 20:33
  • Hi sean,Thank you .I made the changes according to your inputs ,its working but as of I observed if I download the zip file for windows it has .exe file but if i do "npm install phantomjs" i could see node_modules and phantomjs script .What exactly both difference ? – Shilpa Nov 23 '16 at 07:41
  • I am really sorry If my question is not making sense ,since new to phantom as well as node ,wt to know ,wts the difference of zip and npm install for windows,Realy appreciate if you could help me out here – Shilpa Nov 23 '16 at 07:44
  • No worries! For your question regarding 'npm install phantomjs', when you do this, npm creates a 'node_modules' directory (if not already created) to store modules local to your project. What that means is that the phantomjs inside of there, and the one you have elsewhere on your machine, are the same (assuming you installed the same version in both places). If you prefer to not have a 'node_modules' dir, and have npm install phantom globally, then do 'npm install -g phantomjs'. So the ultimate difference is installing phantom locally to your project/working repo, or globally – sramzan Nov 23 '16 at 16:51
  • man didi it again... I'll delete those bad comments lol [npm install documentation](https://docs.npmjs.com/cli/install) – sramzan Nov 23 '16 at 16:56
  • Also, since this answer answered your initial question, would you mind accepting it as the correct solution please? If you prefer it over the other answer of course – sramzan Nov 23 '16 at 16:58
0

You mixed up two ways of running PhantomJS.

The more straightforward, more simple way is just launching PhantomJS from command line and giving it the path of a script as an argument. On Windows you would do it like this:

"C:/Users/shilshet/New folder/phantom/phantomjs.exe" "C:/Users/shilshet/New folder/phantom/create_list.js"

Note the quotes here, they're needed because there are spaces in filenames.

Vaviloff
  • 16,282
  • 6
  • 48
  • 56
  • I am not finding phantomjs.exe file after I used npm install phantom --save.Could you please let me know where it will be ,as asfter I installed via npm , i could see node_modulues folder in that \phantomjs-prebuilt\b‌​in – Shilpa Nov 22 '16 at 07:05