Skip to content

Commit

Permalink
Webdriverio v5 (codeceptjs#1386)
Browse files Browse the repository at this point in the history
* webdriver v initial implementation

* fixed unit tests

* fixed multi-session report

* updated tests

* updated config for appium

* updated tests, docs

* fixed changes

* fixed REST test

* udpated

* codestyle updates
  • Loading branch information
DavertMik authored Dec 25, 2018
1 parent c0c7827 commit 349cc5c
Show file tree
Hide file tree
Showing 43 changed files with 4,579 additions and 172 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
- HELPER=Nightmare
- HELPER=Puppeteer
- HELPER=ProtractorWeb
- HELPER=WebDriverIO
- HELPER=WebDriver
addons:
apt:
packages:
Expand Down
10 changes: 5 additions & 5 deletions docs/acceptance.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ How does your client, manager, or tester, or any other non-technical person, kno

Acceptance (also called End to End) tests can cover standard but complex scenarios from a user's perspective. With acceptance tests you can be confident that users, following all defined scenarios, won't get errors. We check **not just functionality of application but a user interface** (UI) as well.

By default CodeceptJS uses [WebDriverIO](/helpers/WebDriverIO/) helper and **Selenium** to automate browser. Within web page you can locate elements, interact with them, and check that expected elements are present on a page.
By default CodeceptJS uses [WebDriver](/helpers/WebDriver/) helper and **Selenium** to automate browser. Within web page you can locate elements, interact with them, and check that expected elements are present on a page.
However, you can also choose [Nightmare](/helpers/Nightmare) or [Protractor](/helpers/Protractor) helpers, driven by corresponding libraries.
No matter of helper and library you use for acceptance testing, CodeceptJS should execute same actions in similar manner.

Expand All @@ -26,7 +26,7 @@ This is how we can check that login form of a simple web application works. At f
## Locating Element

Element can be found by CSS or XPath locators. Practically every steps
in WebDriverIO helper accept them both.
in WebDriver helper accept them both.

```js
I.seeElement('.user'); // element with CSS class user
Expand Down Expand Up @@ -215,7 +215,7 @@ More wait actions can be found in helper's reference.

It is possible to wait for elements pragmatically. If a test uses element which is not on a page yet, CodeceptJS will wait for few extra seconds before failing. This feature is based on [Implicit Wait](http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#implicit-waits) of Selenium. CodeceptJS enables implicit wait only when searching for a specific element and disables in all other cases. Thus, the performance of a test is not affected.

SmartWait can be enabled by setting wait option in WebDriverIO config.
SmartWait can be enabled by setting wait option in WebDriver config.
Add `"smartWait": 5000` to wait for additional 5s.

SmartWait works with a CSS/XPath locators in `click`, `seeElement` and other methods. See where it is enabled and where is not:
Expand Down Expand Up @@ -257,7 +257,7 @@ within({frame: "#editor"}, () => {
});
```

Nested IFrames can be set by passing array *(WebDriverIO, Nightmare & Puppeteer only)*:
Nested IFrames can be set by passing array *(WebDriver, Nightmare & Puppeteer only)*:

```js
within({frame: [".content", "#editor"]}, () => {
Expand Down Expand Up @@ -341,4 +341,4 @@ Also, you can use `within` inside a session but you can't call session from insi
### done()
CodeceptJS through helpers provides user friendly API to interact with a webpage. In this section we described using WebDriverIO helper which allows to control browser through Selenium WebDriver.
CodeceptJS through helpers provides user friendly API to interact with a webpage. In this section we described using WebDriver helper which allows to control browser through Selenium WebDriver.
2 changes: 1 addition & 1 deletion docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Create `multiple` section in configuration file, and fill it with run suites. Ea
"smoke": {
"browsers": [
"firefox",
// replace any config values from WebDriverIO helper
// replace any config values from WebDriver helper
{
"browser": "chrome",
"windowSize": "maximize",
Expand Down
10 changes: 5 additions & 5 deletions docs/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ I object is an **actor**, an abstraction for a testing user. I is a proxy object

## Architecture

CodeceptJS bypasses execution commands to helpers. Depending on helper enabled your tests will be executed differently. If you need cross-browser support you should choose Selenium-based WebDriverIO or Protractor, if you are interested in speed - use Chrome-based Puppeteer, or Electron-based Nightmare. Those engines can run tests in window mode or headlessly and doesn't require additional tools to be installed.
CodeceptJS bypasses execution commands to helpers. Depending on helper enabled your tests will be executed differently. If you need cross-browser support you should choose Selenium-based WebDriver or Protractor, if you are interested in speed - use Chrome-based Puppeteer, or Electron-based Nightmare. Those engines can run tests in window mode or headlessly and doesn't require additional tools to be installed.

Here is the diagram of CodeceptJS architecture

![](https://codecept.io/images/architecture.svg)

All helpers share the same API so it's easy to migrate tests from one backend to other.
However, because of difference in backends and their limitations, they are not guarantted to compatible between each other. For instance, you can't set request headers in WebDriverIO or Protractor, but you can do so in Puppteer or Nigthmare.
However, because of difference in backends and their limitations, they are not guarantted to compatible between each other. For instance, you can't set request headers in WebDriver or Protractor, but you can do so in Puppteer or Nigthmare.

Please note, you can't run tests by different helpers at once. You can't use some APIs from WebDriverIO and some from Nightmare. You should **pick one helper, as it definses how tests are executed.** If requirements change it's easy to migrate to another, but don't use few helpers at once. It's just not possible.
Please note, you can't run tests by different helpers at once. You can't use some APIs from WebDriver and some from Nightmare. You should **pick one helper, as it definses how tests are executed.** If requirements change it's easy to migrate to another, but don't use few helpers at once. It's just not possible.

A helper should be enabled in main config. Configuration (like base url) should be provided as well:

```json
"helpers": {
"WebDriverIO": {
"WebDriver": {
"url": "http://localhost",
"browser": "chrome"
}
}
```

In this config config all methods of `I` will be taken from `WebDriverIO` helper.
In this config config all methods of `I` will be taken from `WebDriver` helper.

## Writing Tests

Expand Down
2 changes: 1 addition & 1 deletion docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ codeceptjs run --config path/to/codecept.json
Override config on the fly. Provide valid JSON which will be merged into current config:

```sh
codeceptjs run --override '{ "helpers": {"WebDriverIO": {"browser": "chrome"}}}'
codeceptjs run --override '{ "helpers": {"WebDriver": {"browser": "chrome"}}}'
```

Run tests and produce xunit report:
Expand Down
6 changes: 3 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ exports.config = {
By default `codecept.json` is used for configuration. You can override its values in runtime by using `--override` or `-o` option in command line, passing valid JSON as a value:

```sh
codeceptjs run -o '{ "helpers": {"WebDriverIO": {"browser": "firefox"}}}'
codeceptjs run -o '{ "helpers": {"WebDriver": {"browser": "firefox"}}}'
```

You can also switch to JS configuration format for more dynamic options.
Expand All @@ -59,7 +59,7 @@ codeceptjs run -o '{ "helpers": {"WebDriverIO": {"browser": "firefox"}}}'
```js
exports.config = {
helpers: {
WebDriverIO: {
WebDriver: {
// load variables from the environment and provide defaults
url: process.env.CODECEPT_URL || 'http://localhost:3000',

Expand Down Expand Up @@ -107,7 +107,7 @@ codeceptjs run --profile firefox
```js
exports.config = {
helpers: {
WebDriverIO: {
WebDriver: {
url: 'http://localhost:3000',
// load value from `profile`
browser: process.profile || 'firefox'
Expand Down
4 changes: 2 additions & 2 deletions docs/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ API supposed to be a stable interface and it can be used by acceptance tests. Co
## REST

[REST helper](http://codecept.io/helpers/REST/) uses [Unirest](http://unirest.io/nodejs.html) library to send HTTP requests to application.
However, it doesn't provide tools for testing APIs, so it should be paired with WebDriverIO, Nightmare or Protractor helpers for browser testing.
However, it doesn't provide tools for testing APIs, so it should be paired with WebDriver, Nightmare or Protractor helpers for browser testing.

Enable REST helper in global config. It is recommended to set `endpoint`, a base URL for all API requests.
If you need some authorization you can optionally set default headers too.
Expand All @@ -34,7 +34,7 @@ See the sample config:
}
},

"WebDriverIO" : {
"WebDriver" : {
"browser": "chrome"
}
}
Expand Down
8 changes: 4 additions & 4 deletions docs/docker.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Codeceptjs Docker

CodeceptJS packed into container with the Nightmare, Protractor, Puppeteer, and WebDriverIO drivers.
CodeceptJS packed into container with the Nightmare, Protractor, Puppeteer, and WebDriver drivers.

## How to Use

Expand Down Expand Up @@ -56,12 +56,12 @@ services:
### Linking Containers
If using the Protractor or WebDriverIO drivers, link the container with a Selenium Standalone docker container with an alias of `selenium`. Additionally, make sure your `codeceptjs.conf.js` contains the following to allow CodeceptJS to identify where Selenium is running.
If using the Protractor or WebDriver drivers, link the container with a Selenium Standalone docker container with an alias of `selenium`. Additionally, make sure your `codeceptjs.conf.js` contains the following to allow CodeceptJS to identify where Selenium is running.

```javascript
...
helpers: {
WebDriverIO: {
WebDriver: {
...
host: process.env.HOST
...
Expand Down Expand Up @@ -116,7 +116,7 @@ services:
- .:/tests
```

Moreover, alternatively arguments to `codecept run-multiple` command can be passed via `RUN_MULTIPLE` and `CODECEPT_ARGS` environment variable.
Moreover, alternatively arguments to `codecept run-multiple` command can be passed via `RUN_MULTIPLE` and `CODECEPT_ARGS` environment variable.
For example this is what looks like in your codeceptjs.conf.js

```yaml
Expand Down
20 changes: 10 additions & 10 deletions docs/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This command generates a basic helper and appends it to `helpers` section of con

```json
"helpers": {
"WebDriverIO": { },
"WebDriver": { },
"MyHelper": {
"require": "./path/to/module.js"
}
Expand Down Expand Up @@ -68,10 +68,10 @@ codeceptjs def .

This way, if your tests are written with TypeScript, your IDE will be able to leverage features like autocomplete and so on.

## WebDriverIO Example
## WebDriver Example

Next example demonstrates how to use WebDriverIO library to create your own test action.
Method `seeAuthentication` will use `client` instance of WebDriverIO to get access to cookies.
Next example demonstrates how to use WebDriver library to create your own test action.
Method `seeAuthentication` will use `client` instance of WebDriver to get access to cookies.
Standard NodeJS assertion library will be used (you can use any).

```js
Expand All @@ -86,8 +86,8 @@ class MyHelper extends Helper {
* checks that authentication cookie is set
*/
async seeAuthentication() {
// access current client of WebDriverIO helper
let client = this.helpers['WebDriverIO'].browser;
// access current client of WebDriver helper
let client = this.helpers['WebDriver'].browser;

// get all cookies according to http://webdriver.io/api/protocol/cookie.html
// any helper method should return a value in order to be added to promise chain
Expand Down Expand Up @@ -152,7 +152,7 @@ You can also pass additional config options to your helper from a config - **(pl
```js
"helpers": {
// here goes standard helpers:
// WebDriverIO, Protractor, Nightmare, etc...
// WebDriver, Protractor, Nightmare, etc...
// and their configuration
"MyHelper": {
"require": "./my_helper.js", // path to module
Expand Down Expand Up @@ -196,14 +196,14 @@ Each implemented method should return a value as they will be added to global pr

### Hook Usage Examples

1) Failing if JS error occur in WebDriverIO:
1) Failing if JS error occur in WebDriver:

```js
class JSFailure extends codecept_helper {

_before() {
this.err = null;
this.helpers['WebDriverIO'].browser.on('error', (e) => this.err = e);
this.helpers['WebDriver'].browser.on('error', (e) => this.err = e);
}

_afterStep() {
Expand All @@ -222,7 +222,7 @@ class JSWait extends codecept_helper {
_afterStep(step) {
if (step.name == 'click') {
var jqueryActive = () => jQuery.active == 0;
return this.helpers['WebDriverIO'].waitUntil(jqueryActive);
return this.helpers['WebDriver'].waitUntil(jqueryActive);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/helpers/ApiDataFactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ See the example:
}
```
It is required to set REST API `endpoint` which is the baseUrl for all API requests.
It is required to set REST API `endpoint` which is the baseURL for all API requests.
Factory file is expected to be passed via `factory` option.
This Helper uses [REST][3] helper and accepts its configuration in "REST" section.
Expand Down
6 changes: 3 additions & 3 deletions docs/helpers/Appium.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Appium

**Extends WebdriverIO**
**Extends Webdriver**

Appium helper extends [WebriverIO][1] helper.
It supports all browser methods and also includes special methods for mobile apps testing.
Expand Down Expand Up @@ -381,12 +381,12 @@ Appium: support Android and iOS
Remove an app from the device.

```js
I.removeApp('com.example.android.apis');
I.removeApp('appName', 'com.example.android.apis');
```

#### Parameters

- `bundleId` String ID of bundled appAppium: support only Android
- `bundleId` String ID of bundleAppium: support only Android

### rotate

Expand Down
3 changes: 2 additions & 1 deletion docs/helpers/Puppeteer.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ This helper should be configured in codecept.json or codecept.conf.js

```js
"chrome": {
"executablePath" : "/path/to/Chrome"
"executablePath" : "/path/to/Chrome",
"browserWSEndpoint": "ws://localhost:3000"
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/helpers/REST.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ REST helper allows to send additional requests to the REST API during acceptance

## Configuration

- baseURL: API base URL
- endpoint: API base URL
- timeout: timeout for requests in milliseconds. 10000ms by default
- defaultHeaders: a list of default headers

Expand Down
Loading

0 comments on commit 349cc5c

Please sign in to comment.