Testcafe-hammerhead: Cannot read property 'indexOf' of undefined

Created on 22 Nov 2017  路  3Comments  路  Source: DevExpress/testcafe-hammerhead

Environment: chrome windows 10.
Tested URL: https://rentalbeast.com/apartments/for_rent/#!/search/general

The app uses angular and RoR.

TestsScript:

import { Selector } from 'testcafe'; 

fixture `Getting Started`
    .page `https://rentalbeast.com/apartments/for_rent/#!/search/general`;  

test('Test search by city', async t => {
    const mainSearchInputExists = await Selector('.main-search-input').exists;
    const mainSearchInputCount = await Selector('.main-search-input').count;
    console.log(`Exists: ${mainSearchInputExists}. Count: ${mainSearchInputCount}`); //This seems ok
    await t.
        expect(mainSearchInputExists).ok(); // This is also ok
});

The test fails with a "Cannot read property 'indexOf' of undefined" And when debugging it on chrome I found these errors:
image

client level 1 storages bug

Most helpful comment

File https://rentalbeast.com/assets/application-b21baee6b0c6be73cc0fa5a8721c7679c078f7f9bd9098bc96d366ed79403e95.js contains the following piece of code:

...
 $(".find-input").keyup(function(e) {
        if (13 == e.keyCode)
            homeFindRentalsSubmit();
        else
            for (var loc in sessionStorage)
                delete sessionStorage[loc]
    });
...

There is a workaround for the problem described above.
As I understand you need to clear sessionStorage. Rewrite as:

 $(".find-input").keyup(function(e) {
        if (13 == e.keyCode)
            homeFindRentalsSubmit();
        else
           sessionStorage.clear();
    });

and TestCafe will work without errors.

All 3 comments

Hi @madroneropaulo.
I reproduced the issue.

Proxy processed the following code wrongly:

sessionStorage.setItem('1', '1');

for (var loc in sessionStorage)
    delete sessionStorage[loc];

File https://rentalbeast.com/assets/application-b21baee6b0c6be73cc0fa5a8721c7679c078f7f9bd9098bc96d366ed79403e95.js contains the following piece of code:

...
 $(".find-input").keyup(function(e) {
        if (13 == e.keyCode)
            homeFindRentalsSubmit();
        else
            for (var loc in sessionStorage)
                delete sessionStorage[loc]
    });
...

There is a workaround for the problem described above.
As I understand you need to clear sessionStorage. Rewrite as:

 $(".find-input").keyup(function(e) {
        if (13 == e.keyCode)
            homeFindRentalsSubmit();
        else
           sessionStorage.clear();
    });

and TestCafe will work without errors.

Was this page helpful?
0 / 5 - 0 ratings