Skip to content

Instantly share code, notes, and snippets.

@smooney
Last active May 2, 2018 15:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smooney/d8b0e7b5f7b89d74bb7d to your computer and use it in GitHub Desktop.
Save smooney/d8b0e7b5f7b89d74bb7d to your computer and use it in GitHub Desktop.
Quick function to get Selenium Webdriver to work with React drag and drop methods. Dependencies on React and React Test Utils.
// driver.execute_script(path/to/this/script, dragElement, dropElement)
(function(dragItem, dropZone) {
var simulateDragDrop = function(dragItem, dropZone) {
var mockEvent = {
dataTransfer: {
data: {
},
setData: function(type, val){
this.data[type] = val;
},
getData: function(type){
return this.data[type];
}
}
};
React.addons.TestUtils.Simulate.dragStart(dragItem, mockEvent);
React.addons.TestUtils.Simulate.dragOver(dropZone, mockEvent);
React.addons.TestUtils.Simulate.drop(dropZone, mockEvent);
};
simulateDragDrop(dragItem, dropZone);
})(arguments[0], arguments[1]);
@robbiewareham
Copy link

+1

@abobwhite
Copy link

Thanks for this! Could you show an example of the usage in selenium or geb? Also - what's your approach for including the react test utils into the page? The addons are only included in the non-minified version of react-with-addons but the non-minified is very inefficient rendering due to propType validation.

@jgrabow1
Copy link

jgrabow1 commented May 2, 2018

@abobwhite Did you ever figure out how to include the react test utils? I'm having trouble with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment