5

I am setting up Selenium testing for Safari 5 on Mac. I need to install our Safari extension before hand, and it needs to happen silently and without any user prompting. From previous posts, I've found this works in that it loads the browser with the extension:

open -a Safari okta.safariextz

But it leaves the browser opened with a prompt to the user: "Are you sure you want to install the extension?"

Selenium doesn't have access to this prompt and can't click install. I need to configure Safari such that it does not prompt the user to install, but just allows the extension to be installed.

Is there any way to do this?

Any pointers appreciated.

-Denali

Denali Lumma
  • 319
  • 6
  • 14

2 Answers2

2

Edit: Possible new method: The answer here might suggest (it's somewhat unclear) that, with a possible risk of messing up your future safari upgrades, you might be able to manually install an extension, skipping the confirmation prompt, via a file move and a plist hack. I haven't tried it, but it looks as if it might work:

If you're just doing this for in-house deployment and don't mind if it breaks on a Safari upgrade, then you can quit Safari, install the extension into ~/Library/Safari/Extensions and update ~/Library/Safari/Extensions/Extensions.plist (the format is rather obvious; /usr/libexec/PlistBuddy is useful for such things).

You can't do what you're after--at least, not with any commandline switch or plist hack that I know of. Extension install confirmation is a core part of Safari's security model, and is not easily circumvented.

Instead, I'd consider using automator (if you're not familiar with it, think Selenium but for desktop apps, and more) to send a click on the appropriate button, and then distributing an automator app that launches safari with the appropriate parameters, sends the click when the extension dialog appears, and then goes on to run Selenium-based (rather than automator-based) automations. To get started, I'd check out the following links: Automating via applescript rather than the "duplo legos" automation builder: http://www.mactech.com/articles/mactech/Vol.21/21.06/UserInterfaceScripting/index.html Very brief overview of macro recording (you hit record, send the click you want, hit save, and you can re-execute your recorded actions): http://automator.us/leopard/features/virtual-user.html My favorite intro to automator tutorial: http://cjrtools.org/mac/tutorials/autohowto.html

Community
  • 1
  • 1
Zac B
  • 3,796
  • 3
  • 35
  • 52
  • Thanks, I'll check those out. I understand this would be a security hole if you could control it from the same command line program you are using to install the extension, but what about if you have control over the OS and the browser, as I do? It seems like there should be some way of configuring the browser for testing purposes. – Denali Lumma Apr 02 '12 at 18:22
  • There's still no easy way that I know of. Needing to launch, install extensions, and run selenium tests in one go is something of a small niche, and not, I'd imagine, something that the Safari developers consider a worthwhile cause for opening a significant security hole. The – Zac B Apr 02 '12 at 19:43
  • Oops, there might be another method, but I haven't tested it. Editing my answer; try it out. – Zac B Apr 02 '12 at 19:43
0

I don't believe there is any way to do a silent extension install as it would be a security hole. You may want to try incorporating an AppleScript to do the extension install before running your Selenium tests.

Here is another question on StackOverflow with AppleScript details for Safari extension reloading that can be used for your purposes:

How to reload a Safari Extension from the command line?

Community
  • 1
  • 1
kenki
  • 538
  • 3
  • 4