angularjs - Protractor returning a value from a promise -


i'm writing test see if code removing level looking @ text value on screen holds count of levels.

  'allows deleting level versions', ->     browser.get('/api#/costings')     element(by.id("edit")).click()     startcount = element(by.id("versions_count")).gettext().then( (count) ->       return count     )      element(by.id("versions")).click()     first=element.all(by.id("listing")).first()     first.element(by.id("delete")).click()     helper.accept_dialog()      element(by.id("back")).click()     expect(element(by.id("versions_count")).gettext()).toequal(startcount - 1) 

problem here startcount results in function. cannot seem startcount integer can see if count has gone down 1 item.

it gives me error;

  1) edit existing costing allows deleting level versions    message:      expected '1' equal nan. 

if try parseint(startcount) same error.

the variable startcount promise, , startcount - 1 doesn't make sense: there no automatic type conversion promise resolved value, can't subtract 1 it.

what can do, create promise resolved value expected versions count:

expectedcount = element(by.id("versions_count")).gettext().then( (count) ->   return (count - 1).tostring(); ) 

and can pass promise toequal, automatically unwraps promises @ appropriate point in control flow

expect(element(by.id("versions_count")).gettext()).toequal(expectedcount) 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -