Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # submitForm Function demo
- This file demonstrates the use of auto submitting form data.
- To demonstrate this, we need to write a program that
- * use the [webdriverio](http://webdriver.io)
- * instantiates [webdriverio](http://webdriver.io) and pass in the [option](#) parameters.
- * initialize [webdriverio](http://webdriver.io) test browser
- * navigate to www.facebook.com (for Example)
- * write `myEmail@email.com` to the email field
- * write `1234567890` to the password field
- * submit the form
- * print "Submit complete" when submit success
- ## Coding
- First we require `webdriverio`
- ```
- webdriverio = require 'webdriverio'
- ```
- Then we instantiate and pass options.
- ```
- options =
- desiredCapabilities:
- browserName: 'chrome'
- sync: true
- browser = webdriverio.remote options
- ```
- next we initialize webdriverio
- ```
- browser
- .init()
- ```
- next, navigate to [`https://www.facebook.com`](https://www.facebook.com)
- ```
- .url 'https://www.facebook.com/'
- ```
- Next we we write `myEmail@email.com` to the email field
- ```
- .setValue('input[name=email]', 'myEmail@email.com').then ->
- browser
- .pause 1000
- ```
- Next we write `1234567890` to the password field.
- ```
- .setValue('input[name=pass]', '1234567890').then ->
- ```
- Next we `submit` the form.
- ```
- browser.submitForm('form#login_form').then ->
- console.log 'Submit complete'
- ```
- Then we pause for 1 second and observe then end the test.
- ```
- .pause 1000
- .end
- ```
- Don't forget to add return statement, in coffeescript all function requires the return statement.
- The enite codebase looks like:
- ```
- 'use strict'
- webdriverio = require 'webdriverio'
- options =
- desiredCapabilities:
- browserName: 'chrome'
- sync: true
- browser = webdriverio.remote(options)
- browser
- .init()
- .url 'http://www.facebook.com'
- .setValue('input[name=email]', 'myEmail@email.com').then ->
- browser
- .pause(1000)
- .setValue('input[name=pass]', '1234567890').then ->
- browser.submitForm('form#login_form').then ->
- console.log 'Submit complete'
- return
- return
- return
- .pause 1000
- .end
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement