nnnjjj123
2020-11-17 1b2c1edb61190eeb19f465ff031eaa3b2a1b8dbc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
define([
    'intern/dojo/node!leadfoot/helpers/pollUntil',
    'intern/dojo/node!leadfoot/keys',
    'intern/dojo/node!leadfoot/Command'
], function (pollUntil, keys, Command) {
    return {
        isShiftClickSupported: function (remote) {
            // summary:
            //        Detects browser/WebDriver support of shift+click.
            //        This is known to not work in many versions of IE & FF with
            //        Selenium's drivers.
            // remote: PromisedWebDriver
            //        A webdriver instance with a remote page already loaded
            // returns:
            //        A promise that resolves to a boolean
 
            return remote.execute(function () {
                    window.isShiftClickSupported = false;
                    var button = document.createElement('button');
                    button.id = 'shiftClickTestButton';
                    button.onclick = function (event) {
                        window.shiftClickTestButtonClicked = true;
                        window.isShiftClickSupported = event.shiftKey;
                    };
                    document.body.appendChild(button);
                })
                .pressKeys(keys.SHIFT)
                    .findById('shiftClickTestButton')
                    .click()
                    .pressKeys(keys.NULL)
                    .end()
                .then(pollUntil(function () {
                    return window.shiftClickTestButtonClicked;
                }, null, 5000))
                .execute(function () {
                    document.body.removeChild(document.getElementById('shiftClickTestButton'));
                    return window.isShiftClickSupported;
                });
        },
 
        isInputHomeEndSupported: function (remote) {
            // summary:
            //        Detects whether the given browser/OS combination supports
            //        using the home and end keys to move the caret in a textbox.
            // remote: PromisedWebDriver
            //        A webdriver instance with a remote page already loaded
            // returns:
            //        A promise that resolves to a boolean
 
            return remote.execute(function () {
                    var input = document.createElement('input');
                    input.id = 'homeEndTestInput';
                    input.value = '2';
                    document.body.appendChild(input);
                })
                .findById('homeEndTestInput')
                    .click()
                    .type(keys.END + '3' + keys.HOME + '1')
                    .end()
                .execute(function () {
                    var input = document.getElementById('homeEndTestInput'),
                        value = input.value;
                    document.body.removeChild(input);
                    return value === '123';
                });
        },
 
        createCommandConstructor: function (members) {
            // summary:
            //        Creates a custom Command constructor extended with the
            //        provided members.  Based on Leadfoot's Command documentation:
            //        http://theintern.github.io/leadfoot/Command.html
 
            function CustomCommand() {
                Command.apply(this, arguments);
            }
            CustomCommand.prototype = Object.create(Command.prototype);
            CustomCommand.prototype.constructor = CustomCommand;
 
            Object.keys(members).forEach(function (name) {
                CustomCommand.prototype[name] = members[name];
            });
 
            return CustomCommand;
        }
    };
});