DevExpress / testcafe-hammerhead

A powerful web-proxy used as a core for the TestCafe testing framework. :hammer: :smiley:
https://testcafe.io
MIT License
171 stars 161 forks source link

undefined window property crashes application when native automation mode is activated #2942

Closed Thomas-Haider closed 1 year ago

Thomas-Haider commented 1 year ago

What is your Scenario?

We have a platform application, where we load apps in iframes of the main iframes. Sadly, when we enabled native automation mode, we have this situation where the window property in the backup.ts file is undefined.

What is the Current behavior?

Following error gets thrown when the page gets loaded initially: image

What is the Expected behavior?

I wouldn't expect any issues when opening our platform when native automation mode is enabled.

What is your public website URL? (or attach your complete example)

Can't share and sadly, i did not manage to reproduce this outside of our environement

What is your TestCafe test code?

Can't share details but it is just logging in into our SSO screen and then expecting true to equals false :D

fixture('dd').page('some url i can't share');

test('test', async (testController) => testController
    .typeText(SSoScreenPo.EMAIL, username)
    .click(SSoScreenPo.NEXT_BTN)
    .typeText(SSoScreenPo.PASSWORD, pw)
    .click(SSoScreenPo.SIGN_IN_BTN)
    .expect(true)
    .ok());

Your complete configuration file

native automation mode is enabled by default

Your complete test report

application throws error in react boundary and therfore the test fails as it obviously can't find the intended selectors

Screenshots

No response

Steps to Reproduce

Unable to reproduce the issue outside our environment

TestCafe version

3.1.0

Node.js version

16.18.1

Command-line arguments

testcafe chrome test.tc-spec.ts --live

Browser name(s) and version(s)

Chrome 115.0.0.0 / Ventura 13

Platform(s) and version(s)

macOS

Other

I manage to workaround this issue by checking if the passed down window property is undefined and if it is undefined I assigne the window = this. In this case this holds the window property.

My proposal for fixing the issue would be the following: https://github.com/DevExpress/testcafe-hammerhead/blob/e7bc19fd181f73ccf615d3e79985b9187f2c7e8d/src/client/sandbox/backup.ts#L45

add the following code at the beginning of the method:

 if(!window)
      window = this;

so the function would look like this:

function get(window) {
    if(!window)
        window = this;

    var topSameDomainWindow = getTopSameDomainWindow(window);
    var storage = topSameDomainWindow[SANDBOX_BACKUP];
    var iframe = window !== topSameDomainWindow ? window.frameElement : null;
    if (storage) {
          var record = findRecord(storage, iframe);
          return record ? record.sandbox : null;
    }
    return null;
}

With this changes i do not have any issues and therefore I would be greatful if you guys could introduce them :) ,

Thomas-Haider commented 1 year ago

Further, prove to my workaround: When I add a debugger; in the if that checks if the window property is undefined, i see the following following variables assigned: image

miherlosev commented 1 year ago

Duplicate of https://github.com/DevExpress/testcafe/issues/7886

Thomas-Haider commented 1 year ago

Thanks!