Comments (14)
@philipbeadle Thanks for that nice issue subject!
You should be able to load node modules using var mymodule = require(<module>)
in your implementation. You can also put a local package.json
and run npm install
in your test project root.
@renjithgr was working on a detailed example. It is still a work-in-progress AFAIK.
from gauge-js.
I did exactly that I think. I added a package.json file like so
{
"name": "gauge",
"version": "1.0.0",
"description": "testing out gauge with webdriver",
"main": "step_implementation.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"webdriverio": "^4.0.3",
"webdriverjs-angular": "^0.1.3"
}
}
ran npm install and then put
var webdriverjsAngular = require('webdriverjs-angular');
in the step_implmentation.js file
when I run
gauge specs/
I get
Philips-MBP-2:gaugeTest PhilBeadle$ gauge specs/
module.js:338
throw err;
^
Error: Cannot find module 'webdriverjs-angular'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at step_implementation.js:9:26
at ContextifyScript.Script.runInNewContext (vm.js:38:15)
at Object.exports.runInNewContext (vm.js:69:17)
at VM.run (/Users/PhilBeadle/.gauge/plugins/js/1.0.0/src/vm.js:17:6)
at VM.runFile (/Users/PhilBeadle/.gauge/plugins/js/1.0.0/src/vm.js:22:8)
at /Users/PhilBeadle/.gauge/plugins/js/1.0.0/src/impl-loader.js:9:8
from gauge-js.
cant wait to use this with webdriverjs-angular to start writing up proper specs that are executable!! Thanx heaps for the js runner!!
from gauge-js.
Nice catch @philipbeadle! Your package.json
is mostly right, except for calling your project as gauge
😄
Looks like the path to node_modules
in test project root in is not included in the list of paths to scan for node modules. Need to look into it, and if possible, write a quick patch :-)
Anyone up for it?
from gauge-js.
@philipbeadle I pushed a patch. That now loads node_modules from the test project root.
Is it possible for you to build from source and confirm if it works for you? Instructions to build from source is in the contributing guide.
from gauge-js.
I tried adding your one-liner to the index.js and got this error. Is PWD available on Windows?
λ gauge specs\
path.js:8
throw new TypeError('Path must be a string. Received ' +
^
TypeError: Path must be a string. Received undefined
at assertPath (path.js:8:11)
at Object.win32.join (path.js:221:5)
at Object.<anonymous> (C:\Users\portugai\AppData\Roaming\gauge\plugins\js\1.0.0\index.js:41:32)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
index.js
looks like this:
...
else if(process.argv[2] === "--start") {
var args = ["./src/gauge.js", "--run"];
var cmd = "node";
if (process.env.DEBUG === "true") {
cmd = process.platform === "win32" ? "debug.bat" : "node-debug";
}
process.env.NODE_PATH = path.join(process.env.PWD, "node_modules"); // Here's the new line (line 41)
if (process.platform === "win32") {
child_process.exec([cmd, args.join(" ")].join(" "), { env: process.env, stdio: "inherit" }, function (err) {
if (err) {
console.log(err);
}
});
} else {
var runner = child_process.spawn(cmd, args, { env: process.env, stdio: "inherit" });
runner.on("error", function (err) {
console.log(err);
});
}
}
package.json looks similar to @philipbeadle ...
{
"name": "gaugy",
"version": "1.0.0",
"description": "testing out gauge with webdriver",
"main": "example.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"devDependencies": {
"webdriverio": "^4.0.3",
"webdriverjs-angular": "^0.1.3"
}
}
from gauge-js.
Ill give it a crack today, thanx heaps for the patch :)
from gauge-js.
This seems to work for me (around line 41 in index.js):
var existingPath = process.env.PWD ? process.env.PWD : process.env.GAUGE_PROJECT_ROOT;
process.env.NODE_PATH = path.join(existingPath, "node_modules");
from gauge-js.
@philipbeadle have you had any luck running with webdriverio
? Mine seems to run but it doesn't error out. (the assert below should fail). I can even debug through this but getTitle()
function doesn't get called...
"use strict";
// Launch browser config
var webdriver = require('webdriverjs-angular');
var options = {
desiredCapabilities: {
browserName: 'chrome'
}
};
gauge.step("The word <word> has <number> vowels.", function(word, number) {
assert.equal(number, numberOfVowels(word)); // Ignore this :)
var client = webdriver
.remote(options)
.init()
.url('http://www.google.com')
.getTitle(function(title) {
console.log('Title was: ' + title); // function never fires
assert.equal('Google2', title);
})
.done();
gauge.message('The assert above should have failed...'); // This shows up on the report
});
I am running webdriver-manager start
on another console (selenium running on the default 4444 port in the background). I guess this is starting to turn into a webdriver discussion but would you guys recommend any particular web driver tool for gauge-js
?
from gauge-js.
I got the node_modules issue under control with the patch from @kaustavdm :)
Next Ill look into how promises are handled in the steps so we can wait for a step to complerte before the next step runs. I reckon thats why your test is not working as expected. I had the same issue with DaSpec and Gojko added in promise handling which fixed the issue.
Keep up the awesome people!!
from gauge-js.
Looks like gauge-js doesnt handle promises yet. We need to be able to do this like in DaSpec and protractor
defineStep(/Select a friend you wish to contact by clicking their name such as "(.*)"/, function (name) {
return element(by.cssContainingText('button', name)).click();
});
so the next step wont run until this one returns a promise :)
from gauge-js.
@ivanbportugal Your patch was absolutely right. In fact, it is safer for a language runner to use GAUGE_PROJECT_ROOT
because gauge
abstracts that out for platforms. I had missed that when pushing the last patch. It's fixed now. Works on Windows. Thanks!
@philipbeadle gauge-js handes async test implementations. We did not document it yet. Oops. It works by adding an extra argument to the step implementation that can be called when your async operation is done. Like this:
gauge.step("The word <word> has <number> vowels.", function(word, number, done) {
var stuff = asyncFnThatReturnsPromise();
stuff.then(function(result) {
assert(number, 5); // This assert will be called if the promise succeeds
done(); // This call ends this step's execution
}, function (err) {
// Some error handling here
done(); // This call ends this step's execution
});
});
AFAIK, async operation does not work for hooks yet. But it should be simple enough to get them to work.
Update: Even hooks support async operation. See this comment.
from gauge-js.
You can close this one, it all works beautifully with the patch.
from gauge-js.
@philipbeadle Glad it helped.
@ivanbportugal Thanks for the help!
from gauge-js.
Related Issues (20)
- Switch gauge-js to pure javascript grpc
- Unable to SetReadDeadLine on runner: set tcp 127.0.0.1:51101: use of closed network connection HOT 3
- Unable to add JS webdriver for gauge. HOT 2
- OpenBrowser failures are not reported correctly. HOT 2
- package.json can't be in directory above
- Incomplete Stacktraces on test failures
- Taiko confirm(func) doesn't work with gauge-js HOT 4
- Array parameters become non-array when passed from inside a step HOT 4
- multi-threads for js runner HOT 3
- AfterSuite hook receives a "null context value HOT 1
- AfterSuite hook receives a "null" context value HOT 4
- js runner quit unexpectedly. Check logs for more details HOT 1
- Feature request: access table data by column name instead of column index HOT 3
- How to use same table parameters used for a Gauge spec across multiple senarios? HOT 1
- example.spec has an error in ## Display number of items HOT 1
- Unable to install Gauge Js plugin HOT 2
- Unable to install Gauge Js plugin on mac HOT 7
- Unable to run async functions within a step table HOT 6
- NodeJs 16 Gauge-JS plugin installation takes an hour of time in Ubuntu Container HOT 3
- Failed to install plugin 'js' for Gauge HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gauge-js.