Skip to content

Selector waits eternally for elements to appear when the date is mocked by using client scripts. #5447

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

Closed
Thormod opened this issue Aug 21, 2020 · 12 comments
Labels

Comments

@Thormod
Copy link

Thormod commented Aug 21, 2020

What is your Test Scenario?

For my Integration tests, I need to mock the browser date and to accomplish that I'm using clientScripts injecting the mockdate module:

const clientScriptsObject = [
  { module: 'mockdate' },
  { content: "MockDate.set('2020-04-19')" },
];

For this issue, I created a small project that goes to Wikipedia and tries to search for something but using an incorrect selector:

const mockDate = `
    Date.now = function () {
        return 1566408247;
    };
`;

fixture('My first fixture').page('https://www.wikipedia.org/');

test('users can search', async (t) => {
  await t
    .click(Selector('#searchInput'))
    .click(Selector('#this-selector-does-not-exist'))
    .typeText(Selector('#searchInput'), 'vikings')
    .click(Selector('button[type=submit]'));
}).clientScripts({ content: mockDate });

What is the Current behavior?

When the tests execute .click(Selector('#this-selector-does-not-exist')) the Selector get stuck waiting for the element to appear, ignoring the default (and setted) selector timeouts:

image

What is the Expected behavior?

To raise an error specifying that the selector does not exist.

image

What is your web application and your TestCafe test code?

You can access the code here:
https://github.com/Thormod/testcafe-issue

Your website URL (or attach your complete example):
Your complete test code (or attach your test files):
 
Your complete configuration file (if any):

Your complete test report:

Screenshots:

Steps to Reproduce:

Just run npm run test on the example project, or mock the Date.now() function by using clientScript

Your Environment details:

  • testcafe version: ^1.9.1
  • node.js version: v10.19.0
  • command-line arguments: testcafe chrome
  • browser name and version: Chrome latest
  • platform and version: MacOs Catalina 10.15.6
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Aug 21, 2020
@jhenaoz
Copy link

jhenaoz commented Aug 21, 2020

i have a similar issue when i mock date object in test cafe, I guess the testcafe timeouts use the same object we are mocking?

@yesid-lopez
Copy link

I'm having the same issue when I try to avoid external dependencies with mocks and I'm dealing with dates. I'm interested

@salorrego
Copy link

salorrego commented Aug 21, 2020

I'm also having the same issue with the mock dates. I'm also interested, this also happens on Linux Mint 19.3 Tricia

@AlexandroGil
Copy link

im having the exact same issue

@DavidMosquera
Copy link

I'm also having the same issue

@Serandrus
Copy link

I'm also having the same issue! And I see I'm not the only one

@miherlosev
Copy link
Collaborator

Hi @Thormod

Thank you for the detailed information. I've reproduced the problem.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Aug 24, 2020
miherlosev added a commit to miherlosev/testcafe that referenced this issue Aug 24, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@Thormod
Copy link
Author

Thormod commented Aug 31, 2020

@miherlosev Do you know when the new version will be released? PD: Thank you for solving this bug!

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Aug 31, 2020
@AndreyBelym
Copy link
Contributor

A release candidate version testcafe@1.9.2-rc.1 is already published to NPM. You can test it in your environment if you do not mind installing preliminary versions. Once we test it and create a changelog, we will publish a stable release.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Sep 1, 2020
@Thormod
Copy link
Author

Thormod commented Sep 1, 2020

@AndreyBelym @miherlosev There are some TypeErrors in the new version:
image

Uncaught TypeError: Cannot read property 'destUrl' of null
    at Function.t._sameOriginCheck (worker-hammerhead.js:1)
    at r.fetch (worker-hammerhead.js:1)
    at u (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2)
    at b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2
    at xt (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2)
    at Object.bt [as getArrayBuffer] (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2)
    at l.s [as loadVectorData] (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2)
    at l.loadTile (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2)
    at ke.loadTile (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:2)
    at __call$ (b54a5bd5-05e5-4a32-97e0-f1d459ace1fb:1)

It seems to be related with the fetch requests:
image

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 1, 2020
@AndreyBelym
Copy link
Contributor

I cannot reproduce the issue with Wikipedia.org. But I created my own example, which demonstrates a very similar issue: DevExpress/testcafe-hammerhead#2428. The version with the fix is already published to NPM as testcafe@1.9.2-rc.2. As my example and the fix is based on assumptions only, there is a risk that it doesn't fix your specific issue. Could you please try to install testcafe@1.9.2-rc.2 and provide a sample test page if you still can reproduce the issue in your environment?

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Sep 2, 2020
@Thormod
Copy link
Author

Thormod commented Sep 2, 2020

@AndreyBelym It worked! Thank u for solving this so fast!

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 2, 2020
@AlexSkorkin AlexSkorkin removed the STATE: Need response An issue that requires a response or attention from the team. label Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants