简体   繁体   English

Ruby watir 页面对象实现

[英]Ruby watir page object implementation

Trying to add a variable with webelement to a method, then use this method with .click尝试将带有webelement的变量添加到方法中,然后将此方法与.click

def login_button
@browser.element(:class => /button radius button-demo/)
  end

login_button.click 

But, keep getting the same error:但是,不断收到相同的错误:

undefined local variable or method `login_button' for PageObjects:Class (NameError) PageObjects:Class (NameError) 的未定义局部变量或方法“login_button”

but if you do this way:但如果你这样做:

 @browser.element(:class => /button radius button-demo/).click

without adding it to a method, everything works fine.不将其添加到方法中,一切正常。

Official Watir guide provides option with adding variable to a method, but for somereason I can't make it work :(官方 Watir 指南提供了向方法添加变量的选项,但由于某种原因我无法使其工作:(

Here is the simple code snippet using cheezy page object.这是使用俗气的页面对象的简单代码片段。

require 'page-object'
class Login_Page
   include PageObject
   text_field(:user_name, css: "[name='username']")
   text_field(:password, css: "[name='password']")
   button(:sign_in, css: "button[type='submit']")

   def click_on_sign_in
       sign_in # default method is click for button element
       # if you want to call click method
       sign_in.wait_until(100, &:present?).click
       # clicking using fire event
       sign_in.wait_until(100, &:present?).fire_event :onclick
   end
end

Refer to cheezy documentation for more information.有关更多信息,请参阅cheezy 文档

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

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