如何在赛普拉斯中编写方案大纲功能的步骤定义文件 [英] 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:作为参数传递 ...不起作用
And('Click on drop-down to select role "([^"]*)"', (role) => {
cy.get('.add-person__inputs--container > :nth-child(2) > .ui').contains(role).click()
#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()
< a href = https://i.stack.imgur.com/P6KsL.png rel = nofollow noreferrer>
赛普拉斯#1& #2 :
#3 :也尝试过这种方法,并且似乎有更好的镜头,因为它给了我一个不同的错误,哈哈
#3: also tried this and seems to have a better shot cos simply it gave me a different error 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()
#3的柏树结果:
HTML 用于我正在测试的页面,我试图从下拉菜单项中获取那些突出显示的值,但是每个项目前面都没有id或名称
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
我得到了 cy.get('。add-person__inputs--container>:nth-child(2 )> .ui ')
(来自赛普拉斯选择器)
And I got cy.get('.add-person__inputs--container > :nth-child(2) > .ui')
from Cypress selector
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>
请记住,我对编码非常陌生,但我认为问题是步骤定义文件或CSS选择器。 ..:(
please bear in mind I'm very new to coding but I think the issue is either step definition file or css selector... :(
在此先感谢:D
推荐答案
缺少引号,请尝试一下:
It looks in step call missing quotes, try as blow:
And Click on drop-down to select role "<Role>"
这篇关于如何在赛普拉斯中编写方案大纲功能的步骤定义文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!