Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-sendBeacon-support
Browse files Browse the repository at this point in the history
  • Loading branch information
tehhowch authored Feb 27, 2024
2 parents 579265d + ff1bbcc commit 0fd45a3
Show file tree
Hide file tree
Showing 14 changed files with 6,381 additions and 20,090 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '18.x'
cache: 'npm'
- name: Install Dependencies
run: npm install
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: 'main'
fetch-depth: 0
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 18.x
- name: NPM Setup
run: |
npm set registry "https://registry.npmjs.org/"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '18.x'
cache: 'npm'
- name: Install Dependencies
run: npm install
- name: Run Tests
run: npm test
- name: Upload WDIO logs
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: wdio-logs
path: ${{ github.workspace }}/test/logs/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
# Don't merge updates to GitHub Actions versions automatically.
# (Some repos may wish to limit by version range (major/minor/patch), or scope (dep vs dev-dep), too.)
if: contains(steps.metadata.outputs.package-ecosystem, 'npm')
uses: lewagon/wait-on-check-action@v1.3.1
uses: lewagon/wait-on-check-action@v1.3.3
with:
ref: ${{ github.event.pull_request.head.sha }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 0 additions & 3 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run prettier:check
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14.21.1
18.19.0
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## wdio-intercept-service changelog

### [ [>](https://github.com/webdriverio-community/wdio-intercept-service/tree/v.next) ] v.next / <DATE>
- Upgrade WDIO test dependencies to minimum of 8.14 for auto-driver management
- Update repo GH action dependencies
- Update WDIO to v8.32 to fix Chromedriver download URL (thanks @seanpoulter)
- Fix property check that broke compatibility with WDIO versions before v6.10
- Fix issue with unit test concurrency by removing unnecessary use of WebdriverIO `remote`

### [ [>](https://github.com/webdriverio-community/wdio-intercept-service/tree/v4.3.0) ] 4.4.0 / 24.02.2023
- Promptly throw if the user passes an invalid "index" parameter to `getRequest`
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WebdriverIO Intercept Service

This is a plugin for [webdriver.io](http://webdriver.io/). If you don't know it yet, check it out, it's pretty cool.

Although selenium and webdriver are used for e2e and especially UI testing, you might want to assess HTTP requests done by your client code (e.g. when you don't have immediate UI feedback, like in metrics or tracking calls). With wdio-intercept-service you can intercept ajax HTTP calls initiated by some user action (e.g. a button press, etc.) and make assertions about the request and corresponding resposes later.
Although selenium and webdriver are used for e2e and especially UI testing, you might want to assess HTTP requests done by your client code (e.g. when you don't have immediate UI feedback, like in metrics or tracking calls). With wdio-intercept-service you can intercept ajax HTTP calls initiated by some user action (e.g. a button press, etc.) and make assertions about the request and corresponding responses later.

There's one catch though: you can't intercept HTTP calls that are initiated on page load (like in most SPAs), as it requires some setup work that can only be done after the page is loaded (due to limitations in selenium). **That means you can just capture requests that were initiated inside a test.** If you're fine with that, this plugin might be for you, so read on.

Expand All @@ -19,7 +19,7 @@ There's one catch though: you can't intercept HTTP calls that are initiated on p

## Installation

```
```shell
npm install wdio-intercept-service -D
```

Expand Down
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ class WebdriverAjax {
this._wdajaxExpectations = [];
}

before(_, __, browser) {
before() {
// WebdriverIO before v6.10 does not pass in the browser instance
/** @type {import('webdriverio').BrowserBase} */
const browser =
typeof arguments[2] === 'undefined' ? globalThis.browser : arguments[2];

/**
* instance need to have addCommand method
*/
if (typeof browser.addCommand !== 'function') {
if (!browser || typeof browser.addCommand !== 'function') {
throw new Error(
"you can't use WebdriverAjax with this version of WebdriverIO",
);
Expand Down
10 changes: 5 additions & 5 deletions lib/interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
var interceptor = {
disableInterceptor: function disableInterceptor(done) {
var NAMESPACE = '__webdriverajax';
if (window[NAMESPACE] != undefined) {
if (typeof window[NAMESPACE] !== 'undefined') {
window[NAMESPACE].interceptorDisabled = true;
}
done(window[NAMESPACE]);
},

excludeUrls: function excludeUrls(urls, done) {
var NAMESPACE = '__webdriverajax';
if (window[NAMESPACE] != undefined) {
if (typeof window[NAMESPACE] !== 'undefined') {
// Convert the strings to regular expressions once.
var exprs = urls.map(function (obj) {
return new RegExp(obj.source, obj.flags);
Expand All @@ -32,21 +32,21 @@ var interceptor = {
};

// Some browsers don't support FormData.entries(), so we polyfill that (sigh)
if (typeof FormData.prototype.entries == 'undefined') {
if (typeof FormData.prototype.entries === 'undefined') {
polyfillFormDataEntries();
}

if (supportsSessionStorage()) {
window.sessionStorage.removeItem(NAMESPACE);
}

if (typeof window.navigator.sendBeacon == 'function') {
if (typeof window.navigator.sendBeacon === 'function') {
replaceSendBeacon();
} else {
console.error(PKG_PREFIX + 'sendBeacon API preconditions not met!');
}

if (typeof window.fetch == 'function') {
if (typeof window.fetch === 'function') {
replaceFetch();
if (
typeof window.Promise === 'undefined' ||
Expand Down
Loading

0 comments on commit 0fd45a3

Please sign in to comment.