【发布时间】:2017-06-30 06:12:36
【问题描述】:
我想为硒红宝石制作猴子补丁。
这是我关注的article。
但是,当我定义自己的代码时:
module Selenium
module WebDriver
module Driver
module CookieManagement
# This is the same as Driver.get, but I just want it to save all the domains it goes to in an easily accessible variable
def get_and_save(url)
puts "You've asked me to get, so I am getting"
get(url)
end
end
end
end
end
我收到一个错误:
Uncaught exception: Driver is not a module
我知道发生这种情况是因为我已经定义了一个 Driver 类,所以没关系。但是,文章中的这个家伙怎么不会发生这种情况,更重要的是,那么可接受的解决方法是什么?
更新
我想我不包括我确实包含导致上述错误的代码行是不好的。
Selenium::WebDriver::Driver.include Selenium::WebDriver::Driver::CookieManagement
而且,它是纯红宝石。 不涉及轨道。
【问题讨论】:
-
“驱动程序不是一个模块”——它是一个类,见the source
-
@wiesion 是的,我可以看到,正如我上面所说的。因此,我的问题。这家伙做了完全相同的事情并写了一篇关于它的文章。它对他有用,我不明白为什么。
-
文章提到你应该在自定义文件和
{Target}.include(寻找评论# Actually monkey-patch DateTime)中组织你的Monkey补丁。这是他唯一一次提到它,但这是一个要求。 -
在您的情况下,您应该将猴子补丁放在
/lib/core_extensions/selenium/web_driver/driver/cookie_management.rb和初始化程序中(确保此时已加载 Selenium)在目标类/模块上执行包含。您也可以查看this post -
你说的“为什么文章里的那个家伙没有发生”是什么意思?他在文章的什么地方定义了
Selenium::WebDriver::Driver模块?
标签: ruby