vendredi 3 avril 2015

Trouble with a Malformed Function definition and Using it via Inheritance

I'm using Cucumber.js and the PhantomJS-Node wrapper.


I'm not a guru at JavaScript yet or OOP or Closures and all that quite yet.


I've created a World.js for Cucumber so I can create some Phantom objects for example the page object that I wanna use in my Cucumber tests.


and in it I currently have:



var phantom = require('phantom');

var World = function World(callback) {

phantom.create("--web-security=no", "--ignore-ssl-errors=yes", { port: 12345 }, function (ph) {
var phantomProcess = ph;

this.createBrowserPage = function(){
phantomProcess.createPage(function(page) {

this.headlessPage = page;
});
};
});

callback();
};

exports.World = World;


I then have my Cucumber.js step_definitions.js which has:



this.World = require("../../support/world.js").World;

module.exports = function() {
"use strict";

this.createBrowserPage();

var page = this.headlessPage;

this.Given(/^I visit the customers display page$/, function (callback) {

page.open("/", function(status){

status.should.equal("success");
callback();
});
});

// ...etc.
};


(and then later I plan on adding a hook to stop the phantom session via phantomProcess.exit(). For now I just wanna get this issue resolved with the function I'm trying to call from my tests)


The problem I have is I get undefined is not a function for the line this.createBrowserPage() in my module.exports = function().


So I am probably not defining and exposing / inheriting that function correctly in my World.js and would like some help in how I can properly code that function and use it in my step definition.


Functions are first class citizens in JS right? So I assume what I've done is exposed World (exports.World = World) and I thought I was properly defining the createBrowserPage() as a property of the object World so I could use it elsewhere but apparently I'm not doing this right or this is not possible the way I'm trying to code all this.


Aucun commentaire:

Enregistrer un commentaire