Functional testing an addon

I’m developing a WebExtension for Firefox and Chrome and want to perform functional testing of this add-on. Questions about this seem to have been asked here before, but unfortunately I can’t find the answer on a specific issue: how to interact with the extension popup?

I’m following the setup provided by https://github.com/Standard8/example-webextension/. Using driver.setContext(CHROME) I can click on the button and I can see the popup being opened, however I can’t find a way to actually interact with it. I’ve tried various switchTo commands, but the popup does not seem to exist in any context, handle or frame.

1 Like

It seems I was a bit too optimistic about being able to click on the button and have the popup to open. Somehow this only works when using the selenium/firefox-standalone-debug container. After switching to the normal selenium/firefox-standalone container I see the following error in the docker logs:

JavaScript error: chrome://marionette/content/driver.js, line 601: TypeError: be.getTabBrowser is not a function

I don’t know why this error does not occur when using the debug container, but it does prevent the popup from being opened and it seems to be related to interaction with this popup.

I know that the point of testing with selenium is to test in a realistic environment, but using the panel seems quite painful if selenium / the Firefox driver does’t support it. Do you really need the panel?

Opening a popup with a script that closes it on window.onblur could, depending on your use of the panel, work too and should be better supported.

Our extension is part of a password management solution. The popup contains the majority of the interactive elements. So far, I’ve managed to test the auto-fill, provided by a content script, but for the more complex interactions, I do need access to the popup. Note that this is not a popup in the form of window.open(...). It’s what’s called default_popup in manifest.json under browser_action (see this page on MDN).

I’m using selenium with the geckodriver, because that’s what is recommended by other threads on this forum. It seems odd that if this approach is the recommended way, that it’s not possible to interact with the popup at all.

For functional/integration testing selenium is certainly the only way. However you may want to think about at least testing the popup when the page is opened in a tab, which changes a few things, but should still let you test some of the page’s behavior in Firefox.

There is no definitive recommended way of testing your extension, but generally writing unit tests is currently simpler than integration tests.

So you are suggesting to open the popup in a normal tab via the moz-extension://7c2ca2d6-.../index.html url and test this via selenium? It seems the extension functions fine this way, so I guess this is doable. What are the differences I have to take into account? The WebExtensions API is available and messaging also works.

Mainly opening and closing (closing is much less graceful than in tabs, especially with beforeunload etc.) is different and what happens when user focus changes (popups close, tabs don’t).

Ok, that shouldn’t be a problem and the interaction via the chrome context has similar problems. For example, the extension popup stays open even after navigating to a new page when using selenium. I didn’t even find a reliable way to close it from the outside. At the moment all my tests run with the popup open all the time :slight_smile:

Thanks for the help so far