mojotech / pioneer

Integration Testing
MIT License
527 stars 35 forks source link

Allow to query the DOM with static methods. #298

Open bitplanets opened 9 years ago

bitplanets commented 9 years ago

Sometimes I don't want to create a Widget instance and I have only one class.

samccone commented 9 years ago

Can you provide an example with what you are looking to be able to do?

bitplanets commented 9 years ago
        this.Widget.findAll({
          selector: "." + value
        }).then(function(value){
        })

I want to count the number of items with that class.

bitplanets commented 9 years ago

For example

this.Widget.find({
  selector: "." + value
}).then(function(items){
    console.log(items);
    // console.log(items.length);
})

This works but I get this error

C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:1643
      throw error;
            ^
TypeError: Cannot call method 'isDisplayed' of undefined
    at Widget.W.Widget.Widget.isPresent (C:\t\node_modules\pioneer\lib\support\widgets.js:205:26)
    at webdriver.promise.ControlFlow.runInNewFrame_ (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:1539:20)
    at pollCondition (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:1305:12)
    at C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:1301:5
    at webdriver.promise.ControlFlow.runInNewFrame_ (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:1539:20)
    at webdriver.promise.ControlFlow.runEventLoop_ (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:1404:8)
    at wrapper [as _onTimeout] (timers.js:261:14)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
==== async task ====
undefined not found
    at webdriver.promise.ControlFlow.wait (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:1296:15)
    at webdriver.WebDriver.wait (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:543:21)
    at Widget.W.Widget.Widget._ensureElement (C:\t\node_modules\pioneer\lib\support\widgets.js:305:28)
    at Widget.W.Widget.Widget.find (C:\t\node_modules\pioneer\lib\support\widgets.js:159:21)
    at Function.W.Widget.Widget.find (C:\t\node_modules\pioneer\lib\support\widgets.js:45:22)
    at Object.<anonymous> (C:\t\tests\steps\missions.js:22:25)
    at C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\goog\base.js:1243:15
    at webdriver.promise.ControlFlow.runInNewFrame_ (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:1539:20)
    at notify (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:362:12)
    at notifyAll (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:331:7)
    at resolve (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:309:7)
    at fulfill (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:429:5)
    at Object.webdriver.promise.asap (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:671:5)
    at webdriver.promise.ControlFlow.runInNewFrame_ (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:1550:25)
    at notify (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:362:12)
    at notifyAll (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:331:7)
    at resolve (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:309:7)
    at fulfill (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:429:5)
    at C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:1406:10
    at C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\goog\base.js:1243:15
    at webdriver.promise.ControlFlow.runInNewFrame_ (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:1539:20)
    at notify (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:362:12)
    at notifyAll (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:331:7)
    at resolve (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:309:7)
    at fulfill (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:429:5)
    at C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\goog\base.js:1243:15
    at webdriver.promise.ControlFlow.runInNewFrame_ (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:1539:20)
    at notify (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:362:12)
    at notifyAll (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:331:7)
    at resolve (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:309:7)
    at fulfill (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:429:5)
    at C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\promise.js:617:49
    at C:\t\node_modules\pioneer\node_modules\selenium-webdriver\lib\webdriver\http\http.js:96:5
    at IncomingMessage.<anonymous> (C:\t\node_modules\pioneer\node_modules\selenium-webdriver\http\index.js:122:7)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:943:16
    at process._tickCallback (node.js:419:13)
samccone commented 9 years ago

yep makes sense, currently everything is scoped to a widget operation

bitplanets commented 9 years ago

Also remember to make the error more descriptive, in this case you wouldn't even know where to start. Also why this error?

samccone commented 9 years ago

@bitplanets open to PR's to improve the error messages

The error message is because there is no el on the static widget https://github.com/mojotech/pioneer/blob/master/src/widgets/Widget.coffee#L136