简体   繁体   中英

Calling a Method - Watir-Webdriver

I am new to automation and I have started using Watir Webdriver to automate a website. However, there are certain pieces of code which can be reused for multiple test cases. How can I group the reusable pieces of code into a method which I can call in every test case ? Could you please provide references or examples ?

You are interested in methods.

Here is an example:

def automation_snippet
  @browser.text_field(:id => 'field_id').set 'foo'
end

Later you will probably be interested in classes, page objects, and modules.

This is basic ruby stuff. You will need to make sure that whatever method you want to use is in scope, too.

So, keywords to start with are methods and scope. If you are using Cucumber, then you can define methods in any step definition file and they will be available in all your other Cucumber tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM