nathanboktae / mocha-phantomjs

:coffee: :ghost: Run client-side mocha tests in the command line through phantomjs
MIT License
954 stars 112 forks source link

Calling phantomJS function #253

Closed appzone closed 7 years ago

appzone commented 7 years ago

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 commented 7 years ago

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

appzone commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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.