Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nightwatch

Package Overview
Dependencies
Maintainers
1
Versions
355
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nightwatch - npm Package Compare versions

Comparing version 0.2.8 to 0.3.0

examples/reports/alerts.xml

30

examples/tests/google.js

@@ -19,22 +19,14 @@ /**

client
.url('http://google.com');
client.waitForElementVisible('body', 1000);
client.getLocation("input[type=text]", function(result) {
console.log(result)
//this.assert.equal(typeof result, "object", "is object");
//this.assert.equal(result.value.height, 20, 'is 20');
});
client.assert.title('Google');
client.url(function(result) {
this.assert.ok(result.value.indexOf('google.nl') !== -1, 'Google url is ok');
});
client.assert.visible('input[type=text]')
.url('http://google.com')
.waitForElementVisible('body', 1000)
.getLocation("input[type=text]", function(result) {
this.assert.equal(result.value.height, 20, 'is 20');
})
.assert.title('Google')
.url(function(result) {
this.assert.ok(result.value.indexOf('google.nl') !== -1, 'Google url is ok');
})
.assert.visible('input[type=text]')
.setValue('input[type=text]', 'nightwatch')
.waitForElementVisible('button[name=btnG]', 1000)
//.setValue('input[type=text]', '2 nightwatch')
.waitForElementVisible('button[name=btnG]', 1000);
},

@@ -41,0 +33,0 @@

@@ -18,2 +18,3 @@ var util = require('util'),

this.terminated = false;
this.capabilities = {};

@@ -27,3 +28,2 @@ this.options.screenshots || (this.options.screenshots = {

this.screenshotPath = this.options.screenshotPath || '';
this.isRunning = false;
this.launch_url = this.options.launch_url || null;

@@ -306,14 +306,13 @@

var datestamp = d.toLocaleString('en-GB', {
weekday: 'narrow',
year: 'numeric',
month: '2-digit',
day: '2-digit',
timeZoneName : 'short',
hour : '2-digit',
minute : '2-digit',
second : '2-digit',
era : 'short'
}).replace(/\:/g,'').replace(/\s/g,'-').replace(/-\(.+?\)/,'');
weekday: 'narrow',
year: 'numeric',
month: '2-digit',
day: '2-digit',
timeZoneName : 'short',
hour : '2-digit',
minute : '2-digit',
second : '2-digit',
era : 'short'
}).replace(/\:/g,'').replace(/\s/g,'-').replace(/-\(.+?\)/,'');
var fileName = path.join(self.options.screenshots.path, 'ERROR_' + datestamp + '.png');
self.saveScreenshotToFile(fileName, screenshotContent);

@@ -396,3 +395,3 @@ }

if (typeof expectedValue != 'undefined' && typeof receivedValue != 'undefined') {
logged += ' ' + Logger.colors.white(' - expected "' + Logger.colors.green(expectedValue)) + '" but got: ' + Logger.colors.red(receivedValue);
logged += ' ' + Logger.colors.white(' - expected ' + Logger.colors.green('"' + expectedValue + '"')) + ' but got: ' + Logger.colors.red(receivedValue);
}

@@ -434,3 +433,3 @@

var errorCodes = require('./selenium/errors.json');
errorMessage = errorCodes[result.status].message || '';
errorMessage = errorCodes[result.status] && errorCodes[result.status].message || '';
}

@@ -461,8 +460,11 @@

self.sessionId = data.sessionId;
if (data.value) {
self.capabilities = data.value;
}
Logger.info('Got sessionId from selenium', self.sessionId);
self.emit('selenium:session_create', self.sessionId, request, response);
} else {
Logger.warn('Couldn\'t retrieve a new session from selenium server.');
}
})
} else {
Logger.warn('Couldn\'t retrieve a new session from selenium server.');
}
})
.on('error', function(data, err) {

@@ -469,0 +471,0 @@ console.error(Logger.colors.red('Connection refused!'), 'Is selenium server started?');

@@ -16,3 +16,11 @@ {

"25": {"id": "UnableToSetCookie", "message": "A request to set a cookie's value could not be satisfied."},
"28": {"id": "Timeout", "message": ""}
"26": {"id": "UnexpectedAlertOpen", "message": "A modal dialog was open, blocking this operation."},
"27": {"id": "NoAlertOpenError", "message": "An attempt was made to operate on a modal dialog when one was not open."},
"28": {"id": "Timeout", "message": ""},
"29": {"id": "InvalidElementCoordinates", "message": "The coordinates provided to an interactions operation are invalid."},
"30": {"id": "IMENotAvailable", "message": "IME was not available."},
"31": {"id": "IMEEngineActivationFailed", "message": "An IME engine could not be started."},
"32": {"id": "InvalidSelector", "message": "Argument was an invalid selector (e.g. XPath/CSS)."},
"33": {"id": "SessionNotCreatedException", "message": "A new session could not be created."},
"34": {"id": "MoveTargetOutOfBounds", "message": "Target provided for a move action is out of bounds."}
}

@@ -34,2 +34,6 @@ var Actions = {},

Actions.doubleClick = function(callback) {
return postRequest.call(this, '/doubleclick', callback);
};
/**

@@ -316,2 +320,32 @@ * Based on pull request from elfsternberg (https://github.com/elfsternberg);

/////////////////////////////////////////////////////////////////////////////
// Window specific commands
/////////////////////////////////////////////////////////////////////////////
Actions.window = function(method) {
method = method.toUpperCase();
switch (method) {
case 'POST':
if (arguments.length < 2) {
throw new Error('POST requests to /window must include a name parameter also.');
}
var handleOrName = arguments[1];
var callback = arguments[2] || function() {};
return postRequest.call(this, '/window', {
name : handleOrName
}, callback);
case 'DELETE':
var options = {
path : '/session/' + this.sessionId + '/window',
method : "DELETE"
}
var callback = arguments[1] || function() {};
return this.runProtocolCommand(options, callback).send();
default:
throw new Error('This method expects first argument to be either POST or DELETE.');
}
};
Actions.window_handle = function(callback) {

@@ -325,4 +359,68 @@ return getRequest.call(this, "/window_handle", callback);

/**
* Change or get the size of the specified window. If the second argument
* is a function it will be used as a callback and the call will perform
* a get request to retrieve the existing window size.
*
* @param {String} windowHandle
* @param {Number} width
* @param {Number} height
* @param {Function} height
*/
Actions.windowSize = function(windowHandle, width, height, callback) {
if (typeof windowHandle !== 'string') {
throw new Error('First argument must be a window handle string.');
}
var path = '/window/' + windowHandle + '/size';
if (arguments.length == 2 && typeof arguments[1] == 'function') {
return getRequest.call(this, path, arguments[1]);
}
width = Number(width);
height = Number(height);
if (typeof width !== 'number' || isNaN(width)) {
throw new Error('Width and height arguments must be passed as numbers.');
}
if (typeof height !== 'number' || isNaN(height)) {
throw new Error('Width and height arguments must be passed as numbers.');
}
return postRequest.call(this, path, {
width : width,
height : height
}, callback);
};
Actions.refresh = function(callback) {
return postRequest.call(this, "/refresh", callback);
};
/////////////////////////////////////////////////////////////////////////////
// Alert handling
/////////////////////////////////////////////////////////////////////////////
/**
* Accepts the currently displayed alert dialog. Usually, this is equivalent
* to clicking on the 'OK' button in the dialog.
*
* @param {Function} callback
*/
Actions.accept_alert = function(callback) {
return postRequest.call(this, "/accept_alert", callback);
};
/**
* Dismisses the currently displayed alert dialog. For confirm() and prompt()
* dialogs, this is equivalent to clicking the 'Cancel' button. For alert()
* dialogs, this is equivalent to clicking the 'OK' button.
*
* @param {Function} callback
*/
Actions.dismiss_alert = function(callback) {
return postRequest.call(this, "/dismiss_alert", callback);
};
/**
* GET /session/:sessionId/url - Retrieve the URL of the current page.

@@ -373,2 +471,5 @@ * POST /session/:sessionId/url - Navigate to a new URL.

/////////////////////////////////////////////////////////////////////////////
// Helpers
/////////////////////////////////////////////////////////////////////////////
function getRequest(path, callback) {

@@ -375,0 +476,0 @@ var options = {

{
"name": "nightwatch",
"description": "A node.js bindings implementation for selenium 2.0/webdriver",
"version": "0.2.8",
"version": "0.3.0",
"author": {

@@ -6,0 +6,0 @@ "name": "Andrei Rusu",

@@ -41,2 +41,10 @@ {

{
"url" : "/wd/hub/session/1352110219202/window",
"method": "DELETE"
},
{
"url" : "/wd/hub/session/1352110219202/window",
"method": "POST"
},
{
"url" : "/wd/hub/session/1352110219202/buttondown",

@@ -43,0 +51,0 @@ "postdata" : "{\"button\":1}",

@@ -17,3 +17,3 @@ var protocol = require('../../lib/selenium/protocol.js');

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"using":"id","value":"#weblogin"}');

@@ -32,3 +32,3 @@ test.equal(command.request.path, '/wd/hub/session/1352110219202/element');

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"using":"id","value":"#weblogin"}');

@@ -47,3 +47,3 @@ test.equal(command.request.path, '/wd/hub/session/1352110219202/elements');

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.data, '{}');

@@ -62,3 +62,3 @@ test.equal(command.request.path, '/wd/hub/session/1352110219202/element/active');

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.data, '');

@@ -77,3 +77,3 @@ test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/clear');

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/selected');

@@ -91,3 +91,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/enabled');

@@ -105,3 +105,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/ELEMENT1/equals/ELEMENT2');

@@ -119,3 +119,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/attribute/test_attr');

@@ -133,3 +133,3 @@ });

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/click');

@@ -147,3 +147,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/css/test_property');

@@ -161,3 +161,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/displayed');

@@ -175,3 +175,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/location');

@@ -189,3 +189,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/location_in_view');

@@ -203,3 +203,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/name');

@@ -217,3 +217,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/size');

@@ -231,3 +231,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/text');

@@ -245,3 +245,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/value');

@@ -259,3 +259,3 @@ });

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"value":["t","e","s","t"]}');

@@ -274,3 +274,3 @@ test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/value');

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"script":"<script>test();</script>","args":["arg1"]}');

@@ -289,3 +289,3 @@ test.equal(command.request.path, '/wd/hub/session/1352110219202/execute');

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.request.path, '/wd/hub/session/1352110219202/frame');

@@ -303,3 +303,3 @@ });

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"id":"testFrame"}');

@@ -318,3 +318,3 @@ test.equal(command.request.path, '/wd/hub/session/1352110219202/frame');

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"button":0}');

@@ -357,3 +357,3 @@ test.equal(command.request.path, '/wd/hub/session/1352110219202/buttondown');

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"button":2}');

@@ -372,3 +372,3 @@ test.equal(command.request.path, '/wd/hub/session/1352110219202/buttonup');

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"element":"testElement","xoffset":0,"yoffset":1}');

@@ -378,2 +378,28 @@ test.equal(command.request.path, '/wd/hub/session/1352110219202/moveto');

},
testRefresh : function(test) {
var client = this.client;
this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.actions.refresh.call(client, function callback() {
test.done();
});
test.equal(command.request.method, 'POST');
test.equal(command.request.path, '/wd/hub/session/1352110219202/refresh');
});
},
testDoubleClick : function(test) {
var client = this.client;
this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.actions.doubleClick.call(client, function callback() {
test.done();
});
test.equal(command.request.method, "POST");
test.equal(command.request.path, '/wd/hub/session/1352110219202/doubleclick');
});
},

@@ -388,3 +414,3 @@ testScreenshot : function(test) {

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/screenshot');

@@ -402,3 +428,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/status');

@@ -416,3 +442,3 @@ });

test.equal(command.request.method, "POST");
test.equal(command.request.method, 'POST');
test.equal(command.data, '');

@@ -431,3 +457,3 @@ test.equal(command.request.path, '/wd/hub/session/1352110219202/element/TEST_ELEMENT/submit');

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/title');

@@ -445,3 +471,3 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/window_handle');

@@ -459,7 +485,134 @@ });

test.equal(command.request.method, "GET");
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/window_handles');
});
},
testCloseWindow : function(test) {
var client = this.client;
this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.actions.window.call(client, 'DELETE', function callback() {
test.done();
});
test.equal(command.request.method, 'DELETE');
test.equal(command.request.path, '/wd/hub/session/1352110219202/window');
});
},
testSwitchWindow : function(test) {
var client = this.client;
this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.actions.window.call(client, 'POST', 'other-window', function callback() {
test.done();
});
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"name":"other-window"}');
test.equal(command.request.path, '/wd/hub/session/1352110219202/window');
});
},
testWindowCommand : function(test) {
var client = this.client;
this.client.on('selenium:session_create', function(sessionId) {
test.throws(
function() {
test.done();
protocol.actions.window.call(client, 'POST');
}, 'POST method without a name param throws an error'
);
test.throws(
function() {
protocol.actions.window.call(client, 'GET');
}, 'GET method throws an error'
);
});
},
testWindowSizeErrors : function(test) {
var client = this.client;
this.client.on('selenium:session_create', function(sessionId) {
test.throws(
function() {
protocol.actions.windowSize.call(client, function() {});
}, 'First argument must be a window handle string.'
);
test.throws(
function() {
protocol.actions.windowSize.call(client, 'current', 'a', 10);
}, 'Width and height arguments must be passed as numbers.'
);
test.throws(
function() {
protocol.actions.windowSize.call(client, 'current', 10);
}, 'Width and height arguments must be passed as numbers.'
);
test.throws(
function() {
test.done();
protocol.actions.windowSize.call(client, 'current', 10, 'a');
}, 'Width and height arguments must be passed as numbers.'
);
});
},
testWindowSizeGet : function(test) {
var client = this.client;
this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.actions.windowSize.call(client, 'current', function callback() {
test.done();
});
test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202/window/current/size');
});
},
testWindowSizePost : function(test) {
var client = this.client;
this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.actions.windowSize.call(client, 'current', 10, 10, function callback() {
test.done();
});
test.equal(command.request.method, 'POST');
test.equal(command.data, '{"width":10,"height":10}');
test.equal(command.request.path, '/wd/hub/session/1352110219202/window/current/size');
});
},
testAcceptAlert : function(test) {
var client = this.client;
this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.actions.accept_alert.call(client, function callback() {
test.done();
});
test.equal(command.request.method, 'POST');
test.equal(command.request.path, '/wd/hub/session/1352110219202/accept_alert');
});
},
testDismissAlert : function(test) {
var client = this.client;
this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.actions.dismiss_alert.call(client, function callback() {
test.done();
});
test.equal(command.request.method, 'POST');
test.equal(command.request.path, '/wd/hub/session/1352110219202/dismiss_alert');
});
},
tearDown : function(callback) {

@@ -466,0 +619,0 @@ this.client = null;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc