当前位置:网站首页>SAP Spartacus Accessibility E2E 端到端测试
SAP Spartacus Accessibility E2E 端到端测试
2022-08-01 21:54:00 【华为云】
Spartacus 中的可访问性有自己的一套端到端测试,这些测试位于 projects/storefrontapp-e2e-cypress/cypress/integration/accessibility/tabbing-order.e2e-spec.ts。
其中包括需要用户登录的测试(例如,对于我的帐户页面和购物车),以及不需要用户登录的测试(例如对于主页和登录页面) )。
目前,测试涵盖了通过应用程序的标签。 对于每个新功能,都应该手动编写一个新测试,以检查选项卡的工作方式。 如果 Tab 的某些方面无法正常工作(例如,Tab 顺序不符合预期,或者无法通过 Tab 访问可交互元素),则测试应该失败。
要运行添加到 tabbing-order.e2e-spec.ts 的新测试,请在运行 Cypress 时选择 tabbing-order 测试。
Implementing a New A11y E2E Test
(1) 向 projects/storefrontapp-e2e-cypress/cypress/helpers/accessibility/tabbing-order.config.ts 中的配置对象添加一个新属性。
名称应简短且具有描述性。
login: [ { value: 'userId', type: TabbingOrderTypes.FORM_FIELD }, { value: 'password', type: TabbingOrderTypes.FORM_FIELD }, { value: 'Forgot password?', type: TabbingOrderTypes.LINK }, { value: 'Sign In', type: TabbingOrderTypes.BUTTON }, { value: 'Register', type: TabbingOrderTypes.BUTTON }, ]
注意:
a. The login is of type TabElement[].
b. 类型是一个 TabbingOrderTypes 枚举,它支持多种类型的元素。 您可以通过在 Spartacus 源代码中查找 TabbingOrderTypes 枚举的定义来查看所有支持的类型。
(2) 将新的帮助文件添加到 projects/storefrontapp-e2e-cypress/cypress/helpers/accessibility/tabbing-order/。
import { verifyTabbingOrder } from '../tabbing-order'; import { fillLoginForm } from '../../auth-forms'; import { user } from '../../../sample-data/checkout-flow'; import { TabElement } from '../tabbing-order.model'; const containerSelector = '.LoginPageTemplate'; export function loginTabbingOrder( config: TabElement[], prefillForm: boolean = false ) { cy.visit('/login'); if (prefillForm) { const { email: username, password } = user; fillLoginForm({ username, password }); } verifyTabbingOrder(containerSelector, config); }
a. 某些页面或视图可能需要额外的步骤,并且帮助文件可能比上面显示的示例更大或更复杂。 您可以通过查看 projects/storefrontapp-e2e-cypress/cypress/helpers/accessibility/tabbing-order/ 中现有的帮助程序文件来查看其他示例。
b. 使用 const containerSelector,您可以使用类似 CSS 的选择器创建一个变量来保存您的功能。
c. 导出的函数,例如本例中的 loginTabbingOrder 函数,应该始终带有 TabbingOrder 后缀,并且应该始终以 config 作为参数。
d. cy.visit 是 cypress 功能的一个例子。 在此示例中,它告诉 cypress 访问您的功能所在的页面。
您导出的函数应始终使用预定义的 verifyTabbingOrder(containerSelector, config) 函数。
(3) 在 projects/storefrontapp-e2e-cypress/cypress/integration/accessibility/tabbing-order.e2e-spec.ts 中,从您在上一步创建的帮助文件中导入 TabbingOrder 函数。
例如:
import { loginTabbingOrder } from '../../helpers/accessibility/tabbing-order/login';
(4) 在同一个文件 (tabbing-order.e2e-spec.ts) 中,添加测试。
context('Login page', () => { it('should allow to navigate with tab key (empty form)', () => { loginTabbingOrder(config.login); }); it('should allow to navigate with tab key (filled out form)', () => { loginTabbingOrder(config.login, true); }); });
a. context 应指向您要测试的页面。
b. 字符串 ‘should allow to navigation with tab key’ 在每个测试中都使用,并且应该包含在所有新测试中。
c. loginTabbingOrder 是您在 login.ts 帮助文件中创建的函数,(config.login) 是指您添加到 projects/storefrontapp-e2e-cypress/cypress/helpers/accessibility/tabbing-order 中的配置对象的登录属性 .config.ts(在此过程的第 1 步中)。
边栏推荐
- 高等代数_证明_矩阵的任意特征值的代数重数大于等于其几何重数
- KMP 字符串匹配问题
- 基于php湘西旅游网站管理系统获取(php毕业设计)
- 基于php在线音乐网站管理系统获取(php毕业设计)
- 程序员必备的 “ 摸鱼神器 ” 来了 !
- Dichotomy Medium LeetCode6133. Maximum Number of Groups
- 基于php动漫周边商城管理系统(php毕业设计)
- Unity Shader general lighting model code finishing
- 你居然不懂Bitmap和Drawable? 相关知识大扫盲
- [Mobile Web] Mobile terminal adaptation
猜你喜欢
SOM网络1:原理讲解
feel so stupid
ModuleNotFoundError: No module named 'yaml'
SQL injection of WEB penetration
毕业十年,财富自由:那些比拼命努力更重要的事,从来没人会教你
Upload markdown documents to blog garden
Kubernetes Scheduler全解析
Today's sleep quality record 74 points
Based on php tourism website management system acquisition (php graduation design)
【C语言实现】两种计算平均成绩题型,博主精心整理,值得一读
随机推荐
AIDL communication
使用 Zokrates 在 BSV 上创建您的第一个 zkSNARK 证明
MySQL相关知识
【Objective-C中的@synthesize】
User Experience | How to Measure User Experience?
Spark shuffle调优
number of solutions to solve a multivariate multi-degree equation
第一讲 测试知多少
render-props和高阶组件
小程序--分包
高等代数_证明_矩阵的任意特征值的代数重数大于等于其几何重数
Advanced Algebra_Proof_The algebraic multiplicity of any eigenvalue of a matrix is greater than or equal to its geometric multiplicity
dvwa 通关记录1 - 暴力破解 Brute Force
【建议收藏】ヾ(^▽^*)))全网最全输入输出格式符整理
迁移学习——Discriminative Transfer Subspace Learning via Low-Rank and Sparse Representation
WEB 渗透之端口协议
入门数据库Days4
ModuleNotFoundError: No module named ‘yaml‘
工程建筑行业数据中台指标分析
Based on php online music website management system acquisition (php graduation design)