Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to use Select, Cut, Copy & Paste using Protractor in Mac OS

Select, Cut, Copy & Paste using Protractor in Mac-OS

If you are a QA Engineer then somewhere down the road you will come across Protractor/selenium and face limitations that come with automation.

I faced a similar limitation when I had to copy a 7-page google document and paste it in my application to verify whether the formatting of the document is affected or not.

So the problem here arises when we are working with mac OS.

MacOS + Selenium/Protractor, doesn’t allow native functions to be called, which in simple words means that you cannot perform either command +a , command + C or command +v in mac.

OSX does not support native key events, so the Driver simulates all key presses. This means that the key press is contained within the “content” window, so the browser probably never sees the COMMAND as it would from a native event.

So I had to find a workaround in order to conquer the wild elephants and I would be talking about the same in this blog

  • Cut: Shift+Delete
  • Copy: Ctrl+Insert
  • Paste: Shift+Insert
  • Select: SHIFT + Arrow_down

Select-All

`browser.actions().sendKeys(protractor.Key.chord(protractor.Key.SHIFT, protractor.Key.ARROW_DOWN)).perform();

browser.getCapabilities().then(function(capabilities) {
let browserName = capabilities.get('platform');
console.log("Performing select all on " + browserName);
if (browserName == 'Windows NT') {
ele.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, "a"));
}
else
{
for (let i = 0; i  text.length; i++) {
browser.actions().sendKeys(protractor.Key.chord(protractor.Key.SHIFT, protractor.Key.ARROW_DOWN)).perform();}
}
});

Paste

`browser.actions().sendKeys(protractor.Key.chord(protractor.Key.SHIFT, protractor.Key.INSERT)).perform();}

browser.getCapabilities().then((capabilities) => {
let browserName = capabilities.get(platform);
console.log(Browser is  + browserName);
if (browserName == Windows NT) {
browser.actions().sendKeys(protractor.Key.chord(protractor.Key.CONTROL, "v")).perform();
}
else
{
browser.actions().sendKeys(protractor.Key.chord(protractor.Key.SHIFT, protractor.Key.INSERT)).perform();
}
});

Copy

`browser.actions().sendKeys(protractor.Key.chord(protractor.Key.CONTROL, protractor.Key.INSERT)).perform();

browser.getCapabilities().then((capabilities) => {
let browserName = capabilities.get(platform);
console.log(Browser is  + browserName);
if (browserName == Windows NT) {
browser.actions().sendKeys(protractor.Key.chord(protractor.Key.CONTROL, "c")).perform();
}
else
{
browser.actions().sendKeys(protractor.Key.chord(protractor.Key.CONTROL, protractor.Key.INSERT)).perform();
}
});

CUT

browser.actions().sendKeys(protractor.Key.chord(protractor.Key.SHIFT, protractor.Key.DELETE)).perform();

browser.getCapabilities().then((capabilities) => {
let browserName = capabilities.get(platform);
console.log(Browser is  + browserName);
if (browserName == Windows NT) {
browser.actions().sendKeys(protractor.Key.chord(protractor.Key.CONTROL, "x")).perform();
}
else
{
browser.actions().sendKeys(protractor.Key.chord(protractor.Key.SHIFT, protractor.Key.DELETE)).perform();
}
});

I talked about some of the challenges in protractor automation. In scenarios where you would like to use protractor to test your web application across different operating systems, and devices in a more scalable manner, one can easily use the above mentioned workarounds.

I hope you find them useful.



This post first appeared on C.R.A.P. Design Principles To Improve Visual Appeal, please read the originial post: here

Share the post

How to use Select, Cut, Copy & Paste using Protractor in Mac OS

×

Subscribe to C.r.a.p. Design Principles To Improve Visual Appeal

Get updates delivered right to your inbox!

Thank you for your subscription

×