Shilpa
Shilpa

Reputation: 103

PhantomJS -headless browseer

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?

Upvotes: 0

Views: 146

Answers (2)

sramzan
sramzan

Reputation: 96

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.

Upvotes: 1

Vaviloff
Vaviloff

Reputation: 16838

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.

Upvotes: 0

Related Questions