简体   繁体   English

无法使用快捷键(热键)

[英]Unable to use short cut keys (hotKeys)

I am writing e2e tests in NightWatch v2.1.3 using page objects.我正在使用页面对象在 NightWatch v2.1.3 中编写 e2e 测试。 There are list of items, and an item can be selected either by click or by hotKey of its index.有项目列表,可以通过单击或通过其索引的热键来选择项目。

Example: second element can be selected by click or shift+2.示例:可以通过单击或 shift+2 选择第二个元素。

Following code i have written, taking reference from the docs , but it is not working按照我编写的代码,参考文档,但它不起作用

browser.perform(function () {
    const actions = this.actions({async: true});
    console.log('performing hotKeys');
    actions
        .click('@option1')
        .keyDown(Keys.SHIFT)
        .keyDown(Keys.NUMPAD2)
        .keyUp(Keys.NUMPAD2)
        .keyUp(Keys.SHIFT);
});

Console is happening but the click and keyUp, keyDown is not working, when kept inside the .perform method.控制台正在发生,但是当保存在.perform方法中时,单击和 keyUp、keyDown 不起作用。

What need to be fixed here?这里需要修复什么?

  1. return keyword is important. return关键字很重要。 (silly mistake here) (这里是愚蠢的错误)
  2. Use 'a', 'b', '1', '2' for normal keys (single quotes are important, even for numbers)使用 'a'、'b'、'1'、'2' 作为普通键(单引号很重要,即使是数字)
  3. click is not working, inside actions api. Better use the api click instead of userActions click . click不起作用,内部操作 api。最好使用api click而不是userActions click No idea why this click is added under new user-actions.不知道为什么在新用户操作下添加此click The documentations does not have enough examples, one need to find out through hit and trial method.文档中没有足够的示例,需要通过点击和试用的方法来查找。

Example:例子:

  • For SHIFT + 1对于 SHIFT + 1
browser
  .pause(3000)
  .perform(function () {
    const actions = this.actions({ async: true });

    return actions
      .keyDown(Keys.SHIFT)
      .keyDown('1')
      .keyUp('1')
      .keyUp(Keys.SHIFT);
  })
  .pause(2000);
  • For Shift + 10对于 Shift + 10

(This depends on the way feature is developed, if app need both 1 and 0 to be pressed or not) (这取决于功能的开发方式,如果应用程序需要同时按下 1 和 0)

browser
  .pause(3000)
  .perform(function () {
    const actions = this.actions({ async: true });

    return actions
      .keyDown(Keys.SHIFT)
      .keyDown('1')
      .keyUp('1')
      .keyDown('0')
      .keyUp('0')
      .keyUp(Keys.SHIFT);
  })
  .pause(2000);

// keyUp('10') wont work, it is not a valid key in your keyboard
  • For simple 'a'对于简单的'a'

(This depends on the way feature is developed, if app need both 1 and 0 to be pressed or not) (这取决于功能的开发方式,如果应用程序需要同时按下 1 和 0 或不需要)

browser
  .pause(3000)
  .perform(function () {
    const actions = this.actions({ async: true });

    return actions
      .keyDown('a')
      .keyUp('a')
  })
  .pause(2000);

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

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