Skip to content

Commit

Permalink
inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dweber019 committed Mar 2, 2018
0 parents commit 80e0cb9
Show file tree
Hide file tree
Showing 7 changed files with 1,767 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HOST=https://google.ch
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
node_modules
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

# Installation

You need to set up your development environment before you can do anything.

Install [Node.js and NPM](https://nodejs.org/en/download/)

- on OSX use [homebrew](http://brew.sh) `brew install node`
- on Windows use [chocolatey](https://chocolatey.org/) `choco install nodejs`

Install yarn globally

```bash
npm install yarn -g
```

Then install the dependencies with
```bash
yarn install
```

Then copy the `.env.example` to `.env` and replace the setting in the file with your settings
```bash
cp .env.example .env
```

# Usage

This repository uses the [testcafe](https://devexpress.github.io/testcafe/) library to perform e2e tests.

## Running the tests

You can run all tests by
```bash
npm test
```

or just run a single file by
```bash
npm run test:single <path-to-file>

npm run test:single tests/test-case.spec.ts
```

## Write tests

All test are located in `tests/`. See example `estate.ts`.
There is also a helper utility `helper.ts` which can be imported and provides some help.
The `helper.ts` can also be extended.

## Documentation

[Here you can find help about seleting elements (e.g. get text)](https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/selectors.html)

[Here you can find help about actions elements (e.g. clicks)](https://devexpress.github.io/testcafe/documentation/test-api/actions/)

[Here you can find help about Aurelia specific stuff](https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/framework-specific-selectors.html#aurelia)

## CI

To run the all test headless use `npm run ci`.

Additional information about CI integrations can be found [here](https://devexpress.github.io/testcafe/documentation/recipes/integrating-testcafe-with-ci-systems/).
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "test-cafe-e2e",
"version": "1.0.0",
"description": "E2E testing for almost any frontend app",
"scripts": {
"test": "testcafe chrome tests/**/*.spec.ts",
"test:single": "testcafe chrome",
"ci": "testcafe chrome:headless tests/**/*.spec.ts"
},
"bugs": {
"url": "https://github.com/w3tecch/test-cafe-e2e/issues"
},
"homepage": "https://github.com/w3tecch/test-cafe-e2e#readme",
"license": "MIT",
"keywords": [
"e2e",
"testcafe",
"w3tec",
"boilerplate"
],
"contributors": [
{
"name": "Gery Hirschfeld <[email protected]> (https://github.com/hirsch88)"
},
{
"name": "David Weber <[email protected]> (https://github.com/dweber019)"
}
],
"devDependencies": {
"@types/dotenv": "^4.0.2",
"dotenv": "^4.0.0",
"testcafe": "^0.18.5",
"testcafe-aurelia-selectors": "^0.1.3"
}
}
39 changes: 39 additions & 0 deletions tests/google.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { config } from 'dotenv';
import { ClientFunction, Selector } from 'testcafe';

import { getBrowserTitle, handleAuthentication } from './helper';

config();

fixture`Google`
.page(process.env.HOST);
// .beforeEach(async t => {
// await handleAuthentication(t);
// });

test('Should display google start page', async t => {

const title = await getBrowserTitle();
await t
.expect(title).eql('Google');
});



test('Should show results for e2e testing', async t => {

const searchTerm = 'e2e testing';
const searchInput = Selector('#lst-ib');

await t
.typeText(searchInput, searchTerm);

const searchButton = Selector('input[name=btnK]');

await t
.click(searchButton);

const title = await getBrowserTitle();
await t
.expect(title).contains(searchTerm);
});
22 changes: 22 additions & 0 deletions tests/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ClientFunction, Role } from 'testcafe';

/**
* Helper functions
*/
export const getBrowserTitle = ClientFunction(() => document.title);

/**
* Authentication handling example
*/
const regularUser = Role(`${process.env.HOST}/#/login`, async t => {
await t
.click('.login__button button')
.typeText('.ui-inputfield', process.env.EMAIL)
.click('.submitButton')
.typeText('.ui-inputfield', process.env.PASSWORD)
.click('.submitButton');
}, { preserveUrl: true });

export const handleAuthentication = async (t: TestController) => {
await t.useRole(regularUser);
}
Loading

0 comments on commit 80e0cb9

Please sign in to comment.