Last active
May 2, 2018 15:42
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]); |
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.
@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
+1