Guest User

Untitled

a guest
Sep 2nd, 2016
320
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. TLO::login = (username, password) ->
  2.   console.log chalk.bgYellow('TLO.login(...)')
  3.   a = this
  4.   return new Promise (resolve, reject) ->
  5.     if !a.browser.isExisting '#form_login'
  6.       reject {
  7.         error: true
  8.         message: 'Login Failed'
  9.       } # failed to login
  10.     else
  11.       a.cache.user = username
  12.  
  13.       console.log chalk.yellow('Redirecting To Login Page')
  14.       a.browser.url(a.endpoints.login)
  15.  
  16.       chain = a.browser.setValue('#username', username).then () ->
  17.         console.log chalk.blue('Login Username Specified')
  18.       .getValue('#username').then (value) ->
  19.         console.log chalk.cyan('Username Verified As: ', value)
  20.  
  21.       .setValue('#password', password).then () ->
  22.         console.log chalk.blue('Login Password Specified')
  23.       .getValue('#password').then (value) ->
  24.         console.log chalk.cyan('Password Verified As: ', value)
  25.  
  26.       .click('input.button.btnss').then () ->
  27.         console.log chalk.yellow('Login Processed')
  28.           # form submit not working, click had to be used
  29.       .getTitle().then (title) ->
  30.         console.log chalk.yellow('Redirected To: ', title)
  31.  
  32.       .waitForVisible('#versionInfo', 1500).then () ->
  33.         a.cache.loggedIn = true
  34.       .getText('#versionInfo').then (text) ->
  35.         a.version = text
  36.         console.log chalk.green text
  37.  
  38.       .catch (error) ->
  39.         console.log chalk.bgRed(error) # error encountered in promise chain
  40.  
  41. ---------------------------------------------------------------------------------------------------------------------------------------
  42.  
  43. tlo = new TLO beta
  44. tlo.login('jnolette', 'test')
  45.   .then (result) ->
  46.     if ( result && !result.error )
  47.       console.log chalk.green(result.message)
  48.     else if ( result && result.error )
  49.         console.log chalk.red(result.message) # error encountered was expected
  50.     else
  51.       console.log chalk.bgRed('Unhandeled Error Has Occured #001') # codepath error #001
  52.  
  53. .catch (error) ->
  54.   console.log chalk.bgRed(error) # error encountered in promise
RAW Paste Data