andywer / drag-mock

Trigger HTML5 drag & drop events for testing
MIT License
35 stars 11 forks source link

Using it with webdriver.io from a test #8

Open prewk opened 7 years ago

prewk commented 7 years ago

Hi, I'm unsure on how to add the functionality from inside a test.

dragMock.extendWebdriver(webdriver); and dragMock.loadLibrary(webdriver); assumes I have a webdriver, but afaik I only have a browser?

const dragMock = require('drag-mock');

describe('Something', function() {
  it('should drag n drop', function() {
    // How do I extend and load it into the webdriver here?
    dragMock.extendWebdriver(browser);
    dragMock.loadLibrary(browser);

    browser.dragStart('.Something');
    // ^-causes a "browser.dragStart is not a function" error
  });
});

Do I add it to the webdriver in one of the lifecycle hooks in wdio.conf.js? I can't find the right method or argument there, unfortunately.

andywer commented 7 years ago

Are you using webdriver.io? Then I suggest using the before() hook in your test file. And you also have the webdriver object: http://webdriver.io/guide.html

If you are not using webdriver, you shouldn't have to care about extendWebdriver() and loadLibrary().

Hope that helps!

prewk commented 7 years ago

Thanks, I am using webdriver.io, and that guide (scroll to bottom) is what prompted me to use The browser object which seems to be the webdriver instance.

However, running the following code:

dragMock.extendWebdriver(browser);
dragMock.loadLibrary(browser);

..and subsequently:

browser.dragStart('.Something');

Causes a browser.dragStart is not a function crash in the test. Using the before() hook or not, it seems if I only have one test, and it crashes like that, something else is amiss, don't you think?

andywer commented 7 years ago

Ahhh, now we are on the same page.

I fear that more recent webdriver versions have a different API than one and a half years ago when I wrote this... :-/ Maybe it's a minor issue, but currently I haven't got the time to look into that, sorry.

If you are able to make it work, please share it and we can share the knowledge here. If you decide to go for a different tool, let me know, too and I might add it as a possible alternative to the README :)

prewk commented 7 years ago

I see, thank you for your assessment anyways :)

If I come up with something I'll get back to you, I'll leave this issue open, then.

jaqua commented 7 years ago

Could you solve that issue? I have exact the same problem...

prewk commented 7 years ago

Sorry, not yet.

andywer commented 7 years ago

Added a line to the README to at least warn users: https://github.com/andywer/drag-mock#webdriverio-integration