【问题标题】:How to mock day.js using testcafe to click on calender如何使用testcafe模拟dayjs点击日历
【发布时间】:2020-05-04 17:39:35
【问题描述】:

我正在尝试使用带有今天日期的测试咖啡馆单击日历,我尝试使用时刻获取日期格式但无法单击日历,我正在使用选择器(withText),它总是返回未找到选择器.

【问题讨论】:

  • 您能澄清一下您的确切问题吗?是“如何模拟图书馆”、“如何点击日历”还是“为什么选择器什么都不返回”?你用的是什么日历?您尝试过哪些方法?你的测试代码是什么样的?
  • 感谢@Alex Skorkin 的回复我的问题是如何点击日历?开发人员使用 day.js 包装器,我尝试使用类,但它们具有动态值并且无法识别选择器。 // 等待 t.click(this.btnDate); var selected_date = moment(); var output_pattern = "dddd, MMMM D, YYYY"; var todayDate = selected_date.format(output_pattern);等待 t .expect(this.test.getAttribute('aria-label')).contains(todayDate);等待 t.click(this.test.withText(todayDate)); // 另外请发布一个如何点击 day.js 的示例
  • 抱歉,这些信息仍然不足以让我们看到问题。您能否提供一个简单示例或指向您正在使用的日历的公共链接?
  • @Artem 谢谢phila.gov/the-latest/archives/#/?templates=featured 这个网址有示例日期选择器,我没有使用类似的,但我想知道它是如何工作的

标签: testing automation automated-tests e2e-testing testcafe


【解决方案1】:

https://www.phila.gov/the-latest/archives/#/?templates=featured 的示例

import { Selector } from 'testcafe';

fixture `Select date`
    .page `https://www.phila.gov/the-latest/archives/#/?templates=featured`

test('Select date', async t => {
    const dateInput = Selector('input[name="start"]');

    await t
        .click(dateInput)
        .click(dateInput.parent('.vdp-datepicker').find('.cell.day').withText('2'))
        .expect(dateInput.value).eql('May. 02, 2020');
});

【讨论】:

  • 谢谢@Artem
猜你喜欢
  • 1970-01-01
  • 2021-03-15
  • 1970-01-01
  • 2011-02-11
  • 1970-01-01
  • 2020-05-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多