Search code examples
testingiframeautomatione2e-testingtestcafe

Is it possible to prevent testcafe/hammerhead scripts injection in specific iframe?


everyone. What I want to do - to create an empty/pristine iframe on testcafe page.

Problem: Testcafe/hammerhead injects custom script, that overrides prototypes and creates many global variables. I need to prevent it somehow. So I need to create iframe on testcafe page, but without all this custom injected stuff.enter image description here

Is there any API method or "hack" for this?

I use the latest testcafe version.


Solution

  • TestCafe cannot operate with an iframe without embedding service scripts. I agree that making a global variable is not the best practice in JavaScript. However, TestCafe's global variable is marked as non-enumerable (see here). It means that the client's script cannot find this global variable because it cannot access it without knowing this variable's name. In my opinion, the prototype overriding is not a big problem because a lot of JavaScript frameworks (Angular, JQuery, etc.) do the same.