Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give a chance to send more then one key at time #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rombok
Copy link

@rombok rombok commented Mar 16, 2021

Please. Could you add something like this? It gives a way to insert a file path into browsers upload dialog.
e.g.

/**                                                                                                                                                                                                                                           
 * @When I drag :file at droparea :targetClass                                                                                                                                                                                                
 */                                                                                                                                                                                                                                           
public function iDragFileAtDroparea($file, $targetClass)                                                                                                                                                                                      
{                                                                                                                                                                                                                                             
    /** @var NodeElement $dropArea */                                                                                                                                                                                                         
    $dropArea = $this->getNodeElement('.' . $targetClass);                                                                                                                                                                                    
    $js = <<< EOJS                                                                                                                                                                                                                            
        e = document.createElement('input');                                                                                                                                                                                                  
        e.type = 'file';                                                                                                                                                                                                                      
        e.id = 'uploadFile';                                                                                                                                                                                                                  
        e.addEventListener('change', function(event) {                                                                                                                                                                                        
            var dataTransfer = {                                                                                                                                                                                                              
                dropEffect: '',                                                                                                                                                                                                               
                effectAllowed: 'all',                                                                                                                                                                                                         
                files: e.files,                                                                                                                                                                                                               
                items: {},                                                                                                                                                                                                                    
                types: [],                                                                                                                                                                                                                    
                setData: function(format, data) {},                                                                                                                                                                                           
                getData: function(format) {}                                                                                                                                                                                                  
            };                                                                                                                                                                                                                                
            var emit = function(event, target) {                                                                                                                                                                                              
                var evt = document.createEvent('Event');                                                                                                                                                                                      
                evt.initEvent(event, true, false);                                                                                                                                                                                            
                evt.dataTransfer = dataTransfer;                                                                                                                                                                                              
                target.dispatchEvent(evt);                                                                                                                                                                                                    
            };                                                                                                                                                                                                                                
            tgt = window.document.getElementsByClassName("$targetClass")[0];                                                                                                                                                                    
            emit('dragenter', tgt);                                                                                                                                                                                                           
            emit('dragover', tgt);                                                                                                                                                                                                            
            emit('drop', tgt);                                                                                                                                                                                                                
            document.body.removeChild(e);                                                                                                                                                                                                     
        }, false);                                                                                                                                                                                                                            
        document.body.appendChild(e);                                                                                                                                                                                                         
    EOJS;                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                              
    $this->getSession()->executeScript($js);                                                                                                                                                                                                  
    $this->getSession()->getDriver()->sendKeys('//input[@id="uploadFile"]', $file);                                                                                                                                                           
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant