DevExpress / testcafe

A Node.js tool to automate end-to-end web testing.
https://testcafe.io
MIT License
9.82k stars 673 forks source link

JS modified in wrong manner #7415

Closed tandreys closed 1 year ago

tandreys commented 1 year ago

What is your Scenario?

Some functions are failing only under Testcafe. Take that code var a=0; var b = function(){ a++; return a; } var t={1: 0, 2:0}; for (var i=0;i<2;i++){ t[b()] +=1; } console.log(a); console.log(t);

What is the Current behavior?

a=0; var b = function(){ a++; return a; } var t={1: 0, 2:0}; for (var i=0;i<2;i++){ set$(t,b(),get$(t,b())+1) ; } console.log(a); console.log(t);

giving 4

Object {1:1, 2: 0, 3:NaN}

What is the Expected behavior?

2 Object { 1: 1, 2: 1 }

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

<!DOCTYPE html>

What is your TestCafe test code?

fixture Sandbox

test('repro', async t => { await t.navigateTo("file:///C:/temp/repro.html");

await t.debug();

})

Your complete configuration file

No response

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

1. 2. 3.

TestCafe version

2.1.0

Node.js version

tried with latest 14,16 and 18

Command-line arguments

testcafe "chrome" repro.js -d

Browser name(s) and version(s)

chrome, firefox, edge

Platform(s) and version(s)

Windows 11, Ubuntu 20

Other

you can see t[b()] += 1; is transformed to set$(t,b(),get$(t,b())+1), and the value of a is not expected in testcafe, because the function b is not idempotent (it changes a every time).

AlexKamaev commented 1 year ago

Thank you for reporting this. I was able to reproduce the issue.

Please also read about the new TestCafe option that is available in the https://www.npmjs.com/package/testcafe/v/2.1.1-alpha.2 version and newer.

TestCafe runs tests using the URL-rewritten proxy. This approach is good. However, there is a way to improve the stability and speed of test execution - the native browser automation API. We have a test execution mode uses native browser automation - we call it the Proxyless mode. In Proxyless mode, a few issues are already fixed. By the way, this issue was also fixed in Proxyless mode. Try running your tests in Proxyless mode and let us know the results. This option is available in all interfaces:

// Command-line
testcafe chrome tests --experimental-proxyless
// Programmatic
const testcafe = await createTestCafe({ experimentalProxyless: true });

// Configuration file
{
"experimentalProxyless": "true"
} 

Note that at present it is an experimental mode. Also, the Proxyless mode is implemented only in Google Chrome. It will not work correctly if you run tests in a non-Chrome browser or in a combination of other browsers.

tandreys commented 1 year ago

Hi, I'm not able to launch test in proxyless mode ERROR Unable to open the "chrome:" browser due to the following error:

TypeError: Cannot read properties of undefined (reading 'Fetch') at Proxyless.init (C:\testcafe\node_modules\testcafe\src\proxyless\index.ts:28:28) at BrowserProviderPluginHost._setupProxyless (C:\testcafe\node_modules\testcafe\src\browser\provider\built-in\dedicated\chrome\index.js:53:25) at processTicksAndRejections (node:internal/process/task_queues:95:5) at BrowserProviderPluginHost.openBrowser (C:\testcafe\node_modules\testcafe\src\browser\provider\built-in\dedicated\chrome\index.js:96:13) at BrowserProvider.openBrowser (C:\testcafe\node_modules\testcafe\src\browser\provider\index.ts:323:9) at BrowserConnection._runBrowser (C:\testcafe\node_modules\testcafe\src\browser\connection\index.ts:258:13)

I'm on Windows 11, Chrome 108

tandreys commented 1 year ago

it's a node issue, I was using NodeJS 18. Reverting to node 14, I'm able to launch it and manually checking that the issue does not occur.

But my test is failing on login page. await t .typeText('#j_username', name) .typeText('#j_password', password) .click('#logOnFormSubmit');

The click on submit is working, page is loading but Testcafe is still searching for the button and is failing. The same code without proxyless mode is working fine.

In an other test, it's failing on .beforeEach Error in fixture.beforeEach hook - TypeError: Cannot read property 'proxy' of null

miherlosev commented 1 year ago

Hi @tandreys

it's a node issue, I was using NodeJS 18.

Yes, we have a known issue related to the Node.js@18.x version.

But my test is failing on login page. await t .typeText('#j_username', name) .typeText('#j_password', password) .click('#logOnFormSubmit');

Could you please share a simple example that we can run locally?

github-actions[bot] commented 1 year ago

This issue was automatically closed because there was no response to our request for more information from the original author. Currently, we don't have enough information to take action. Please reach out to us if you find the necessary information and are able to share it. We are also eager to know if you resolved the issue on your own and can share your findings with everyone.