如何在Chrome上使用MAC上的量角器进行复制和粘贴?

时间:2016-01-21 13:23:41

标签: javascript angularjs protractor

如何在Chrome上使用带有量角器的复制和粘贴功能?

newInput.sendKeys(protractor.Key.chord(browser.controlKey, "a"));
newInput.sendKeys(protractor.Key.chord(browser.controlKey, "c"));
newInput.sendKeys(protractor.Key.chord(browser.controlKey, "v"));

使用此代码时,我有“未定义”

我使用此帖Using cross-platform keyboard shortcuts in end-to-end testing中的此代码,但它不起作用:

browser.controlKey = protractor.Key.CONTROL; //browser.controlKey is     a global variable and can be accessed anywhere in the test specs
browser.getCapabilities().then(function(capabilities){
    if(capabilities.caps_.platform === "MAC")
        browser.controlKey = protractor.Key.COMMAND;
});

elm.sendKeys(protractor.Key.chord(browser.controlKey, "c"));

2 个答案:

答案 0 :(得分:6)

这是known chromedriver problem。不幸的是,从Protractor / WebDriverJS发送键盘快捷键不适用于Chrome + Mac。

在我们的项目中,我们已将所有涉及使用键盘快捷键的测试移至Firefox:

var firefox_only_specs = [
    "../specs/sometest1.spec.js",
    "../specs/sometest2.spec.js"
];

exports.config = {
    multiCapabilities: [
        {
            browserName: "chrome",
            chromeOptions: {
                args: ["incognito", "disable-extensions", "start-maximized"]
            },
            specs: [
                "../specs/*.spec.js"
            ],
            exclude: firefox_only_specs
        },
        {
            browserName: "firefox",
            specs: firefox_only_specs
        }
    ],

    // ...
}

答案 1 :(得分:1)

// This does a select all element1.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, protractor.Key.SHIFT, protractor.Key.HOME)); // This copies the text element1.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, protractor.Key.INSERT)); // This pastes it in another element element2.sendKeys(protractor.Key.chord(protractor.Key.SHIFT, protractor.Key.INSERT)); 已被标记为MAC的wontfix in Protractor's github。这是我根据keyboard commands for left-handed users

改编而成的解决方案

适用于MAC,LINUX和WINDOWS的通用复制+粘贴替代方法:

{{1}}