Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling phantomJS function #253

Closed
appzone opened this issue Jul 25, 2017 · 4 comments
Closed

Calling phantomJS function #253

appzone opened this issue Jul 25, 2017 · 4 comments

Comments

@appzone
Copy link

appzone commented Jul 25, 2017

Hi, how can i call phantomJS function with mocha-phantomJs ?

let say i want to call
page.open(url, function (status) {
//Page is loaded!
phantom.exit();
});

how i do that in mocha-phantomjs ?
i read there is a callPhantom(), but how i use that ? thanks

@nathanboktae
Copy link
Owner

Why? What are you trying to do? For a page load, you can just repond to DOMContentLoaded in the browser.

@appzone
Copy link
Author

appzone commented Jul 26, 2017

i am trying to do page automation.
like this url http://phantomjs.org/page-automation.html

i am trying to achieve something like this

describe("Checkout from merchant", function() {
  	it("Should return application ID", function(){
			==> do some phantomJS page automation
  	});

  });

is it possible ?

my code is

  describe("Checkout from merchant", function() {
  	it("Should return application ID", function(){
		page.open('http://www.httpuseragent.org', function(status) {
		  if (status !== 'success') {
		    console.log('Unable to access network');
		  } else {
		    var ua = page.evaluate(function() {
		      return document.getElementById('myagent').textContent;
		    });
		    console.log(ua);
		  }
		  phantom.exit();
		});
  	});

  });

but i got this error page is not defined

error_phantom

in the phantomJs example i must declare the page with
var page = require('webpage').create();

if i put that, i get following error

Uncaught ReferenceError: require is not defined
    at page_one.js:1

@appzone
Copy link
Author

appzone commented Jul 26, 2017

btw i find another solution. separate between mocha and phantomjs instance

but i just want to know if is it possible to do like my comment description upper.

thanks

@nathanboktae
Copy link
Owner

nathanboktae commented Jul 31, 2017

This is not the project you want. It is not for externally automating page crawls - it is for extracting mocha test results on a single page. Please use mocha-casperjs or (Nightmare.js)[https://github.com/segmentio/nightmare]. I'd recommend the later as it uses the more modern Electron, as phantomjs is far behind, based on QT5 and without maintainers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants