Skip to content

Commit

Permalink
Merge pull request #352 from angrykoala/dev
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
angrykoala authored May 3, 2019
2 parents 17289e1 + 937c4fa commit 94272f4
Show file tree
Hide file tree
Showing 126 changed files with 4,545 additions and 3,768 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ typings/

ncp/
.DS_Store
dist/
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test:
stage: test
retry: 2
script:
- npm run lint
- npm run eslint
- npm run tslint
- npm run markdown-lint
- npm test
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ env:
- NO_SANDBOX=true

script:
- npm run lint
- npm run eslint
- npm run tslint
- npm run markdown-lint
- travis_retry npm test

Expand Down
1 change: 1 addition & 0 deletions @types/compositer/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'compositer';
1 change: 1 addition & 0 deletions @types/is-class/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'is-class';
35 changes: 30 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
1.13.1 / 2018-04-20
2.0.0 / 2019-05-03
==================

* Wendigo refactored into TypeScript
* Browser.query and browser.queryAll now support XPath selectors
* Browser.queryXPath removed
* Removed clearRequestMocks option, mocks are only removed on browser close
* Cookies now support extra cookie parameters
* XPath improvements with axis support and minor fixes
* Added new methods to DomElement class
* More support for XPath and DOMElement selectors
* Complex subqueries with multiple parent elements supported
* Changes in plugin system. Dropped support for not assertions
* Removed deprecated methods assert.cookie, assert.webworker and assert.not.cookie
* Browser.request.all changed into a function to make it consistent with other modules
* WaitForRequest/Response and waitForNextRequest/Response moved to requests module
* Browser.assert.request renamed to browser.assert.requests to keep consistency
* Assertions now always return promises for consistency
* Fixed bug where settings on dialog module where not being updated properly
* Fixed bug where mocks with querystring where not being updated properly
* Removed dependency mixwith
* Dependencies updated
* Puppeteer updated to 1.15
* Readme updated and several minor fixes in it

1.13.1 / 2019-04-20
===================

* Some dependencies updated
* Deprecation notice in favor of 2.0

1.13.0 / 2018-03-29
1.13.0 / 2019-03-29
===================

* Support for an object with assert and not functions for a plugin
Expand All @@ -15,13 +40,13 @@
* Cookies is now fully implemented as a plugin
* ElementFromPoint not returns null if no element is found

1.12.1 / 2018-03-25
1.12.1 / 2019-03-25
===================

* Minor improvements to dockerfile
* Fix of console.warn logs when set the option log: true

1.12.0 / 2018-03-25
1.12.0 / 2019-03-25
===================

* Browser.assert.tag and browser.assert.not.tag
Expand All @@ -30,7 +55,7 @@
* Added proxyServer option in create browser
* Minor fixes in some error messages

1.11.0 / 2018-03-24
1.11.0 / 2019-03-24
===================

* Browser.triggerEvent
Expand Down
879 changes: 425 additions & 454 deletions README.md

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions config.js → config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"use strict";
const path = require('path');
import * as path from 'path';

module.exports = {
export default {
injectionScripts: {
path: path.join(__dirname, "injection_scripts"),
path: path.join(__dirname, "..", "injection_scripts"),
files: [
"selector_query.js",
"wendigo_utils.js",
Expand Down
11 changes: 11 additions & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare namespace WendigoUtils {
function isVisible(element: HTMLElement): boolean;
function queryElement(selector: string | HTMLElement): HTMLElement;
function queryAll(selector: string | HTMLElement): Array<HTMLElement>;
function xPathQuery(xPath: string): Array<HTMLElement>;
function getStyles(element: string | HTMLElement): { [s: string]: string };
function mockDate(timestamp: number, freeze: boolean): void;
function clearDateMock(): void;
function findCssPath(node: HTMLElement): string;
function findXPath(node: HTMLElement): string;
}
8 changes: 4 additions & 4 deletions injection_scripts/wendigo_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ if (!window.WendigoUtils) {
clearDateMock() {
window.Date = _origDate;
},
findCssPath(...args) {
return WendigoPathFinder.cssPath(...args);
findCssPath(node) {
return WendigoPathFinder.cssPath(node);
},
findXPath(...args) {
return WendigoPathFinder.xPath(...args);
findXPath(node) {
return WendigoPathFinder.xPath(node);
}
};
}
87 changes: 87 additions & 0 deletions lib/browser/assertions/assert_elements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { rejectAssertion } from '../../utils/assert_utils';
import { isNumber } from '../../utils/utils';
import { WendigoSelector } from '../../types';

enum CountCase {
equal = "equal",
atLeast = "atLeast",
atMost = "atMost",
both = "both"
}

interface CountConfig {
equal?: number;
atLeast?: number;
atMost?: number;
}

export function parseCountInput(count: CountConfig | number): CountConfig {
let result: CountConfig;
if (isNumber(count)) {
result = {
equal: Number(count)
};
} else result = count;
return result;
}

export function getCountCase(count: CountConfig): CountCase | null {
let countCase: CountCase | null = null;
if (isNumber(count.equal)) {
countCase = CountCase.equal;
} else {
if (isNumber(count.atLeast)) {
countCase = CountCase.atLeast;
}
if (isNumber(count.atMost)) {
countCase = countCase ? CountCase.both : CountCase.atMost;
}
}
return countCase;
}

export function makeAssertion(selector: WendigoSelector, countData: CountConfig, countCase: CountCase, elementsFound: number, msg?: string): Promise<void> {
switch (countCase) {
case CountCase.equal:
return equalAssertion(countData, elementsFound, msg, selector);
case CountCase.atLeast:
return atLeastAssertion(countData, elementsFound, msg, selector);
case CountCase.atMost:
return atMostAssertion(countData, elementsFound, msg, selector);
case CountCase.both:
return bothAssertion(countData, elementsFound, msg, selector);
}
}

async function equalAssertion(countData: CountConfig, elementsFound: number, msg: string | undefined, selector: WendigoSelector): Promise<void> {
const expected = Number(countData.equal);
if (elementsFound !== expected) {
if (!msg) msg = `Expected selector "${selector}" to find exactly ${countData.equal} elements, ${elementsFound} found`;
return rejectAssertion("assert.elements", msg, elementsFound, expected);
}
}

async function atLeastAssertion(countData: CountConfig, elementsFound: number, msg: string | undefined, selector: WendigoSelector): Promise<void> {
const expected = Number(countData.atLeast);
if (elementsFound < expected) {
if (!msg) msg = `Expected selector "${selector}" to find at least ${countData.atLeast} elements, ${elementsFound} found`;
return rejectAssertion("assert.elements", msg);
}
}

async function atMostAssertion(countData: CountConfig, elementsFound: number, msg: string | undefined, selector: WendigoSelector): Promise<void> {
const expected = Number(countData.atMost);
if (elementsFound > expected) {
if (!msg) msg = `Expected selector "${selector}" to find up to ${countData.atMost} elements, ${elementsFound} found`;
return rejectAssertion("assert.elements", msg);
}
}

async function bothAssertion(countData: CountConfig, elementsFound: number, msg: string | undefined, selector: WendigoSelector): Promise<void> {
const most = Number(countData.atMost);
const least = Number(countData.atLeast);
if (elementsFound < least || elementsFound > most) {
if (!msg) msg = `Expected selector "${selector}" to find between ${countData.atLeast} and ${countData.atMost} elements, ${elementsFound} found`; // eslint-disable-line max-len
return rejectAssertion("assert.elements", msg);
}
}
Loading

0 comments on commit 94272f4

Please sign in to comment.