types.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. * 基础配置选项,所有配置对象的基类
  3. *
  4. * @description
  5. * 提供通用的配置选项,所有工具函数的配置对象都应该继承此接口。
  6. *
  7. * @example
  8. * ```ts
  9. * interface MyOptions extends BaseOptions {
  10. * customOption?: string;
  11. * }
  12. * ```
  13. */
  14. export interface BaseOptions {
  15. /** 超时时间(毫秒)*/
  16. timeout?: number;
  17. }
  18. /**
  19. * 错误上下文接口,用于提供结构化的错误信息
  20. *
  21. * @description
  22. * 包含操作失败时所需的完整上下文信息,帮助开发者快速定位问题。
  23. *
  24. * @example
  25. * ```ts
  26. * const errorContext: ErrorContext = {
  27. * operation: 'selectRadixOption',
  28. * target: '残疾类型',
  29. * expected: '视力残疾',
  30. * actual: '未找到选项',
  31. * available: ['听力残疾', '言语残疾'],
  32. * suggestion: '检查选项值是否正确'
  33. * };
  34. * ```
  35. */
  36. export interface ErrorContext {
  37. /** 操作类型(如 'selectRadixOption')*/
  38. operation: string;
  39. /** 目标(如下拉框标签)*/
  40. target: string;
  41. /** 期望值 */
  42. expected?: string;
  43. /** 实际值 */
  44. actual?: string;
  45. /** 可用选项列表 */
  46. available?: string[];
  47. /** 修复建议 */
  48. suggestion?: string;
  49. }
  50. /**
  51. * 异步 Select 选项配置
  52. *
  53. * @description
  54. * 用于异步加载选项的 Radix UI Select 组件。
  55. *
  56. * @property {number} timeout - 超时时间(毫秒),默认 5000ms
  57. * @property {boolean} waitForOption - 是否等待选项加载完成,默认 true
  58. * @property {boolean} waitForNetworkIdle - 是否等待网络空闲后再操作,默认 true
  59. *
  60. * @example
  61. * ```ts
  62. * // 默认配置(等待网络空闲和选项加载)
  63. * await selectRadixOptionAsync(page, '省份', '广东省');
  64. *
  65. * // 自定义超时并禁用网络空闲等待
  66. * await selectRadixOptionAsync(page, '城市', '深圳市', {
  67. * timeout: 10000,
  68. * waitForNetworkIdle: false
  69. * });
  70. * ```
  71. */
  72. export interface AsyncSelectOptions extends BaseOptions {
  73. /** 是否等待选项加载完成(默认:true)*/
  74. waitForOption?: boolean;
  75. /** 等待网络空闲后再操作(默认:true)*/
  76. waitForNetworkIdle?: boolean;
  77. }
  78. /**
  79. * 文件上传选项配置
  80. *
  81. * @description
  82. * 用于文件上传工具函数的配置选项。
  83. *
  84. * @property {string} fixturesDir - fixtures 目录路径,默认为 'web/tests/fixtures'
  85. * @property {boolean} waitForUpload - 是否等待上传完成,默认为 true
  86. *
  87. * @example
  88. * ```ts
  89. * // 默认配置
  90. * await uploadFileToField(page, 'photo-upload', 'sample-id-card.jpg');
  91. *
  92. * // 自定义 fixtures 目录
  93. * await uploadFileToField(page, 'photo-upload', 'sample-id-card.jpg', {
  94. * fixturesDir: 'custom/fixtures/path'
  95. * });
  96. *
  97. * // 自定义超时
  98. * await uploadFileToField(page, 'photo-upload', 'sample-id-card.jpg', {
  99. * timeout: 10000
  100. * });
  101. * ```
  102. */
  103. export interface FileUploadOptions extends BaseOptions {
  104. /** fixtures 目录路径,默认为 'tests/fixtures' */
  105. fixturesDir?: string;
  106. /** 是否等待上传完成,默认为 true */
  107. waitForUpload?: boolean;
  108. }
  109. /**
  110. * 表单步骤配置
  111. *
  112. * @description
  113. * 用于表单填写工具函数的配置选项。
  114. *
  115. * @beta 此类型为计划中的功能,对应的工具函数尚未实现。
  116. *
  117. * @example
  118. * ```ts
  119. * // 计划中的功能
  120. * await fillFormField(page, selector, 'value', {
  121. * timeout: 3000,
  122. * scrollToElement: true
  123. * });
  124. * ```
  125. */
  126. export interface FormStepOptions extends BaseOptions {
  127. /** 是否在填写前滚动到元素(默认:true)*/
  128. scrollToElement?: boolean;
  129. }
  130. /**
  131. * 对话框操作配置
  132. *
  133. * @description
  134. * 用于对话框工具函数的配置选项。
  135. *
  136. * @beta 此类型为计划中的功能,对应的工具函数尚未实现。
  137. *
  138. * @example
  139. * ```ts
  140. * // 计划中的功能
  141. * await closeDialog(page, {
  142. * timeout: 2000,
  143. * closeWaitTime: 500
  144. * });
  145. * ```
  146. */
  147. export interface DialogOptions extends BaseOptions {
  148. /** 对话框关闭后的等待时间(毫秒,默认:500)*/
  149. closeWaitTime?: number;
  150. }
  151. // 重新导出 Playwright 类型以便使用者使用
  152. export type { Page } from '@playwright/test';