We have smoke tests that run shortly after deployment on our web application. Sometimes it takes the login page takes a while for its first load.
- Error in Role initializer -
Failed to complete a request to "https://myurl.com/account/login/" within the
timeout period. The problem may be related to local machine's network or firewall settings, server outage, or network problems that make the server inaccessible.
I'm hoping that adding a setPageTimeout
in my Roles will solve this issue, however, I can't confirm until Tuesday.
Can anyone confirm if setPageTimeout
is the way to go? If not, is there a solution available?
import { Role } from 'testcafe';
import { config, pageWait } './config/config';
import { loginPage } from '../pages'
const defaultPageTimeout = 5000;
export const orgAdminRole: Role = Role(config.baseUrl, async t => {
await t
.setPageLoadTimeout(pageWait.extraLongPoll)
.typeText(loginPage.userNameInput, config.orgAdminUser)
.typeText(loginPage.passwordInput, config.orgAdminPass)
.click(loginPage.loginButton)
.setPageLoadTimeout(defaultPageTimeout);
}, { preserveUrl: true });
export const userRole: Role = Role(config.baseUrl, async t => {
await t
.setPageLoadTimeout(pageWait.extraLongPoll)
.typeText(loginPage.userNameInput, config.user)
.typeText(loginPage.passwordInput, config.userPass)
.click(loginPage.loginButton)
.setPageLoadTimeout(defaultPageTimeout);
}, { preserveUrl: true });
UPD: Use the following API to configure your timeouts:
--page-load-timeout-ms
--ajax-request-timeout-ms
--page-request-timeout-ms
Old answer: The reason of this issue is the request timeouts. So, using setPageLoadTimeout is not a solution in your test case.
As a workaround, I suggest you change the request timeouts:
import { Selector } from 'testcafe';
// Import DestinationRequest from the testcafe-hammerhead module. Please, specify your own environment path.
import { DestinationRequest } from '../../../../../../node_modules/testcafe-hammerhead/lib/request-pipeline/destination-request';
fixture `Fixture`
.page `https://example.com`;
test('test', async t => {
// Set timeouts
DestinationRequest.XHR_TIMEOUT = 10 * 60 * 1000; // XHR requests timeout
DestinationRequest.TIMEOUT = 10 * 60 * 1000; // other requests timeout
// Actions and assertions
// Restore default timeouts
DestinationRequest.XHR_TIMEOUT = 2 * 60 * 1000;
DestinationRequest.TIMEOUT = 25 * 1000;
});
We will consider the implementation of public options to set the timeouts in the context of the following issue: https://github.com/DevExpress/testcafe/issues/2940.
As an addition to the previous answer I think TestCafe have changed DestinationRequest
exporting mode. So I'm using as import * as DestinationRequest ...
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With