Skip to content

Commit

Permalink
Merge pull request #48 from angrykoala/dev
Browse files Browse the repository at this point in the history
0.3.1
  • Loading branch information
angrykoala authored Feb 9, 2018
2 parents be5dd9e + 402b43f commit 02abc7c
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 4 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
0.3.1 / 2018-02-09
==================

* Method browser.clickText
* Find by text fixed to return valid html elements


0.3.0 / 2018-02-07
==================

* Support for DOM Node as selector in all methods
* Assert textContains
* Click now supports index and clicks all elements
* Headless" option to set browser's headless mode
* Headless option to set browser's headless mode
* All query methods now return a puppeteer's DOM Node
* browser.type types on all elements and apending the value
* Removed jsdom dependency
Expand Down
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ await browser.assert.text("#my-modal", "Button Clicked");
* [Assert](#assert)
* [Examples](#examples)
* [Troubleshooting](#troubleshooting)
* [Acknowledgements](#acknowledgements)

# Api

Expand Down Expand Up @@ -155,6 +156,13 @@ Clicks all the elements with the matching css selector, if the index parameter i
await browser.click("button.btn");
```

**clickText(text)**
Clicks all the elements matching given text.

```js
await browser.clickText("Click Me!");
```

**title()**
Returns the page title

Expand Down Expand Up @@ -352,6 +360,51 @@ describe("My Tests", function() {
});
```

## Troubleshooting

### Running Tests With Travis CI
Running tests using puppeteer's require disabling the sandbox running mode. This can easily be achieved by passing the environment variable `NO_SANDBOX=true`, this can be done either as part of the test execution command, as a Travis secret env variable or in the `.travis.yml` file itself:

```ỳml
language: node_js
os:
- linux
node_js:
- "stable"
sudo: false
env:
- NO_SANDBOX=true
script:
- npm test
cache:
directories:
- node_modules
```
_Example of travis.yml file_

### Running Tests With Gitlab CI

Using gitlab with the default node image requires installing a few dependencies with `apt-get` before installing wendigo. Same as in travis, sandbox mode should be disabled with the env variable `NO_SANDBOX`:

```yml
image: node:8.9.4

variables:
NO_SANDBOX: "true"

before_script:
- apt-get update
- apt-get install -y -q gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
- npm install

test:
stage: test
script:
- npm test
```
## Acknowledgements
* [Puppeteer](https://github.com/GoogleChrome/puppeteer) and Chrome Headless as base headless browser.
Expand Down
10 changes: 8 additions & 2 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ module.exports = class Browser extends BrowserBase {
});
}

clickText(text) {
return this.findByText(text).then((elements) => {
return this.click(elements);
});
}

title() {
return this.page.title();
}
Expand Down Expand Up @@ -79,12 +85,12 @@ module.exports = class Browser extends BrowserBase {
}

findByText(text) {
const xPath = `//text()[. = '${text}']`;
const xPath = `//*[text()='${text}']`;
return this.queryXPath(xPath);
}

findByTextContaining(text) {
const xPath = `//text()[contains(.,'${text}')]`;
const xPath = `//*[contains(text(),'${text}')]`;
return this.queryXPath(xPath);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wendigo",
"version": "0.3.0",
"version": "0.3.1",
"description": "A proper monster for front-end testing",
"engines": {
"node": ">=8.9.4"
Expand Down
22 changes: 22 additions & 0 deletions tests/browser_interactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,26 @@ describe("Browser Interactions", function() {
await browser.assert.exists("#switch.on");
await browser.assert.text("#switch", "On");
});

it("Click Text", async() => {
await browser.open(configUrls.click);
await browser.clickText("click me");
await browser.assert.text("#switch", "Off");
await browser.clickText("click me");
await browser.assert.text("#switch", "On");
});

it("Click Invalid Text", async() => {
await browser.open(configUrls.click);
await browser.clickText("not click me");
await browser.assert.text("#switch", "On");
});

it("Find By Text Containing And Click", async() => {
await browser.open(configUrls.click);
const elements = await browser.findByTextContaining("click");
await browser.click(elements);
await browser.assert.text("#switch", "Off");
await browser.waitFor("#switch.on", 600);
});
});

0 comments on commit 02abc7c

Please sign in to comment.