0

I created a test to check if the synchronization button works correctly. After clicking the button, the requests for the documents (items) are sent. When I run the test with TestCafe, it requests only for the first element and then stops, even if there are 50 elements to be requested. I've tested it manually and I'm sure it works (requests for 50 elements in a row) so TestCafe causes problems. Does anyone know what's the problem? I've also tested the same thing in Protractor and it worked but not in TestCafe.

I run the synchronization by clicking the button (SYNC_WHEEL).

fixture('should check if the synchronization works').page('http://localhost:3000/');

test('should check if the synchronization works', async t => {

    await t

    .expect(homePage.SYNC_WHEEL.visible).ok()

    .click(homePage.SYNC_WHEEL)

    .wait(10000)

});
Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
  • Hello, Please share the code that is executed when you click the SYNC_WHEEL button. I hope this code sample will help me reproduce the issue and figure out what's going on and why this issue occurs. – Pavel Avsenin Jun 30 '21 at 10:27
  • Sorry, I cannot paste the code here but find my detailed description below. After clicking the synchronization button, items from the SQL database are requested and put to the indexedDB (local DB). It is done by react/redux application. When clicking the synchronization button in TestCafe only one item is added to indexedDB. In the case of manual testing, the whole range (50 items) are added. – Krzysztof Włochyński Jul 01 '21 at 12:19

1 Answers1

1

I have created a test example that emulates the click button via ClientFunction, fetches 100 items, and inserts them into an indexedDB instance. The issue is not reproducible with this sample. Would you check if this sample works correctly on your side? If so, can you change it so that it reproduces the initial issue?

import { ClientFunction } from 'testcafe';

const clickButtonEmulation = ClientFunction(() => {
fetch('https://jsonplaceholder.typicode.com/posts')
    .then(response => response.json())
    .then(posts => {            
        var request = window.indexedDB.open("MyTestDatabase", 3);
        request.onerror = function(event) {
            console.error(event);
        };
        request.onupgradeneeded = function(event) {
            var db = event.target.result;
            var objectStore = db.createObjectStore("posts", { keyPath: "id" });

            for (var i in posts) {
                objectStore.add(posts[i]);
            }

            objectStore.openCursor().onsuccess = function(event) {
                var cursor = event.target.result;
                if (cursor) {
                    console.log("Value for the key " + cursor.key + " is " + cursor.value);
                    cursor.continue();
                }
                else {
                    console.log("No more entries!");
                }
            };
        };
        
    })
});

fixture `fixture`
    .page `http://google.com`;

test(`1`, async t => {
    await clickButtonEmulation();

    await t.debug();
});
Pavel Avsenin
  • 254
  • 1
  • 2