Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

TypeError: Object has no member ‘replace’ #42

Closed
marcelo-dalmeida opened this issue Oct 2, 2019 · 9 comments · Fixed by #45
Closed

TypeError: Object has no member ‘replace’ #42

marcelo-dalmeida opened this issue Oct 2, 2019 · 9 comments · Fixed by #45

Comments

@marcelo-dalmeida
Copy link

marcelo-dalmeida commented Oct 2, 2019

As mentioned in:
https://community.k6.io/t/typeerror-object-has-no-member-replace/253

"Hi

I’ve just converted a postman collection through postman-to-k6 tool.

I’m having the current problem when executing the script and it seems to be connected to http.file part

I’m out of clues about what is happening here

code:

export default function() {
		
  postman[Request]({
    name: "/recommendation (file upload)",
    id: "72996999-1924-45d4-8b65-1e1867785397",
    method: "POST",
    address: "{{recommendation-url}}/recommendation?start=1&limit=10",
    data: { user_id: "5", file: http.file(document_file) },
    headers: {
      "Content-Type": "application/json"
    },
    post(response) {
      var jsonData = JSON.parse(responseBody);
      postman.setEnvironmentVariable(
        "recommendation_request.id",
        jsonData.recommendation_request.id
      );
    }
  });

Error raised while running the script:

ERRO[0005] TypeError: Object has no member 'replace'
        at makeRequestConfig (file:///C:/Users/marcelodalmeida/Desktop/entulho/B-Finder/libs/shim/core.js:996:205(117))
        at executeRequest (file:///C:/Users/marcelodalmeida/Desktop/entulho/B-Finder/libs/shim/core.js:960:35(78))
        at executeRequest (file:///C:/Users/marcelodalmeida/Desktop/entulho/B-Finder/libs/shim/core.js:956:234(53))
        at file:///C:/Users/marcelodalmeida/Desktop/entulho/B-Finder/libs/shim/core.js:307:46(35)
        at file:///C:/Users/marcelodalmeida/Desktop/entulho/B-Finder/recommendation-k6-script.js:37:19(31)
    done [==========================================================] 1 / 1

Thank you in advance"

P.S. It is uploading a word document (binary)

@Lex-talionis
Copy link

i'm having the same problem, its this makeRequestConfig() in core.js. i could hack it about to work but there has surely got to be a fix to this?

@bookmoons
Copy link
Contributor

Hi guys. Thanks for the report. I'll be looking into this soon.

@bookmoons
Copy link
Contributor

Does someone have an example collection they can post? My tests are not reproducing.

@bookmoons
Copy link
Contributor

Hi guys. Would really like to fix this bug but so far I haven't found an input that causes it. If someone could send a Postman collection that causes it, that would help a lot. I'd be able to find what's happening and publish a fix. @marcelo-dalmeida @Lex-talionis

@marcelo-dalmeida
Copy link
Author

Hi @bookmoons

Sorry for the delay.

It is basically a ms/word file upload (binary file upload handling)

Here is the collection I was using it:
recommendation.postman_collection.zip

@bookmoons
Copy link
Contributor

Thanks a lot @marcelo-dalmeida. Will investigate.

@bookmoons
Copy link
Contributor

This is the conversion I see. The file part of the body is an empty string. Still not quite right but tt's different than the report where it's an http.file() call.

Is this also what you see? Is it possible you were adding that http.file() call manually ?

    data: { user_id: "5", file: "" },
  postman[Request]({
    name: "/recommendation (file upload)",
    id: "05cc76cd-214f-46b7-a251-5219b509eab1",
    method: "POST",
    address: "{{recommendation-url}}/recommendation?start=1&limit=10",
    data: { user_id: "5", file: "" },
    headers: {
      "Content-Type": "application/json"
    },
    post(response) {
      var recommendation_url = postman.getEnvironmentVariable(
        "recommendation-url"
      );

      if (
        recommendation_url.startsWith("{{") &&
        recommendation_url.endsWith("}}")
      ) {
        var url_variable = recommendation_url;

        url_variable = url_variable.replace("{{", "");
        url_variable = url_variable.replace("}}", "");

        new_recommendation_url = postman.getEnvironmentVariable(url_variable);

        postman.setEnvironmentVariable(
          "recommendation-url",
          new_recommendation_url
        );
      }

      var jsonData = JSON.parse(responseBody);
      postman.setEnvironmentVariable(
        "recommendation_request.id",
        jsonData.recommendation_request.id
      );
    }
  });

@marcelo-dalmeida
Copy link
Author

I'm not with a computer right now to further check if I got the same and exactly what I did after, but you are right.

I remember now that it didn't work by purely converting it, so I tried to fill the blanks manually. And then I found this error.

So it is probably two separate bugs.

@bookmoons
Copy link
Contributor

OK thanks a lot for your help. Going to build a fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants