Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. # submitForm Function demo
  2.  
  3. This file demonstrates the use of auto submitting form data.
  4.  
  5. To demonstrate this, we need to write a program that
  6. * use the [webdriverio](http://webdriver.io)
  7. * instantiates [webdriverio](http://webdriver.io) and pass in the [option](#) parameters.
  8. * initialize [webdriverio](http://webdriver.io) test browser
  9. * navigate to www.facebook.com (for Example)
  10. * write `myEmail@email.com` to the email field
  11. * write `1234567890` to the password field
  12. * submit the form
  13. * print "Submit complete" when submit success
  14.  
  15. ## Coding
  16. First we require `webdriverio`
  17. ```
  18. webdriverio = require 'webdriverio'
  19. ```
  20. Then we instantiate and pass options.
  21. ```
  22. options =
  23. desiredCapabilities:
  24. browserName: 'chrome'
  25. sync: true
  26. browser = webdriverio.remote options
  27. ```
  28. next we initialize webdriverio
  29. ```
  30. browser
  31. .init()
  32.  
  33. ```
  34. next, navigate to [`https://www.facebook.com`](https://www.facebook.com)
  35. ```
  36. .url 'https://www.facebook.com/'
  37. ```
  38. Next we we write `myEmail@email.com` to the email field
  39. ```
  40. .setValue('input[name=email]', 'myEmail@email.com').then ->
  41. browser
  42. .pause 1000
  43. ```
  44. Next we write `1234567890` to the password field.
  45. ```
  46. .setValue('input[name=pass]', '1234567890').then ->
  47. ```
  48. Next we `submit` the form.
  49. ```
  50. browser.submitForm('form#login_form').then ->
  51. console.log 'Submit complete'
  52. ```
  53. Then we pause for 1 second and observe then end the test.
  54. ```
  55. .pause 1000
  56. .end
  57. ```
  58.  
  59. Don't forget to add return statement, in coffeescript all function requires the return statement.
  60.  
  61. The enite codebase looks like:
  62. ```
  63. 'use strict'
  64. webdriverio = require 'webdriverio'
  65. options =
  66. desiredCapabilities:
  67. browserName: 'chrome'
  68. sync: true
  69. browser = webdriverio.remote(options)
  70. browser
  71. .init()
  72. .url 'http://www.facebook.com'
  73. .setValue('input[name=email]', 'myEmail@email.com').then ->
  74. browser
  75. .pause(1000)
  76. .setValue('input[name=pass]', '1234567890').then ->
  77. browser.submitForm('form#login_form').then ->
  78. console.log 'Submit complete'
  79. return
  80. return
  81. return
  82. .pause 1000
  83. .end
  84.  
  85. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement