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

browser-monkey

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-monkey - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

59

index.js

@@ -197,4 +197,5 @@ var retry = require('trytryagain');

Selector.prototype.findElement = function () {
Selector.prototype.findElement = function (options) {
var self = this;
var allowMultiple = options && options.hasOwnProperty('allowMultiple')? options.allowMultiple: false;

@@ -217,3 +218,7 @@ function findWithFinder(el, finderIndex) {

return findWithFinder($(this.selector || 'body'), 0);
var elements = findWithFinder($(this.selector || 'body'), 0);
if (!allowMultiple && elements.length !== 1) {
throw new Error("expected to find exactly one element: " + self.printFinders(self.finders));
}
return elements;
};

@@ -223,12 +228,21 @@

var self = this;
var allowMultiple = options && options.hasOwnProperty('allowMultiple')? options.allowMultiple: false;
return retry(function() {
var els = self.findElement();
return retry(options, function() {
return self.findElement(options);
});
};
if (!allowMultiple && els.length !== 1) {
throw new Error("expected to find exactly one element: " + self.printFinders(self.finders));
Selector.prototype.notResolve = function(options) {
var self = this;
return retry.ensuring(options, function() {
var found = false;
try {
self.findElement({allowMultiple: true});
found = true;
} catch (e) {
}
return els;
if (found) {
throw new Error("didn't expect to find element: " + self.printFinders(self.finders));
}
});

@@ -245,2 +259,6 @@ };

Selector.prototype.shouldNotExist = function (options) {
return this.notResolve(options);
};
Selector.prototype.elements = function (options) {

@@ -255,11 +273,18 @@ return this.resolve({allowMultiple: true});

Selector.prototype.has = function(options) {
return this.addFinder(elementTester(options)).shouldExist({allowMultiple: true});
return this.shouldHave(options);
};
Selector.prototype.shouldHave = function(options) {
return this.has(options);
var resolveOptions;
if (typeof options === 'object') {
resolveOptions = JSON.parse(JSON.stringify(options));
resolveOptions.allowMultiple = true;
} else {
resolveOptions = {allowMultiple: true};
}
return this.addFinder(elementTester(options)).shouldExist(resolveOptions);
};
Selector.prototype.click = function() {
return this.resolve().then(function($element) {
Selector.prototype.click = function(options) {
return this.resolve(options).then(function($element) {
return sendclick($element[0]);

@@ -269,4 +294,4 @@ });

Selector.prototype.typeIn = function(text) {
return this.resolve().then(function($element) {
Selector.prototype.typeIn = function(text, options) {
return this.resolve(options).then(function($element) {
return sendkeys($element[0], text);

@@ -276,4 +301,4 @@ });

Selector.prototype.typeInHtml = function(html) {
return this.resolve().then(function($element) {
Selector.prototype.typeInHtml = function(html, options) {
return this.resolve(options).then(function($element) {
return sendkeys.html($element[0], html);

@@ -280,0 +305,0 @@ });

{
"name": "browser-monkey",
"version": "1.4.0",
"version": "1.5.0",
"description": "reliable dom testing",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -191,7 +191,24 @@ # browser monkey

```js
var promise = scope.shouldExist();
var promise = scope.shouldExist([options]);
```
* `options.timeout` - length of time to wait for the element (1000ms)
* `options.interval` - time between testing the dom (10ms)
* `options.allowMultiple` - allow multiple elements to be found, default just one
Returns a promise that resolves when the element exists, or is rejected if the timeout expires.
## shouldNotExist
Wait a while for to be sure the element doesn't exist.
```js
var promise = scope.shouldNotExist([options]);
```
* `options.duration` - the duration to wait, default 1000ms.
* `options.interval` - time between testing the dom
Returns a promise that resolves when the element doesn't exist, or is rejected if the timeout expires.
## shouldHave

@@ -202,5 +219,7 @@

```js
var promise = scope.shouldHave(options);
var promise = scope.shouldHave([options]);
```
* `options.timeout` - length of time to wait for the element (1000ms)
* `options.interval` - time between testing the dom (10ms)
* `options.text` - a string, expects the resolved scope to have the text. If an array of strings, expects the elements to have the same number of elements as there are strings in the array, and expects each string to be found in each respective element's text.

@@ -207,0 +226,0 @@ * `options.css` - a CSS string. Expects the resolved element to be matched by the CSS selector. Note that it won't match if the element contains other elements that match the CSS selector. So if we have `{css: '.class'}` then we expect the resolved element to have a class `class`.

@@ -31,2 +31,16 @@ var browser = require('..');

describe('shouldNotExist', function () {
it('should ensure that element never exists', function () {
var good = browser.find('.not-element').shouldNotExist();
var bad = browser.find('.element').shouldNotExist();
eventuallyInsertHtml('<div class="element"></div>');
return Promise.all([
good,
expect(bad).to.be.rejected
]);
});
});
it('should eventually click an element', function () {

@@ -33,0 +47,0 @@ var promise = browser.find('.element').click();

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