node.js - Running blocks of code synchronously in NodeJS/Selenium/Mocha -


i'm doing automated testing in nodejs/selenium/mocha , having lots of trouble getting things execute correctly.

the following code block tests webpage clicking button , checking if corresponding counter goes 0 1.

    it('votes item when user clicks button', function(done) {      driver.findelements(by.classname('list-group-item list-group-item-action'))         .then(function(buttons) {             driver.findelements(by.classname('vote-count'))                 .then(function(counts) {                      var flag = true                      counts[0].gettext().then(function(text) {                         console.log('test')                         if (text != '0') flag = false                     })                       buttons[0].click()                       counts[0].gettext().then(function(text) {                         if (text != '1') flag = false                     })                      expect(flag).to.equal(true)                     done()                  })         })  }) 

i have log statement in there 'should' print 'test' when particular block gets called, never prints because block never gets executed. mocha moves on , finishes test before happens.

even if page doesn't work, tester doesn't opportunity set flag false, test passes if shouldn't.

how can here execute in series, 1 statement after another? tried use async.series didn't seem work me either. plus, seems incredibly messy code simple..


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -