Skip to content

Commit

Permalink
Merge pull request #358 from angrykoala/dev
Browse files Browse the repository at this point in the history
Wendigo 2.0.2
  • Loading branch information
angrykoala authored May 20, 2019
2 parents e7c5926 + becd49f commit 247c9af
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 157 deletions.
5 changes: 4 additions & 1 deletion @types/is-class/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
declare module 'is-class';
declare module 'is-class' {
function isClass(a: any): boolean;
export = isClass;
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2.0.2 / 2019-05-21
==================

* FindByText and FindByTextContaining now support simple quotes (')
* Proper support for XPath on waitFor and watAndClick
* Some dependencies updated

2.0.1 / 2019-05-08
==================

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ await browser.url(); // my-page/home
**waitAndClick(selector, timeout=500)**
Waits for an element to exists and be visible before clicking it. Useful for clicking elements that may have a delay before appearing.

> Only Css Selectors supported.
> DomElements selectors not supported.
**tap(selector, index?)**
Performs a touchscreen tap action on all the elements matching the given selector, if the index parameter is set, only the nth element will be tapped. Returns the number of elements tapped. The interface is compatible with browser.click.
Expand Down Expand Up @@ -502,7 +502,7 @@ await browser.waitFor((s) => { // Waits for 2 or more elements to be in the page
}, 600, ".my-elements");
```

> Css selectors supported only.
> DomElements selectors not supported.
**waitUntilNotVisible(selector, timeout=500)**
Waits until the given selector is no longer visible or doesn't exists, with the given timeout in milliseconds.
Expand Down
6 changes: 3 additions & 3 deletions lib/browser/mixins/browser_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ElementHandle } from 'puppeteer';
import DomElement from '../../models/dom_element';
import { FatalError, WendigoError } from '../../errors';
import { WendigoSelector } from '../../types';
import { isXPathQuery } from '../../utils/utils';
import { isXPathQuery, cleanStringForXpath } from '../../utils/utils';

export default abstract class BrowserQueries extends BrowserCore {
public async query(selector: WendigoSelector, optionalSelector?: string): Promise<DomElement | null> {
Expand Down Expand Up @@ -57,7 +57,7 @@ export default abstract class BrowserQueries extends BrowserCore {
public async findByText(text: string | DomElement, optionalText?: string): Promise<Array<DomElement>> {
this._failIfNotLoaded("findByText");
const xPathText = optionalText || text as string;
const xPath = `//*[text()='${xPathText}']`;
const xPath = `//*[text()=${cleanStringForXpath(xPathText)}]`;

if (optionalText) {
try {
Expand All @@ -73,7 +73,7 @@ export default abstract class BrowserQueries extends BrowserCore {
public async findByTextContaining(text: string | DomElement, optionalText?: string): Promise<Array<DomElement>> {
this._failIfNotLoaded("findByTextContaining");
const xPathText = optionalText || text as string;
const xPath = `//*[contains(text(),'${xPathText}')]`;
const xPath = `//*[contains(text(),${cleanStringForXpath(xPathText)})]`;
if (optionalText) {
try {
return await this.queryAll(text, xPath);
Expand Down
4 changes: 2 additions & 2 deletions lib/browser_factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as compose from 'compositer';
import compose from 'compositer';
import isClass from 'is-class';
import { Page } from 'puppeteer';
import { isClass } from './utils/utils';

import Browser from './browser/browser';
import BrowserAssertion from './browser/browser_assertions';
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/requests/request_mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as EventEmitter from 'events';
import EventEmitter from 'events';
import { URL } from 'url';
import { Request } from 'puppeteer';

Expand Down
14 changes: 11 additions & 3 deletions lib/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as querystring from 'querystring';
import { URL } from 'url';
import * as isClassModule from 'is-class';

export function isNumber(n: any): n is number {
return !Number.isNaN(Number(n));
Expand Down Expand Up @@ -95,6 +94,15 @@ export function arrayfy<T>(raw: T | Array<T>): Array<T> {
else return [raw];
}

export function isClass(c: any): boolean { // Wrapper to allow typing on isClass
return Boolean(isClassModule(c));
export function cleanStringForXpath(str: string): string {
const parts = str.split('\'');
if (parts.length === 1) return `'${parts[0]}'`;

const formattedParts = parts.map((part: string): string => {
if (part === "") {
return '"\'"';
}
return "'" + part + "'";
});
return "concat(" + formattedParts.join(",") + ")";
}
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as process from 'process';
import * as puppeteer from 'puppeteer';
import puppeteer from 'puppeteer';
import BrowserFactory from './lib/browser_factory';
import * as Errors from './lib/errors';
import { WendigoPluginInterface, BrowserSettings, FinalBrowserSettings, WendigoPluginAssertionInterface, PluginModule } from './lib/types';
Expand Down
Loading

0 comments on commit 247c9af

Please sign in to comment.