protractor - 如何根据通过特征文件传递的数据更新 xpath
问题描述
我有一个需要点击日期的场景。需要从功能文件发送日期。xpath如下。
//table[@class="mat-calendar-table"]/tbody/tr/td[@aria-label="January 1, 2019"].
功能文件如下
Scenario: Protractor date pickers Test"
Given Go to title page
Then The title must be "Datepicker | Angular Material"
When enter the date "January 6, 2019"
请让我知道如何将日期从功能文件传递到 xpath
解决方案
import { Given, Then, When } from "cucumber";
// if using async/await
When(/^enter the date "(.*)"$/, async(date) => {
var util = require('util');
var xpath = '/table[@class="mat-calendar-table"]/tbody/tr/td[@aria-label="%s"]'
return await element(by.xpath(util.format(xpath, date))).sendKeys(date);
});
// not using async await
When(/^enter the date "(.*)"$/, (date) => {
var util = require('util');
var xpath = '/table[@class="mat-calendar-table"]/tbody/tr/td[@aria-label="%s"]'
return element(by.xpath(util.format(xpath, date))).sendKeys(date);
});
推荐阅读
- javascript - .map() 函数显示我在 React Native 中为每个孩子隐藏的动画视图。我正在使用钥匙和身份证
- json - Bash中JSON内部的随机字符串
- javascript - 为什么并行在javascript中具有不同的含义
- discord.js - 如何让我的不和谐机器人检测嵌入的字段、标题字段和字段描述?
- mongodb - MongoDB 驱动程序分页
- nlp - word2vec 余弦相似度大于 1 阿拉伯文本
- java - IntelliJ 无法在 Java 1.8.0 下启动:需要 Java 11 或更高版本
- node.js - 如何更新猫鼬中的嵌套数组?
- python - 在 Python 中提取文件的创建时间
- javascript - 项目的 vue.draggable 和持久位置