简体   繁体   English

如何在 Cypress 中编写场景大纲特征的步骤定义文件

[英]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.

相关问题 cypress cucumber - 如何识别调用步骤定义的功能文件? - cypress cucumber - How to identify the which feature file calling step definition? 错误:步骤实现缺少:[step_definition] with cypress &amp; Cucumber 使用示例场景大纲时 - Error: Step implementation missing for: [step_definition] with cypress & Cucumber when using Scenario outline with example 如果我使用 cypress-cucumber,是否必须为每个特征文件创建 Step definition 文件夹? - Do I have to create Step definition folder for each feature file if I am using cypress-cucumber? 如何在 VS 中从特征文件导航到步骤定义文件 - how to navigate from feature file to step definition file in VS 如何在cypress Cucumber中编写可以被Given、When、Then等使用的通用步骤定义 - How to write a common step definition which can be used by Given, When, Then etc. in cypress Cucumber 如何使用正则表达式将数据从特征文件传递到步骤定义文件? - How to pass data from the feature file to step definition file using regular expressions? 如何为cucumber-js中的每个特征文件指定步骤定义文件? - How can I specify step definition file for each feature file in cucumber-js? 如何将功能文件与cucumber.js中的步骤定义相关联(黄瓜为javascript) - How to link feature file with step definition in cucumber.js (cucumber for javascript) 如何使用 WDIO 在 visual studio 中从 BDD 特征文件创建步骤定义 - How to create Step definition from BDD feature file in visual studio using WDIO Cypress Cucumber,如何一步从页面获取数据并在另一个场景步骤中使用它 - Cypress Cucumber, how Get to data from page in one step and use it another scenario step
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM