我们在部署到Web应用程序后不久就会进行冒烟测试。有时,登录页面需要一段时间才能进行首次加载。
- 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.
我希望在我的角色中添加一个setPageTimeout
可以解决这个问题,但是,直到周二才能确认。
任何人都可以确认setPageTimeout
是否可行?如果没有,是否有可用的解决方案?
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 });
此问题的原因是请求超时。因此,在您的测试用例中使用setPageLoadTimeout
不是解决方案。
作为解决方法,我建议您更改请求超时:
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;
});
我们将考虑实施公共选项,以便在以下问题的背景下设置超时:https://github.com/DevExpress/testcafe/issues/2940。