Skip to content
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

improperly behaviour of window.getSelection().getRangeAt(0) #5420

Closed
deringwer opened this issue Aug 13, 2020 · 3 comments
Closed

improperly behaviour of window.getSelection().getRangeAt(0) #5420

deringwer opened this issue Aug 13, 2020 · 3 comments
Labels
HAS WORKAROUND STATE: Stale An outdated issue that will be automatically closed by the Stale bot. TYPE: bug The described behavior is considered as wrong (bug).

Comments

@deringwer
Copy link

deringwer commented Aug 13, 2020

What is your Test Scenario?

Getting a selection of characters after focusing out by Tab key

What is the Current behavior?

Does'not return a selection after focusing out

What is the Expected behavior?

Should return a selected value after focusing out

What is your web application and your TestCafe test code?

Web app code:

<div contenteditable="true">Sample Text</div>
<button>Button to focus</button>

TestCafe code:
window.getSelection().getRangeAt(0)

Steps to Reproduce:

  1. Run web app code
  2. Select a few characters by CTRL
  3. Press Tab key to unfocus
  4. Run TestCafe code to get a currently selected characters

Your Environment details:

  • testcafe version: 1.8.2

  • node.js version: 10.18.1

  • browser name and version: Chrome 84, Edge 84, Safari 13.1

  • platform and version: macOS, Windows

@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 13, 2020
@Farfurix Farfurix self-assigned this Aug 14, 2020
@Farfurix
Copy link
Contributor

@kukuhaha

Hello,

testcafe version: 1.8.2

Please, update your version to the latest v1.9.1.

I suppose you tried to return the Range object from ClientFunction. As a workaround, you can use the following example based on this comment:
index.html

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<div id="div" contenteditable="true">Sample Text</div>
<button id="btn">Button to focus</button>
</body>
</html>

test.js

import { ClientFunction } from 'testcafe';

fixture `Fixture`
    .page `./index.html`;

const getSelectionRange = async t => JSON.parse(await t.eval(() => {
    const { startOffset, endOffset, collapsed } = window.getSelection().getRangeAt(0);

    return JSON.stringify({ startOffset, endOffset });
}));

const focusOnButton = ClientFunction(() => {
    document.getElementById('btn').focus();
});

test('test', async t => {
    await t
        .selectText('#div', 2, 8)

    await focusOnButton();

    const expectedRange = {
        startOffset: 2,
        endOffset:   8
    }

    await t
        .expect(await getSelectionRange(t)).eql(expectedRange);
});

Result:

>testcafe chrome test.js
 Running tests in:
 - Chrome 84.0.4147.125 / Windows 10

 Fixture
 √ test


 1 passed (1s)

@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 14, 2020
@Farfurix Farfurix removed their assignment Aug 19, 2020
@AndreyBelym AndreyBelym added TYPE: bug The described behavior is considered as wrong (bug). and removed STATE: Need research labels Jan 18, 2021
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.

@github-actions github-actions bot added the STATE: Stale An outdated issue that will be automatically closed by the Stale bot. label Jan 19, 2022
@github-actions
Copy link

We're closing this issue after a prolonged period of inactivity. If it still affects you, please add a comment to this issue with up-to-date information. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HAS WORKAROUND STATE: Stale An outdated issue that will be automatically closed by the Stale bot. TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

3 participants