nathanboktae / mocha-phantomjs

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

Use this as a bridge? #226

Closed dschinkel closed 8 years ago

dschinkel commented 8 years ago

So is mocha-phantomjs a phantom-to-node bridge?

If so, if I want to start using the Phantom API, what syntax should I use? I mean there are other bridges out there like phantomjs-node which have their own wrapper syntax but what if I'm using mocha-phantomjs?

example lets say I want to do this in my some-spec.js:

before(function() {
    phantom.create().then(function(ph) {
        ph.createPage().then(function(page) {
            page.open('https://stackoverflow.com/').then(function(status) {
                status = status
            })
        });
    });
})

the above is phantomjs-node syntax as I have phantom = require('phantom') at the top of my file. So would I use phantomjs-node in conjunction with mocha-phantomjs or what?

I'm able to run my tests through my test-runner.html but then I really just want to run this via command-line like I have been which is mocha-phantomjs test/features/specs/test-runner.html which works as in I can get my test to pass without the phantom api stuff. Once I try to introduce the phantom code above, it bombs after I bundle my spec.

dschinkel commented 8 years ago

what I essentially want to do is something like this with mocha http://www.redotheweb.com/2013/01/15/functional-testing-for-nodejs-using-mocha-and-zombie-js.html

So is all I need is mocha-phantomjs meaning I can require('mocha-phantomjs') and it provides a wrapper (bridge) to phantom so I can create page objects and work with that in my tests?

nathanboktae commented 8 years ago

So is mocha-phantomjs a phantom-to-node bridge?

No, it's not. It's a way to use phantomjs as your browser to test your client side mocha tests in that browser. Node.js is used as the command line parser and npm as the distribution mechanism, but that's it. The core brains is in mocha-phantomjs-core which that project has no Node.js

Mocha runs in the browser, so you write browser tests in Mocha. Just as if you were to run your browser tests in mocha by opening Chrome and going to file://foo/bar/tests.html or whatever the URL is, you instead use mocha-phantomjs to run those client side tests and output the results using other mocha reporters to the console.

If you want to write tests where your driving phantom clicking a page, there are other drivers for it like you linked to zombie.js or whatnot.

dschinkel commented 8 years ago

ok so when you say "you write browser tests in Mocha" you would just in your mocha tests work with the DOM (window, ect), not the phantomJS page object? Yea I'm probably needing Casper or Zombie...

dschinkel commented 8 years ago

I think it would be very helpful to have more of an intro on your mocha-phantomjs page. For someone new to this, you just dive into getting it installed and really don't explain the use case for using it or use cases. I get that it allows you to run mocha tests in the browser, ok fine but then what's the use case around that with tests. I think it would be helpful to show examples of mocha tests. The tests that are core to moch-phantomjs lib doesn't work with any DOM elements, etc. because it's core code, so having some additional test examples using mocha running in the .html would be nice. Just a suggestion

nathanboktae commented 8 years ago

Yes, the tests run in the browser, so you can internally fill in form using DOM APIs and such. Or more unit-style tests, whatever - but you're running inside the page.

If you go the casper route I'll point you to mocha-casperjs, but there's lots of options in this space including Nightmarejs, which uses Electron instead of phantomjs so it's not truly headless (similarly you can use slimerjs with casperjs)

dschinkel commented 8 years ago

thanks nathan!