镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

pressKey() does not work properly on Firefox #4115

Closed

Description

@PierreRott

What is your Test Scenario?

Use pressKey('backspace') on Firefox.

What is the Current behavior?

pressKey('backspace') does not work on Firefox, i.e. it doesn't remove the character that should be removed after pressing backspace.

What is the Expected behavior?

pressKey() should accept backspace and other keys as it is on Chrome.

What is your web application and your TestCafe test code?

Your website URL (or attach your complete example):
<input id="nativeInput" type="text" (keypress)="onKeyPress($event)"/>
onKeyPress(event:KeyboardEvent) {
        const eventValue = String.fromCharCode(event.keyCode);
        console.log(eventValue);
        const isValidByPattern = /^[0-1]*$/.test(eventValue);
        console.log(isValidByPattern);
        return isValidByPattern;
 }
Your complete test code (or attach your test files):
test('Should test pressKey', async () => {
    await t
        .typeText(Selector('#nativeInput'), '1')
        .pressKey('backspace')
        .expect(Selector('#nativeInput').value).eql('');
});
Console logs:
// after typing '1' to the input
1 
true
// after pressing backspace
� 
false

Steps to Reproduce:

  1. Create an input which handles keypress
  2. Try to use TestCafe's pressKey('backspace') with it

Your Environment details:

  • testcafe version: 1.2.1
  • node.js version: v10.16.0
  • command-line arguments: testcafe firefox test.ts
  • browser name and version: Firefox 68.0.1
  • platform and version: Windows 10 Enterprise
  • other:

Activity

  1. self-assigned this
    on Aug 6, 2019
  2. aleks-pro commented on Aug 7, 2019

    @aleks-pro
    Collaborator

    Hello @PierreRott ,
    I couldn't reproduce the issue. I tried this with TestCafe 1.2.1, NodeJS 10.16.0, and Firefox 68.0.1. Please check the following test example:

    import { Selector } from 'testcafe';
    
    fixture`Fixture`
        .page`https://jsfiddle.net/qmLvroy4/`;
    
    test('Should test pressKey', async t => {
        await t
            .switchToIframe(Selector('[name="result"]'))
    
            .typeText(Selector('#nativeInput'), '1')
            .pressKey('backspace')
            .expect(Selector('#nativeInput').value).eql('');
    });

    Can you please modify it to show the issue in action?

  3. PierreRott commented on Aug 12, 2019

    @PierreRott
    Author

    JSFiddle example has been modified:

    const inputEl = document.getElementById('nativeInput');
    inputEl.addEventListener('keypress', onKeyPress);
    function onKeyPress(event) {
      const eventValue = String.fromCharCode(event.keyCode);
      console.log(eventValue);
      const isValidByPattern = /^[0-1]*$/.test(eventValue);
      console.log(isValidByPattern);
    
     if (!isValidByPattern) {
        event.preventDefault();
      }
    
      return isValidByPattern;
    }
    
  4. self-assigned this
    on Aug 12, 2019
  5. AlexKamaev commented on Aug 12, 2019

    @AlexKamaev
    Contributor

    @PierreRott
    Thank you for your example, I was able to reproduce the issue.

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
    <input id="nativeInput" type="text" />
    
    <script>
        const inputEl = document.getElementById('nativeInput');
    
        inputEl.addEventListener('keypress', onKeyPress);
    
        function onKeyPress(event) {
            const eventValue = String.fromCharCode(event.keyCode);
            console.log(eventValue);
            const isValidByPattern = /^[0-1]*$/.test(eventValue);
            console.log(isValidByPattern);
    
            if (!isValidByPattern) {
                event.preventDefault();
            }
    
            return isValidByPattern;
        }
    </script>
    
    </body>
    </html>
    import { Selector } from 'testcafe';
    
    fixture`Fixture`
        .page`../pages/index.html`;
    
    test('test', async t => {
        await t
            .typeText(Selector('#nativeInput'), '111')
            .pressKey('backspace')
            .pressKey('backspace')
            .pressKey('backspace')
            .expect(Selector('#nativeInput').value).eql('');
    });
  6. 16 remaining items

  7. daimoonis commented on Nov 29, 2022

    @daimoonis

    Hello, is there any update regarding this issue? Seems to me the Firefox pressKey issue is still relevant. I was able to reproduce both cases (#4115 (comment), #4115 (comment)) on testcafe 2.0.0 and FF 107.

  8. github-actions commented on Nov 30, 2022

    @github-actions

    No updates yet. Once we get any results, we will post them in this thread.

  9. hendriku commented on Feb 9, 2023

    @hendriku

    The issue was resolved for us through an update to testcafe 2.3.0

  10. removed
    STATE: Need responseAn issue that requires a response or attention from the team.
    on Feb 10, 2023
  11. removed
    STATE: StaleAn outdated issue that will be automatically closed by the Stale bot.
    on Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions