What are some tips for using copy and paste with Protractor on a Mac using Chrome?

Is there a way to utilize copy and paste functionality with Protractor on a MAC using 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"));

Upon executing this code, I am encountering an issue where it returns "undefined"

I attempted to implement the code found in this post Using cross-platform keyboard shortcuts in end-to-end testing, however, it is not functioning as expected:

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"));

Answer №1

It has been brought to our attention that there is a known issue with chromedriver. Regrettably, sending keyboard shortcuts from Protractor/WebDriverJS does not function properly on Chrome for Mac.

As a solution in our project, we have transitioned all tests requiring the use of keyboard shortcuts to 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
        }
    ],

    // ...
}

Answer №2

protractor.Key.COMMAND has been deemed unsolvable in Protractor's GitHub repository for MAC users. I found a workaround inspired by keyboard shortcuts designed for left-handed individuals on this website

Here's a universal copy and paste alternative that works across MAC, LINUX, and WINDOWS platforms:

// Select all text
element1.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, protractor.Key.SHIFT, protractor.Key.HOME));

 // Copy the selected text
element1.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, protractor.Key.INSERT));

// Paste the copied text into another element
element2.sendKeys(protractor.Key.chord(protractor.Key.SHIFT, protractor.Key.INSERT));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on positioning components to the right side of the NavigationDrawer in Vuetify with VueRouter

Working on my VueJS project, I've implemented a system to display content based on the user login using Firebase and Vuex state management. When a user is logged in, the content is shown using the v-if directive. Currently, I have successfully placed ...

Failure to pass a variable declared within a function to another JavaScript file running simultaneously

After combing through numerous posts on Google and Stack Overflow, I am still unable to pinpoint why this particular issue persists. This case involves 2 HTML files and 2 JS files (explanations provided below in text following the code snippets). 1) inde ...

Mastering Angular Service Calls in TypeScript: A Comprehensive Guide

In the midst of my TypeScript angular project, I am aiming to revamp it by incorporating services. However, I have encountered an issue where when calling a function within the service, the runtime does not recognize it as the service class but rather the ...

Angular File Sorting Error in Gulp detected

After including .pipe(angularFilesort()) in my gulp script, the task runs wiredep but never proceeds to the default task. It just stops after executing wiredep. However, if I remove .pipe(angularFilesort()), the script works perfectly fine. Can someone h ...

npm is unable to install a forked git repository in its current state

Attempting to install a customized version of ng2-smart-table on my application, but npm seems to be struggling with the process. I've experimented with various commands such as npm install git+http://github.com/myusername/ng2-smart-table.git npm i ...

Backdrop behind of Bootstrap modal located back of other page contents

I'm facing some challenges after transferring a website I developed locally to a live server. The modal windows are appearing behind other content on the live server, although they work perfectly fine on the local version. Despite my attempts to adju ...

NodeJS is capable of handling a limited number of requests at a time

Utilizing jQuery to send requests to a local server has been causing some issues. After sending approximately 4-7 requests, the port stops working without any visible error. Eventually, after a few minutes, some of the requests are successfully sent to the ...

The concept of nested ng-repeat in AngularJS

My HTML structure is as follows: <div class="fields-plan"data-ng-repeat="roomname in assign.roomname"> <section> <span>Room: {{roomname}}</span> </section> <ul data-ng-repeat="r ...

Boost the frequency of updates in Meteor.observe

When Python writes to a database (mongo) every second in the setup, Meteor.js is expected to react immediately to the new record insertion. Issue: However, the use of cursor.observe() results in the console outputting only 4-5 seconds after the new record ...

From AJAX response to React state attribute, store the JSON data

I have a component where I need to fetch freight values via ajax and store them in the state property of this class. import React, { Component } from 'react'; import Freight from './Freight'; import CreateFreightEntryModal from '. ...

Issue with xsl:include functionality in a Firefox extension

I've been working on a Firefox extension that utilizes XSL transformations with no issues. However, I encountered a problem when trying to perform an xsl:include from the XSL stylesheet. Upon importing the XSL stylesheet containing an xsl:include stat ...

Using Vue.js's ref within a v-for iteration

When attempting to utilize components within a v-for loop and initialize the ref for future access to their methods from the parent component, I encountered an issue. Below is a simplified version of the code that demonstrates my scenario: <template> ...

The YYYY-dd-mm input mask pattern is malfunctioning

Hello, I am having trouble creating a pattern for an input field in the format YYYY-mm-dd. My code is not working properly. Can someone please help me correct my code? Any assistance would be greatly appreciated. <html> <head> <title>En ...

What is the method for sending raw put data using the request npm package in a Node.js environment

How can I hit an API using the "require" npm package in Node? The API requires raw PUT data instead of PUT fields. Can anyone please guide me on how to achieve this using the request npm package? For example, here is the raw PUT data that needs to be sent ...

Auto-scrolling text box cursor movement

My query is quite similar to the topic discussed in this thread on automatic newline in textarea. However, my situation involves multiple textareas with a 1-row attribute, making it seem like writing on air due to the absence of visible borders (I've ...

Any tips on how to retrieve the data from an AJAX request using vanilla JavaScript?

After successfully implementing my first AJAX call last week, I am now faced with a new challenge. This time, I need to not only change something onSuccess but also access the returned data. <script type="text/javascript"> function showMessage(j ...

Add information to the Database seamlessly without the need to refresh the page using PHP in combination with JQuery

Check out my code below: <form action='insert.php' method='post' id='myform'> <input type='hidden' name='tmdb_id'/> <button id='insert'>Insert</button> <p i ...

How can I apply a CSS class to the main element of the component?

Instead of simply adding the class in html code, I am looking for a solution like this: In html <my-component></my-component> In JavaScript angular.module('app').component('myComponent', { template: '<div clas ...

simulate angular service/promise in a karma/jasmine test

As I work on writing a karma/jasmine test, I'm seeking clarification on how mocks function in a service that returns a promise. Here's my scenario: Within a controller, I make the following call: mapService.getMapByUuid(mapUUID, isEditor).then( ...

Unable to access property 'scrollToBottom' as it is undefined

I'm encountering the error "Cannot read property 'scrollToBottom' of undefined" and haven't been able to find a solution anywhere, hence this post: Here is my use case: I have a custom accordion list, and on click of one of the list i ...