Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request hook added multiple times when using filter rule #2650

Closed
andrzej-woof opened this issue Jul 22, 2018 · 5 comments
Closed

Request hook added multiple times when using filter rule #2650

andrzej-woof opened this issue Jul 22, 2018 · 5 comments
Assignees
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot. SYSTEM: request hooks TYPE: bug The described behavior is considered as wrong (bug).
Milestone

Comments

@andrzej-woof
Copy link

andrzej-woof commented Jul 22, 2018

Are you requesting a feature or reporting a bug?

Bug

What is the current behavior?

If I initialize hook without filter like const hook = new RequestLogger(); then onRequest and onResponse are executed only once with running tests.
But adding filter function seems like attaching new hook with each executed test.

const filterFunction = function (request) {
    return !/^https?:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.test(request.url);
};

const hook = new RequestLogger(filterFunction);
fixture('Test').requestHooks(hook);

----

import { RequestHook } from 'testcafe';

export class RequestLogger extends RequestHook {
    constructor(requestFilterRuleInit) {
        super(requestFilterRuleInit, DEFAULT_OPTIONS);
    }

    onRequest(event) {
       // This get's called as many times as number executed tests in run
    }

    onResponse(event) {
       // This get's called as many times as number executed tests in run
  }
}

What is the expected behavior?

I would expect that since it's the same const hook it won't get attached more than once.

How would you reproduce the current behavior (if this is a bug)?

See below

Provide the test code and the tested page URL (if applicable)

https://github.com/andrzej-kodify/testcafe-requesthook-bug

Specify your

  • operating system: OSX
  • testcafe version: 0.20.5
  • node.js version: v10.5.0
@AndreyBelym AndreyBelym added the STATE: Need clarification An issue lacks information for further research. label Jul 23, 2018
@miherlosev miherlosev added SYSTEM: request hooks TYPE: question The issue contains a question that won't be addressed. and removed STATE: Need clarification An issue lacks information for further research. labels Jul 23, 2018
@miherlosev
Copy link
Collaborator

miherlosev commented Jul 23, 2018

Hi @andrzej-kodify
To collect request/response info, use a built-in RequestLogger class.
If RequestLogger doesn't have the required functionality, clarify your use case and we will try to help you.

@andrzej-woof
Copy link
Author

Hi @miherlosev
I want to process requests by adding custom headers, logging them in real time, etc.
But other than that shouldn't it just work since creating custom hooks is described in official docs https://devexpress.github.io/testcafe/documentation/test-api/intercepting-http-requests/creating-a-custom-http-request-hook.html ?

@miherlosev miherlosev added TYPE: bug The described behavior is considered as wrong (bug). and removed TYPE: question The issue contains a question that won't be addressed. labels Jul 23, 2018
@miherlosev
Copy link
Collaborator

@andrzej-kodify

I've investigated the example and found the reason of the problem:
onRequest and onResponse methods were called twice for a single request with 204 http status code.
It's a bug.

@miherlosev miherlosev added this to the Planned milestone Jul 23, 2018
@miherlosev miherlosev modified the milestones: Planned, Sprint #16 Aug 14, 2018
@AndreyBelym AndreyBelym modified the milestones: Sprint #16, Sprint #17 Aug 30, 2018
@miherlosev
Copy link
Collaborator

I'm working on this

@lock
Copy link

lock bot commented Mar 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests. For TestCafe API, usage and configuration inquiries, we recommend asking them on StackOverflow.

@lock lock bot added the STATE: Auto-locked An issue has been automatically locked by the Lock bot. label Mar 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 28, 2019
kirovboris pushed a commit to kirovboris/testcafe-phoenix that referenced this issue Dec 18, 2019
…DevExpress#2650) (DevExpress#2834)

* fix 'Request hook added multiple times when using filter rule ' (close DevExpress#2650)

* revert back method name
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot. SYSTEM: request hooks TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

3 participants