[英]How to write step definition file of scenario outline feature in Cypress
I'm using Feature file below:我正在使用以下功能文件:
Scenario Outline: Admin can send invitations to any user roles
And Click on drop-down to select role <Role>
Examples:
|Role|
|Admin|
|Manager|
I'm trying to write a step definition file here, but none of them worked我正在尝试在这里编写一个步骤定义文件,但它们都不起作用
#1: Passing as parameters ... doesn't work #1:作为参数传递......不起作用
And('Click on drop-down to select role "([^"]*)"', (role) => {
cy.get('.add-person__inputs--container > :nth-child(2) > .ui').contains(role).click()
#2: Passing as string values ....doesn't work #2:作为字符串值传递......不起作用
And('Click on drop-down to select role {string}', (role_value) => {
cy.get(`.add-person__inputs--container > :nth-child(2) > .ui[value='${role_value}']`).click()
Cypress result of #1 & #2 : #1 & #2 的赛普拉斯结果:
#3 : also tried this and seems to have a better shot cos simply it gave me a different error LOL #3 : 也试过这个,似乎有更好的镜头因为它给了我一个不同的错误 LOL
And('Click on drop-down to select role {string}', (role_value) => {
cy.get('.add-person__inputs--container > :nth-child(2) > .ui').find(role_value).click()
Cypress result for #3 : #3 的赛普拉斯结果:
HTML for the page I'm testing, I'm trying to get those highlighted values from dropdown items but it has no id or name in front of each item我正在测试的页面的HTML ,我试图从下拉项中获取那些突出显示的值,但每个项前面没有 id 或名称
And I got cy.get('.add-person__inputs--container > :nth-child(2) > .ui')
from Cypress selector我从 Cypress 选择器中得到了
cy.get('.add-person__inputs--container > :nth-child(2) > .ui')
HTML tags HTML 标签
<div class="add-person__inputs--container" style="" xpath="1"><div class="field "><span class="login-form__inputs-container--title">Email</span><div class="ui large input login-form__inputs-container--input"><input name="email" placeholder="Add email address" autocomplete="new-password" type="email" value=""></div></div><div class="add-person__description--container"><span class="login-form__inputs-container--title">Role</span><div name="role" role="listbox" aria-disabled="false" aria-expanded="true" class="ui active visible fluid selection dropdown add-person__dropdown" tabindex="0"><div class="text" role="alert" aria-live="polite">Viewer</div><i aria-hidden="true" class="chevron down icon"></i><div class="visible menu transition"><div role="option" aria-checked="true" aria-selected="true" class="active selected item" style="pointer-events: all;">Viewer</div><div role="option" aria-checked="false" aria-selected="false" class="item" style="pointer-events: all;">Grower</div><div role="option" aria-checked="false" aria-selected="false" class="item" style="pointer-events: all;">Manager</div><div role="option" aria-checked="false" aria-selected="false" class="item" style="pointer-events: all;">Admin</div></div></div></div>
please bear in mind I'm very new to coding but I think the issue is either step definition file or css selector... :(请记住,我对编码很陌生,但我认为问题在于步骤定义文件或 css 选择器... :(
Thanks in advance :D提前致谢
它看起来在步骤中调用缺少的引号,尝试一下:
And Click on drop-down to select role "<Role>"
So this is what worked for me:所以这对我有用:
In the feature file:在特征文件中:
And Click on drop-down to select role "<Role>"
In the step definition file:在步骤定义文件中:
And(/^Click on drop-down to select role "(.*?)"$/, (role) => {
cy.get('.add-person__inputs--container > :nth-child(2) > .ui').contains(role).click()
});
In Example: change it to string.在示例中:将其更改为字符串。 This worked for me:
这对我有用:
Scenario Outline: Admin can send invitations to any user roles And click on dropdown to select role.场景大纲:管理员可以向任何用户角色发送邀请并单击下拉列表以选择角色。
Examples:
|Role|
|"Admin"|
|"Manager"|
and和
('Click on drop-down to select role {string}', (role_value) => {
cy.get(`.add-person__inputs--container > :nth-child(2) > .ui[value='${role_value}']`).click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.