Ruby beginner trying to call a method from another class in Ruby? -
i trying below working. not sure failing. receive following error:
1) error:
test_google(google): nomethoderror: undefined method `new' method:class google.rb:15:in `setup'
i new ruby, pretty 101. can explain me errors , why can understand. thanks!
require "test/unit" require "selenium-webdriver" require "json" require "time" require_relative "methods" class google < test::unit::testcase def setup @driver = selenium::webdriver.for :firefox @base_url = "https://www.google.com/" @accept_next_alert = true @driver.manage.timeouts.implicit_wait = 30 @verification_errors = [] @search = method.new() end def teardown @driver.quit assert_equal [], @verification_errors end def test_google @driver.get(@base_url + "/") @search.search end end class method def search @driver.find_element(:id, "gbqfq").clear @driver.find_element(:id, "gbqfq").send_keys "this test" @driver.find_element(:id, "gbqfb").click @driver.find_element(:id, "gbqfb").click end end
i changed class name:
require "test/unit" require "selenium-webdriver" require "json" require "time" class google < test::unit::testcase def setup @driver = selenium::webdriver.for :firefox @base_url = "https://www.google.com/" @accept_next_alert = true @driver.manage.timeouts.implicit_wait = 30 @verification_errors = [] @search = suber.new() end def teardown @driver.quit assert_equal [], @verification_errors end def test_google @driver.get(@base_url + "/") @search.search end end class suber def search @driver.find_element(:id, "gbqfq").clear @driver.find_element(:id, "gbqfq").send_keys "this test" @driver.find_element(:id, "gbqfb").click @driver.find_element(:id, "gbqfb").click end end
now not sure how tackle setting @driver within 'suber' class. assumed work, throws:
nomethoderror: undefined method find_element' nil:nilclass google.rb:37:in
search' google.rb:25:in `test_google'
: /
as per edit below:
require "test/unit" require "selenium-webdriver" require "json" require "time" module suber def search @driver.find_element(:id, "gbqfq").clear @driver.find_element(:id, "gbqfq").send_keys "this test" @driver.find_element(:id, "gbqfb").click @driver.find_element(:id, "gbqfb").click end end class google < test::unit::testcase include suber def setup @driver = selenium::webdriver.for :firefox @base_url = "https://www.google.com/" @accept_next_alert = true @driver.manage.timeouts.implicit_wait = 30 @verification_errors = [] #@search = suber.new() end def teardown @driver.quit assert_equal [], @verification_errors end def test_google @driver.get(@base_url + "/") search end end
Comments
Post a Comment