【发布时间】:2016-04-05 21:46:02
【问题描述】:
我正在使用 Ruby 2.3.0 编写葫芦测试,但我无法从模块中调用黄瓜方法。
module A
module_function
def visible
wait_for_elements_exist("Some element query")
end
end
还有:
Class B
include A
end
当我调用B.visible 或在B 中定义时:
def visible
A::visible
end
然后调用B.visible,我得到NoMethodError,表示模块A中的wait_for_elements_exist。
我尝试在模块中使用require 'calabash-cucumber/cucumber',在模块中使用include Calabash::Cucumber。没用。
我可以从项目中的其他类访问所有黄瓜方法,并且我在 env.rb 中需要黄瓜,因此已加载库。我想知道如何从模块中访问库函数,或者如何正确地将内容包含到我的模块中。
编辑
我试过include Calabash::Cucumber::WaitHelpers
还有include Calabash::Cucumber::Operations
没有用。我用extend替换了include,现在我可以访问这些方法了,但这并不能解决我的问题。
我需要的是
AndroidModule < Calabash::Android::Operations
IosModule < Calabash::Cucumber::Operations
在这些模块中,我定义了平台之间不同的方法。
然后有ScreenModule 用于各种屏幕,我在其中定义特定于屏幕的方法,并且根据我启动的测试,我需要ScreenModule 来包含平台模块之一。
我需要从ScreenModule 访问::Operations,但它找不到任何这些方法。
我不知道为什么我不能使用wait_for_elements_exist,即使我已经包含了::Operations moudle
【问题讨论】: