Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
681 views
in Technique[技术] by (71.8m points)

ruby - Chrome 62 and Flash

I have a Flash-based app that I need to test using Cucumber. As flash is not enabled by default I need to enable it before each test and whitelist the url I believe. If I pause the test in it's background phase I can manually set these options.

flash option

How can I automate this approach though, I have looked into adding options and preferences, but still cannot seem to get to work.

So this is my standard setup in an env.rb file

Capybara.register_driver :chrome do |app|
  chrome_binary = '/Applications/Google Chrome.app'
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => { "binary" => chrome_binary + '/Contents/MacOS/Google Chrome' })
  Capybara::Selenium::Driver.new(app, :browser => :chrome, :desired_capabilities => capabilities, :options => options)
end

Further reading has highlighted options such as

options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('arg-here')
prefs = {"enable flash here ? "}
options.add_experimental_option("prefs", prefs)

The add_experimental_option throws undefined method add_experimental_option for #<Selenium::WebDriver::Chrome::Options:0x007fca30c10988>

Has anyone automated this process?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To enable Flash before each test and WhiteList the url you can use the following code block to configure the WebDriver instance to allow Flash:

ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.plugins", 1);
prefs.put("profile.content_settings.plugin_whitelist.adobe-flash-player", 1);
prefs.put("profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player", 1);
prefs.put("PluginsAllowedForUrls", "https://your_url.com");
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);

Here you can find a detailed discussion on Manage Flash in Chrome and on PluginsAllowedForUrls

Update :

You haven't mentioned in your comment through which client you are not able to find setExperimentalOption or set_experimental_option. Here is the snapshot from my IDE which have no errors/warnings :

flash

And here is the JavaDoc :

setExperimentalOption


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...