I am trying to test my GUI using Nightwatch. I can't seem to find a way to simulate a right click. I looked at the API help page ( http://nightwatchjs.org/api ) and searched everywhere. Am I missing something? Since I believe that right-clicking should be one of the most basic functions.
Good news!!!
Since Nightwatch.js v0.6.13 , you can run a real right click : -)
"Right Click to Show ContextMenu" : function (browser) { browser .moveToElement('#targetElement') .mouseButtonClick('right') .pause(5000) .end(); }
EDIT: . . -.
. mousebuttonDown() , . 0,1 2. , - :
"Right Click to Show ContextMenu" : function (browser) { browser .moveToElement(/*locate your element here*/) .mouseButtonDown(2) .mouseButtonUp(2) .end(); }
selenium-webdriver...
Nightwatch.js:
"Right Click to Show ContextMenu" : function (browser) { // inject script in client browser.execute(function(selector){ // dispatch "context menu" event $(selector).trigger('contextmenu'); return true; }, ['#menu']) .pause(5000) .end(); }
(cf. API Nightwatch)
JS:document.querySelector('. logo'). dispatchEvent ( CustomEvent ('contextmenu'));(. , Javascript)
JS:document.querySelector('. logo'). dispatchEvent ( CustomEvent ('contextmenu'));
(. , Javascript)
-:
$('#menu').on('contextmenu', function () { alert('context menu'); //return false; // cancel default menu });