Cypress: "autofocus" not working with Chrome since Chrome 79

Created on 21 Jan 2020  路  9Comments  路  Source: cypress-io/cypress

Current behavior:

"autofocus" attribute works with Electron and with older Chrome versions, but it does not work in Chrome 79.
When testing a page with "autofocus" attribute, cy.focused() returns no elements, and nothing is in focus.

Chrome console log:

Autofocus processing was blocked because a document's URL has a fragment '#/tests/__all'.

Desired behavior:

Autofocus attribute is working in tests as expected in any supported browser, including Chrome 79.
No warnings in JS console log.

Test code to reproduce


Simple HTML page:

<!DOCTYPE html>
<html>
<body>
<form>
  First name:<br>
  <input type="text" name="firstname" autofocus>
  <br>
  Last name:<br>
  <input type="text" name="lastname">
</form>
</body>
</html>

Code of the integration test:

describe('Focus', function() {
    it.only('autofocus', function() {
        cy.visit('./af.html');
        cy.focused().should('have.attr', 'name','firstname');
    });
});

Versions

Cypress 3.8.2
Chrome 79.0.3945.117
Ubuntu 16.04 and 18.04

chrome ready for work bug

Most helpful comment

Hi,

I think it's broken when there's hashtag in the url, in my case there were 4, and the console message was:

Autofocus processing was blocked because a document's URL has a fragment '####'.

If you open the simple html page in chrome without any testing integrated, autofocus works fine.

All 9 comments

Welp, that is very weird. Confirmed this happens in Chrome 79. Did not narrow down to what specific release.

Screen Shot 2020-01-21 at 10 59 08 PM

Hi,

I think it's broken when there's hashtag in the url, in my case there were 4, and the console message was:

Autofocus processing was blocked because a document's URL has a fragment '####'.

If you open the simple html page in chrome without any testing integrated, autofocus works fine.

Same here

Same issue. Developing an angular app and Chrome won't autofocus. Gives "_Autofocus processing was blocked because a document's URL has a fragment '#/login'._" error. Does work on Firefox.

Here's the tracking bug for chromium: https://crbug.com/1046357

I wouldnt say this is chrome related because I have same issue using firefox 72 beta. Element does not get auto-focused while running tests. After opening page in new tab I can see autofocus is working (same browser)

I noticed on cypress when open interface run tests and I start work with another screen and leave tests running ...
if there is no focus on chrome ... it don't pass tests with focus on fields.

I must to keep the focus on chrome window running

I wouldnt say this is chrome related because I have same issue using firefox 72 beta. Element does not get auto-focused while running tests. After opening page in new tab I can see autofocus is working (same browser)

@dcrystalj Safari doesn't has this issue.

Thanks,
Kenny.

This is related with the html spec.

To fix this problem, spec should be changed (the discussion is going on here), or cypress should change the test url structure.

Was this page helpful?
0 / 5 - 0 ratings