简体   繁体   English

调用方法-Watir-Webdriver

[英]Calling a Method - Watir-Webdriver

I am new to automation and I have started using Watir Webdriver to automate a website. 我是自动化的新手,我已经开始使用Watir Webdriver来自动化网站。 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. 如果使用的是Cucumber,则可以在任何步骤定义文件中定义方法,这些方法将在所有其他Cucumber测试中可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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