Skip to content

Commit

Permalink
Added support for Webdriver Standalone (#139)
Browse files Browse the repository at this point in the history
* Added support for Webdriver Standalone

The before function is currently already being called with the arguments of config, capabilities, browser.
Since the browser object will be the same, this change allows the service to be compatible with the CLI Testrunner
and WebDriver standalone. Documentation in the README and a new test has been added also.

* Cleaning up code as per PR feedback

* Updating chromedriver to fix failing build

Co-authored-by: Jeffrey Quach <jquach@atlassian.com>
  • Loading branch information
juenobueno and Jeffrey Quach committed Aug 2, 2021
1 parent 8cde9cc commit 4cb8d0d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ npm install wdio-intercept-service -D

## Usage

### Usage with WebDriver CLI

It should be as easy as adding wdio-intercept-service to your `wdio.conf.js`:

```javascript
Expand All @@ -37,6 +39,43 @@ exports.config = {

and you're all set.

### Usage with WebDriver Standalone

When using WebdriverIO Standalone, the `before` and `beforeTest` / `beforeScenario` functions need to be called manually.

```javascript
import { remote } from 'webdriverio';
import WebdriverAjax from 'wdio-intercept-service'

const WDIO_OPTIONS = {
port: 9515,
path: '/',
capabilities: {
browserName: 'chrome'
},
}

let browser;
const interceptServiceLauncher = WebdriverAjax();

beforeAll(async () => {
browser = await remote(WDIO_OPTIONS)
interceptServiceLauncher.before(null, null, browser)
})

beforeEach(async () => {
interceptServiceLauncher.beforeTest()
})

afterAll(async () => {
await client.deleteSession()
});

describe('', async () => {
... // See example usage
});
```

Once initialized, some related functions are added to your browser command chain (see [API](#api)).

## Quickstart
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WebdriverAjax {
this._wdajaxExpectations = [];
}

before() {
before(_, __, browser) {
/**
* instance need to have addCommand method
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@wdio/spec-reporter": "^7.6.0",
"@wdio/static-server-service": "^7.6.0",
"@wdio/sync": "^7.6.0",
"chromedriver": "^90.0.0",
"chromedriver": "^92.0.0",
"husky": "4.2.5",
"prettier": "2.3.0",
"release-it": "^14.6.2",
Expand Down
20 changes: 20 additions & 0 deletions test/spec/plugin_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

const assert = require('assert');
const { remote } = require('webdriverio');
const WebdriverAjax = require('../../index').default;

describe('webdriverajax', function testSuite() {
this.timeout(process.env.CI ? 100000 : 10000);
Expand All @@ -17,6 +19,24 @@ describe('webdriverajax', function testSuite() {
assert.deepEqual(ret, { requests: [] });
});

it('sets up the interceptor in standalone mode', async () => {
const browser = await remote({
port: 9515,
path: '/',
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
args: ['--headless'],
},
},
});

const webdriverAjax = new WebdriverAjax();
webdriverAjax.before(null, null, browser);

assert.equal(typeof browser.setupInterceptor, 'function');
});

it('should reset expectations', () => {
assert.equal(typeof browser.setupInterceptor, 'function');
browser.url('/get.html');
Expand Down

0 comments on commit 4cb8d0d

Please sign in to comment.