webdriverio-boneyard / wdio-sync

A WebdriverIO v4 plugin. Helper module to run WebdriverIO commands synchronously.
http://v4.webdriver.io
MIT License
17 stars 31 forks source link

make commands chainable #21

Closed christian-bromann closed 8 years ago

christian-bromann commented 8 years ago

Right now we can't chain commands anymore so we end up like this:

browser.url("...");
browser.click(..);
browser.click(..);
browser.click(..);
var title = browser.getTitle()

This can be annoying and unfamiliar. This patch allows to chain commands again. Though it is limited to everything that returns an object (basically all protocol commands). It allows us to do this again:

var title = browser
  .url("...")
  .click("...")
  .getTitle();
christian-bromann commented 8 years ago

Ok need to check why it is failing on Travis. Tests are passing on my machine.

georgecrawford commented 8 years ago

I also have errors, but they're different:

Running "build" task

Running "eslint:target" (eslint) task

Running "clean:0" (clean) task
>> 1 path cleaned.

Running "babel:dist" (babel) task

Running "mocha_istanbul:coverage" (mocha_istanbul) task
Transformation error; return original code
[TypeError: Plugin is not a function]

  wdio-sync
    executeHooksWithArgs
      ✓ should execute all hooks with same parameters (116ms)
      ✓ should respect promises (1010ms)
      ✓ should allow func parameter
Error: buu
    at hookThrows (/Users/george/Sites/Git/wdio-sync/test/wdio-sync.spec.js:48:44)
    at /Users/george/Sites/Git/wdio-sync/build/index.js:145:34
      ✓ should reject if hook throws
    wdioSync
      ✓ should be registered globally
      ✓ should initiate Fiber context

  wrapCommand
    ✓ should return actual results (216ms)
    1) should allow to chain objects
    ✓ should not allow to chain strings, integer or falsy values (109ms)

  8 passing (2s)
  1 failing

  1) wrapCommand should allow to chain objects:
     Uncaught TypeError: instance.getObject(...).getInteger is not a function
      at test/wrapCommand.spec.js:59:34
      at test/wrapCommand.spec.js:31:17

>>
Warning: Task "mocha_istanbul:coverage" failed. Use --force to continue.
$ node --version
v5.1.0
georgecrawford commented 8 years ago

I can see three problems here:

  1. wdioSync spec would cause problems for wrapCommand later unless the Rewire dependency was reset (fixed in https://github.com/webdriverio/wdio-sync/commit/fc7e6c7fe0c544bcdd43e85887d31522029bec15)
  2. executeHooksWithArgs should reject if hook throws causes wrapCommand should allow to chain objects to fail with:
  1) wrapCommand should allow to chain objects:
     Uncaught TypeError: instance.getObject(...).getInteger is not a function
      at test/wrapCommand.spec.js:59:34
      at test/wrapCommand.spec.js:31:17

instance.getObject() is {}, but I can't understand why. (The suite passes if executeHooksWithArgs should reject if hook throws is skipped).

  1. Something's wrong with grunt/istanbul:
$ grunt mocha_istanbul:coverage
Running "mocha_istanbul:coverage" (mocha_istanbul) task
Transformation error; return original code
[TypeError: Plugin is not a function]

(also a problem on Travis).

christian-bromann commented 8 years ago

wdioSync spec would cause problems for wrapCommand later unless the Rewire dependency was reset (fixed in fc7e6c7)

good catch

executeHooksWithArgs should reject if hook throws causes wrapCommand should allow to chain objects to fail with:

it's because we have these globals lying around. Not sure what's the better solution here. We need them across functions.

Something's wrong with grunt/istanbul:

After looking through the internet it seems that adding an .istanbul.yaml fixes the problem. I guess this will resolve itself ones we updated the dependency to use babel v6 but I wasn't able to get this working yet. Dependency management with babel is annoying: everything has to but nothing is compatible with each other :-/

Merging.