简体   繁体   English

剑道 DatePicker 上的硒(夜间值班)setValue 不起作用

[英]Selenium (nightwatch) setValue on Kendo DatePicker not working

I'm trying to input a date string formatted mm/dd/yyyy into a Kendo React DatePicker control using nightwatch setValue .我正在尝试使用 nightwatch setValue格式为mm/dd/yyyy的日期字符串输入到 Kendo React DatePicker 控件中。 It seems that no matter what approach I take to select the control it always sets the cursor on the year portion first and typing then only fills in those four characters.似乎无论我采用什么方法来选择控件,它总是首先将光标设置在年份部分,然后输入然后只填充这四个字符。 (For example if I provide '05/06/2016', all I see typed into the input is 'mm/dd/0016' and month and day never update.) (例如,如果我提供“05/06/2016”,我在输入中看到的只是“mm/dd/0016”,月和日永远不会更新。)

The control seems to work fine in a normal scenario if I click with the mouse on the month field, the cursor will display there and if I type 2 characters, a / 2 more characters another / and then the last 4 the control is working properly.如果我在月份字段上单击鼠标,该控件似乎在正常情况下工作正常,光标将显示在那里,如果我键入 2 个字符,再输入一个/ 2 个字符/然后最后 4 个字符,控件工作正常. It just seems to be an issue with selenium selecting the control and DatePickers default behavior.硒选择控件和 DatePickers 默认行为似乎只是一个问题。

I've tried using browser.Key.LEFT_ARROW to see if I could move the cursor left twice first since the accessibility handling allows for it.我尝试使用browser.Key.LEFT_ARROW来查看是否可以先将光标向左移动两次,因为可访问性处理允许这样做。 I also tried calling clearValue() on the input first then typing from scratch but no success on either case.我还尝试先在输入上调用clearValue()然后从头开始输入,但在任何一种情况下都没有成功。

I would rather not have select the date using the calendar control if I can avoid it.如果可以避免,我宁愿不使用日历控件选择日期。

Here's what my code looks like currently:这是我的代码目前的样子:

const consumerInfo = {
      birthMonth: "05",
      birthDay: "06",
      birthYear: "2016",
      birthDate: "05/06/2016",
    };

const datePickerSelector = '.myDatePicker';
const datePickerInputSelector = '.myDatePicker .k-input';

browser.waitForElementVisible(datePickerSelector, DEFAULT_WAIT_TIME)
      .waitForElementVisible(datePickerInputSelector, DEFAULT_WAIT_TIME)
      .setValue('.myDatePicker .k-input, [
        consumerInfo.birthYear,
        browser.Keys.LEFT_ARROW,
        consumerInfo.birthDay,
        browser.Keys.LEFT_ARROW,
        consumerInfo.birthMonth,
      ])
      .assert.value(
        datePickerInputSelector,
        consumerInfo.birthDate,
        `Birthdate is set to ${consumerInfo.birthDate}`
      );

Any suggestions are appreciated.任何建议表示赞赏。

While not perfect I came up with a solution so hopefully it helps some others should this come up.虽然不完美,但我想出了一个解决方案,所以希望它可以帮助其他一些人。

The approach ended up being roughly similar to what I proposed above but allowing more time between each operation.该方法最终与我上面提出的方法大致相似,但允许在每次操作之间留出更多时间。 I added it into a util function that accepts the selector to target the input control with along with the month/day/year to fill in the control with.我将它添加到一个 util 函数中,该函数接受选择器以将输入控件以及月/日/年作为目标来填充控件。 It's possible the time intervals can be reduced in places to less than 500ms but without more exhausted testing that was better than 1000ms (which worked) and 100ms (which inconsistently worked).有可能将某些地方的时间间隔减少到小于 500 毫秒,但没有比 1000 毫秒(有效)和 100 毫秒(不一致地有效)更好的更精疲力竭的测试。

See below:见下文:

const toDatePickerInsertion = (browser, pickerInputSelector) => ({
  month,
  day,
  year,
}) => {
  return browser
    .click(pickerInputSelector)
    .pause(500)
    .keys(browser.Keys.LEFT_ARROW)
    .pause(500)
    .keys(browser.Keys.LEFT_ARROW)
    .pause(500)
    .keys(month)
    .pause(500)
    .keys(browser.Keys.RIGHT_ARROW)
    .pause(500)
    .keys(day)
    .pause(500)
    .keys(browser.Keys.RIGHT_ARROW)
    .pause(500)
    .keys(year);
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM