嗨我有一个让我发疯的问题,当我的代码符合时我收到了错误
uninitialized constant BaseHelper (NameError)
我的代码一直工作得很好,直到我添加了另一个子类(AccessoriesMerchandise) 我的课程看起来像这样
BaseHelper类:
class BaseHelper
def find(locator)
@browser.find_element locator
end
def type(locator, input)
find(locator).send_keys input
end
end
儿童班:
class FindADealerPage < BaseHelper
#PageObjects
FIND_A_DEALER_SEARCH_FIELD = {id: "abcd"}
MAP_TAB = {css: 'abcd abcd abcd'}
SERVICE_CHECK_BOX = {class: "abcd"}
SUBMIT_SEARCH = {class: "abcd"}
DEALER_RESULTS_FIRST_DEALER = {css: "abcd"}
def initialize(browser, wait)
@browser = browser
@wait = wait
end
def go_to_find_a_dealer_page
@browser.get $base_url
end
end
他们都坐在同一个文件夹中!我在课程中添加了我的问题。
class AccessoriesMerchandise < BaseHelper
#PageObjects
ACCESSORIES_ACCORDION = {css: 'div.mesSpecAccordion.accessoriesAccordion'}
PANEL_CLOSED = {css: 'h2.trigger'}
PANEL_OPENED_ACTIVE = {css: 'h2.trigger.active'}
def initialize(browser, wait)
@browser = browser
@wait = wait
end
def go_to_page
@browser.get $base_url
end
end
此课程也位于同一个文件夹中。 我正在使用的框架是Ruby Selenium WebDriver,Cucumber和Rspec Expectations
答案 0 :(得分:2)
您需要require
它应该是[如你所说的两个都在同一个文件夹中]
require 'base_helper.rb'
class FindADealerPage < BaseHelper
#PageObjects
FIND_A_DEALER_SEARCH_FIELD = {id: "abcd"}
MAP_TAB = {css: 'abcd abcd abcd'}
SERVICE_CHECK_BOX = {class: "abcd"}
SUBMIT_SEARCH = {class: "abcd"}
DEALER_RESULTS_FIRST_DEALER = {css: "abcd"}
def initialize(browser, wait)
@browser = browser
@wait = wait
end
...
end