bUnit: Make it easy to pass keys to keyboard event triggers

The current keyboard event triggers require you to pass the explicit key as a string you want, e.g. cut.Find("input").KeyPress("a"). That works ok for normal characters, but for keys like “backspace” it can be confusing to the user.

To make it easier, we should investigate having a helper class, type, or enum, that provides the values, so we avoid the “magic strings” in the test code. E.g.:

cut.Find("input").KeyPress(Key.Enter);
cut.Find("input").KeyPress(Key.Backspace);
cut.Find("input").KeyPress(Key.A);
cut.Find("input").KeyPress(Key.a); // difference between lower case and upper case letters?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 16 (16 by maintainers)

Most upvoted comments

I can handle those guidelines. 😃 I’ll make the change.

I think the API should only be for special characters. It should be a static class with static properties for each special key, like:

    public static class Keys
    {
        public static string Backspace { get; }
        ...

Then in a test you would use it as follows:

    element.KeyPress("z");               // for text keys
    element.KeyPress(Keys.Backspace);    // special keys

This would be great for people new to the bUnit library. It would definitely make it more accessible and other test libraries, like Selenium have a Keys class for doing this.

It is difficult to find the documentation of the special keys (without asking someone), and they are useful in testing input controls. Backspace is a relatively easy one to figure out, but whether it’s Up, UpArrow, or ArrowUp is more complicated.