yaml file:
items:
- user: user
pwd: pwd
- user: user1
pwd: pwd1
watir code:
conf = YAML::load_file("**.yaml')
items = conf["items"]
items.each do |item|
ie.text_field(:id,"user").set(item["user"])
end
please have a try and leave message here
On Apr 16, 2:05 am, sonny wrote:
> I'm still learning Ruby/Watir. I have a test suite that will
> successfully run. I now want to move the variables into a yaml file.
> My question is how do I get my script to use the data in the yaml
> file? I've done a lot of searching and trial and error, but can't
> figure it out. I should have a YAML::load statement, but I can't get
> the syntax right.
>
> Here's a simple example:
>
> - my_methods.rb -
> def open_url(page_url)
> $ie = Watir::IE.start(page_url)
> end
>
> def enter_username(user_name)
> $ie.text_field(:name, 'username').set(user_name)
> end
>
> def enter_password(password)
> $ie.text_field(:name, 'password').set(password)
> end
>
> def click_sign_in
> $ie.button(:value,/Login/).click
> end
>
> def logout
> $ie.link(:text, 'SignOut').click
> $ie.link(:text, 'login page').click
> end
>
> def try_again
> $ie.link(:text, 'please try again.').click
> end
>
> -- the_data.yaml -
>
> test: test_01_valid_login
> user:cows4yaml
> pwd:c0w...@ml
> ---
> test: test_02_invalid_password
> user:cows4yaml
> pwd: cowscows
> ---
> test: test_03_invalid_user
> user:cowsforyaml
> pwd:c0w...@ml
> ---
>
> -- my_test_script.rb -
> require 'watir'
> require 'test/unit'
> require 'watir/assertions'
> require 'watir/testcase'
> require 'yaml'
> require 'my_methods'
>
> class TC_login_tests < Watir::TestCase
> #open browser
> open_url("http://gawab.com";)
>
>
> # here would be code to tell the script that the test data is in
> # the_data.yaml file
>
>
> def test_01_valid_login
> enter_username(user)
> enter_password(pwd)
> click_sign_in
> verify($ie.html.include?('Messages Summary') ,message='Not the
> main page')
> logout
> end
>
> def test_02_invalid_pwd
> enter_username(user)
> enter_password(pwd)
> click_sign_in
> verify($ie.html.include?('Sorry. Your password is
> incorrect') ,message='Not Invalid Password page')
> try_again
> end
>
> def test_03_invalid_username
> enter_username(user)
> enter_password(pwd)
> click_sign_in
> verify($ie.html.include?('Sorry. Your password is
> incorrect') ,message='Not Invalid Password page')
> try_again
> end
> end #class TC_login_tests
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Watir General" group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines:
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/watir-general
-~--~~~~--~~--~--~---