Socket
Socket
Sign inDemoInstall

nightwatch-commands

Package Overview
Dependencies
36
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.6.2 to 1.7.0

commands/waitForContextsReady.js

2

.github/PULL_REQUEST_TEMPLATE.md
Status: **Ready for Review** or **Open for Visibility**
Owner:
Reviewers: @ellenmobify @marlowpayne @mobify-derrick
Reviewers: @ellenmobify @marlowpayne @mikenikles

@@ -5,0 +5,0 @@ ## Changes

@@ -6,3 +6,3 @@ exports.command = function(callback) {

//
return client.waitForCondition('return $.active;', 8000, function(result) {
return client.waitForCondition('return jQuery.active;', 8000, function(result) {
if (typeof callback === 'function') {

@@ -9,0 +9,0 @@ callback.call(client, result);

{
"name": "nightwatch-commands",
"version": "1.6.2",
"version": "1.7.0",
"description": "A set of Mobify specific custom commands for Nightwatch.js",

@@ -14,5 +14,6 @@ "repository": {

"devDependencies": {
"nightwatch": "0.8.6",
"nightwatch": "0.9.1",
"nodeunit": "~0.8.4",
"grunt": "0.4.5",
"grunt-cli": "~0.1.13",
"grunt-eslint": "^17.0.0",

@@ -23,3 +24,3 @@ "mobify-code-style": "^2.3.6"

"install": "node selenium/installation/install.js",
"test": "grunt lint"
"test": "./node_modules/.bin/grunt lint; ./node_modules/.bin/grunt test"
},

@@ -26,0 +27,0 @@ "homepage": "https://github.com/mobify/nightwatch-commands",

@@ -331,2 +331,22 @@ nightwatch-commands

#### waitForContextsReady(expectedContextsCount, milliseconds, timeout, messages, callback)
The `waitForContextsReady` command receives a number of expected contexts to check for, waits for a maximum time before timing out, and polls at a specified time interval. Used with Appium when testing hybrid mobile web apps. See http://nightwatchjs.org/api/contexts.html
Parameter Name | Parameter Type | Description
------------- | -------------- | -----------
expectedContextsCount | Number | The condition to check against.
milliSeconds | Number | _optional_ The number of milliseconds to poll before timeout.
timeout | Number | _optional_ The number of milliseconds between each poll.
message | String | _optional_ The message to output.
callback | Function | _optional_ A function to call after the current command finishes execution.
```
this.demoTest = function (browser) {
browser.waitForContextsReady(3, 8000);
// At this point, it is safe to switch the context to either the NATIVE
// context or any of the WEBVIEW_* contexts.
};
```
#### waitForUrl(url, milliseconds, timeout, messages, callback)

@@ -333,0 +353,0 @@

{
"port" : 10195,
"mocks" : [
{
"url" : "/wd/hub/session",
"postdata" : "{\"desiredCapabilities\":{\"browserName\":\"firefox\",\"javascriptEnabled\":true,\"acceptSslCerts\":true,\"platform\":\"ANY\"},\"sessionId\":null}",
"response" : "{\"status\": 0, \"sessionId\": \"1352110219202\", \"value\": { \"javascriptEnabled\": true, \"browserName\": \"firefox\"}, \"state\": null}",
"responseHeaders" : {
},
"statusCode" : 200,
"method": "POST"
},
{
"port": 10195,
"mocks": [{
"url": "/wd/hub/session",
"postdata": "",
"response": "{\"status\": 0, \"sessionId\": \"1352110219202\", \"value\": { \"javascriptEnabled\": true, \"browserName\": \"firefox\", \"version\": \"TEST\", \"platform\": \"TEST\"}, \"state\": null}",
"responseHeaders": {},
"statusCode": 201,
"method": "POST"
}, {
"url" : "/wd/hub/session/1352110219202",
"method": "DELETE"
},
{
"postdata" : "",
"response" : "{\"status\":0,\"value\":true}"
}, {
"url" : "/wd/hub/session/1352110219202",
"postdata" : "",
"response" : "{\"status\":0,\"value\":false}"
}, {
"url" : "/wd/hub/session/1352110219202",
"method": "DELETE",
"postdata" : "",
"response" : "{\"status\":0,\"value\":false}"
}, {
"url" : "/wd/hub/session/1352110219202/url",
"method": "GET",
"postdata" : ""
}, {
"url" : "/wd/hub/session/1352110219202/url",
"method": "POST",
"postdata" : "{\"url\":\"http://localhost\"}"
},
{
"url" : "/wd/hub/test",
"response" : "{\"status\":0}"
},
{
"url" : "/wd/hub/test_error",
"response" : "{\"status\":7,\"value\":{\"screen\":\"screenshot_data\"}}",
"statusCode" : 500
},
{
"url" : "/wd/hub/session/1352110219202/element",
"postdata" : "{\"using\":\"css selector\",\"value\":\"body\"}",
"response" : "{\"sessionId\":\"1352110219202\",\"status\":0,\"value\":{\"ELEMENT\":\"0\"},\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":604376696}"
},
{
"url" : "/wd/hub/session/1352110219202/element",
"postdata" : "{\"using\":\"css selector\",\"value\":\"#weblogin\"}",
"response" : "{\"sessionId\":\"1352110219202\",\"status\":0,\"value\":{\"ELEMENT\":\"0\"},\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":604376696}"
},
{
"url" : "/wd/hub/session/1352110219202/buttondown",
"postdata" : "{\"button\":0}",
"response" : "{\"sessionId\":\"1352110219202\",\"status\":0,\"class\":\"org.openqa.selenium.remote.Response\",\"hCode\":604376696}"
},
{
}, {
"url" : "/wd/hub/session/1352110219202/url",
"method": "GET",
"postdata" : "",
"response" : "{\"value\":\"http://localhost/\",\"status\":0}"
}, {
"url" : "/wd/hub/session/null/url",
"method": "GET",
"postdata" : ""
}, {
"url" : "/wd/hub/session/1352110219202/execute",
"postdata" : "{\"script\":\"return true;\",\"args\":[]}",
"response" : "{\"status\":0,\"value\":true}"
},
{
}, {
"url" : "/wd/hub/session/1352110219202/execute",
"postdata" : "{\"script\":\"return false\",\"args\":[]}",
"response" : "{\"status\":0,\"value\":false}"
}, {
"url" : "/wd/hub/session/1352110219202/execute",
"postdata" : "{\"script\":\"return Mobify.evaluatedData;\",\"args\":[]}",
"response" : "{\"status\":0,\"value\":true}"
},
{
"url" : "/wd/hub/session/1352110219202/execute",
"postdata" : "{\"script\":\"var passedArgs = Array.prototype.slice.call(arguments,0); return function (sel, t) { var event = new MouseEvent(t || 'click', { 'view': window, 'bubbles': true, 'cancelable': true }); var el = document.querySelector(sel); el.dispatchEvent(event); return true; }.apply(window, passedArgs);\",\"args\":[\".clickMe\",null]}",
}, {
"url" : "/wd/hub/session/null/execute",
"method": "POST",
"postdata": "{\"script\":\"var passedArgs = Array.prototype.slice.call(arguments,0); return function () {\\n var framework = Mobify || Adaptive;\\n return !!framework;\\n }.apply(window, passedArgs);\",\"args\":[]}",
"response" : "{\"status\":0,\"value\":true}"
},
{
}, {
"url" : "/wd/hub/session/1352110219202/execute",
"postdata" : "{\"script\":\"var passedArgs = Array.prototype.slice.call(arguments,0); return function (sel, t) { var event = new MouseEvent(t || 'click', { 'view': window, 'bubbles': true, 'cancelable': true }); var el = document.querySelector(sel); el.dispatchEvent(event); return true; }.apply(window, passedArgs);\",\"args\":[\".clickMe\",\"click\"]}",
"method": "POST",
"postdata": "{\"script\":\"var passedArgs = Array.prototype.slice.call(arguments,0); return function () {\\n var framework = Mobify || Adaptive;\\n return !!framework;\\n }.apply(window, passedArgs);\",\"args\":[]}",
"response" : "{\"status\":0,\"value\":true}"
},
{
}, {
"url" : "/wd/hub/session/1352110219202/execute",
"method": "POST",
"postdata": "{\"script\":\"var passedArgs = Array.prototype.slice.call(arguments,0); return function (){ var framework = Mobify || Adaptive; return !!framework; }.apply(window, passedArgs);\",\"args\":[]}",
"response" : "{\"status\":0,\"value\":true}"
},
{
}, {
"url" : "/wd/hub/session/1352110219202/execute",
"postdata": "{\"script\":\"var passedArgs = Array.prototype.slice.call(arguments,0); return function () {\\n var framework = Mobify || Adaptive;\\n return framework ? framework.evaluatedData : null;\\n }.apply(window, passedArgs);\",\"args\":[]}",
"response" : "{\"status\":0,\"value\":true}"
}, {
"url" : "/wd/hub/session/1352110219202/execute",
"postdata" : "{\"script\":\"var passedArgs = Array.prototype.slice.call(arguments,0); return function (sel, t) {\\n var event = new MouseEvent(t || 'click', {\\n 'view': window,\\n 'bubbles': true,\\n 'cancelable': true\\n });\\n var el = document.querySelector(sel);\\n el.dispatchEvent(event);\\n return true;\\n }.apply(window, passedArgs);\",\"args\":[\".clickMe\",\"click\"]}",
"response" : "{\"status\":0,\"value\":true}"
}, {
"url" : "/wd/hub/session/1352110219202/execute",
"postdata" : "{\"script\":\"var passedArgs = Array.prototype.slice.call(arguments,0); return function (sel, t) {\\n var event = new MouseEvent(t || 'click', {\\n 'view': window,\\n 'bubbles': true,\\n 'cancelable': true\\n });\\n var el = document.querySelector(sel);\\n el.dispatchEvent(event);\\n return true;\\n }.apply(window, passedArgs);\",\"args\":[\".clickMe\",null]}",
"response" : "{\"status\":0,\"value\":true}"
}, {
"url" : "/wd/hub/session/1352110219202/execute",
"postdata" : "{\"script\":\"return $.active;\",\"args\":[]}",
"response" : "{\"status\":0,\"value\":0}"
}
]
}, {
"url" : "/wd/hub/session/1352110219202/contexts",
"method": "GET",
"postdata" : "",
"response" : "{\"status\":0,\"value\":[\"NATIVE\", \"WEBVIEW_1\", \"WEBVIEW_2\"]}"
}]
}
var nightwatch = require('../node_modules/nightwatch');
module.exports = {
init : function(callback) {
return nightwatch.client({
// desiredCapabilities: {
// browserName: 'chrome'
// },
init: function(options, callback) {
var opts = {
seleniumPort: 10195,
silent: true,
output: false,
globals: {
myGlobal: 'test'
},
desiredCapabilities: {
browserName: 'chrome'
},
/* eslint-disable camelcase */
custom_commands_path: '../commands',
custom_assertions_path: '../assertions',
selenium_port : 10195,
custom_assertions_path: '../assertions'
/* eslint-enable camelcase */
silent : true,
output : false
}).start().once('error', function() {
};
if (options) {
for (var prop in options) {
if (options.hasOwnProperty(prop)) {
opts[prop] = options[prop];
}
}
}
return nightwatch.client(opts).on('selenium:session_create', function() {
if (callback) {
callback();
}
}).once('error', function() {
if (callback) {
callback();
}
process.exit();
});
}).start();
}
};
var http = require('http');
var mocks = null;
function mockServer(options) {
function mockServer(options, callback) {
// The default options:

@@ -10,4 +10,7 @@ var defaultOptions = {

responseHeaders: {},
responseType: 'application/json',
responseType: 'application/json'
};
callback = callback || function() {};
for (var k in defaultOptions) {

@@ -18,60 +21,60 @@ options[k] = (options[k] || defaultOptions[k]);

if (Array.isArray(options.mocks)) {
mocks = options.mocks;
mocks = options.mocks;
}
// Prepare the next request:
function nextInLine(req, postdata) {
var mockFound = false;
var mockFound = false;
// console.log('postdata', postdata);
// console.log('req.url', req.url);
mocks.forEach(function(item) {
item.postdata = item.postdata || '';
item.method = item.method || 'POST';
item.statusCode = item.statusCode || 200;
mocks.forEach(function(item) {
item.postdata = item.postdata || '';
item.method = item.method || 'POST';
item.statusCode = item.statusCode || 200;
if (item.url == req.url && item.method == req.method && item.postdata == postdata) {
item.responseHeaders = item.responseHeaders || {};
item.response = item.response || '';
mockFound = item;
}
});
// console.log(mockFound)
return mockFound;
if ((item.url == req.url) && (item.method == req.method) && (item.postdata == postdata || !item.postdata)) {
item.responseHeaders = item.responseHeaders || {};
item.response = item.response || '';
mockFound = item;
}
});
return mockFound;
}
var s = http.createServer(function(req, res) {
var postdata = '';
var headers;
req.setEncoding('utf8');
req.on('data', function(chunk) {
postdata += chunk;
});
req.on('end', function() {
var item = nextInLine(req, postdata);
var responsedata = '';
if (item) {
headers = item.responseHeaders;
headers['Content-Type'] = options.responseType;
headers['Content-Length'] = item.response.length;
res.writeHead(Number(item.statusCode), headers);
responsedata = item.response;
} else {
headers = {};
headers['Content-Type'] = options.responseType;
headers['Content-Length'] = 0;
res.writeHead(200, 'OK', headers);
}
if (typeof options.finishedCallback == 'function') {
options.finishedCallback(req, res);
}
res.end(responsedata);
});
});
var postdata = '';
var headers;
req.setEncoding('utf8');
req.on('data', function(chunk) {
postdata += chunk;
});
req.on('end', function() {
var item = nextInLine(req, postdata);
var responsedata = '';
if (item) {
headers = item.responseHeaders;
headers['Content-Type'] = options.responseType;
headers['Content-Length'] = item.response.length;
res.writeHead(Number(item.statusCode), headers);
responsedata = item.response;
} else {
// Keep this for debugging
// console.log('MOCK NOT FOUND');
// console.log('REQUEST URL: ', req.url);
// console.log('REQUEST METHOD: ', req.method);
// console.log('REQUEST POST DATA: ', postdata);
headers = {};
headers['Content-Type'] = options.responseType;
headers['Content-Length'] = 0;
res.writeHead(200, 'OK', headers);
}
s.listen(options.port, function() {
options.listenCallback = options.listenCallback || function() {};
options.listenCallback();
if (typeof options.finishedCallback == 'function') {
options.finishedCallback(req, res);
}
res.end(responsedata);
});
});
s.listen(options.port, callback);
return s;

@@ -81,19 +84,19 @@ }

module.exports = {
init : function() {
var i;
var mockoptions = require('../mocks.json');
try {
i = new mockServer(mockoptions);
} catch (err) {
console.log(err);
init: function(callback) {
var i;
var mockoptions = require('../mocks.json');
try {
i = new mockServer(mockoptions, callback);
} catch (err) {
console.log(err);
}
return i;
},
addMock: function(mock) {
if (Array.isArray(mocks)) {
mocks.push(mock);
return true;
}
return false;
}
return i;
},
addMock : function(mock) {
if (Array.isArray(mocks)) {
mocks.push(mock);
return true;
}
return false;
}
};

@@ -27,4 +27,10 @@ try {

server.on('listening', function() {
reporter.run(['src'], options, function() {
server.close();
reporter.run(['src'], options, function(err) {
setTimeout(function() {
server.close();
}, 100);
if (err) {
process.exit(1);
}
});

@@ -31,0 +37,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc