Is it possible to reuse SST's browser session for direct selenium actions?

Asked by Konstantin

Is it possible to reuse SST's browser session for direct selenium actions?

For example:

from sst.actions import *

from selenium import webdriver

Was planning to use it for WebDriver ActionChains API

Question information

English Edit question
selenium-simple-test Edit question
No assignee Edit question
Solved by:
Corey Goldberg
Last query:
Last reply:
Revision history for this message
Best Corey Goldberg (coreygoldberg) said :

you can do what you proposed, but I'm not sure that is what you need.

doing this:

... will launch a new Firefox instance and new browser and load "someotherwebsite" .
If that's all you need, go for it :)

if you wanted to use the existing SST browser session, you could do:

from sst.actions import browser

... which would give you access to 'browser', which is a webdriver Firefox() instance at run-time.

consider this example:

from sst.actions import *
from sst.actions import browser


... both pageloads will use the same browser session.

does that help?
(have a look at in the SST source to see how/what/when 'browser' is used.)

a better solution (if possible) is to modify SST to be able to handle ActionChains nicely.

please let me know your progress on this. Sounds like an interesting area, and it would be really cool if SST could support things like drag-n-drop.


Revision history for this message
Konstantin (konstantin1979) said :

Thanks Corey Goldberg, that solved my question.

Revision history for this message
Florian Sesser (fs-8) said :

Thanks for above answer Corey!

However I have an issue with the code when running multiple tests with a common library in shared/ that should use the selenium session (to take screen shots).

In tests/shared/
from sst.actions import browser
def take_snap(page):
    browser.get_screenshot_as_file(os.path.join(folder, filename))

In tests/
from sst.actions import *
from sst.actions import browser
import vd

(there are more tests like

Above code works for the first test (file) executed or when SST is called with one specific test as parameter. But I intend to use SST with the -d parameter.

Expected behavior: SST starts a new browser session for every test and use that session to take screen shots

Actual behavior: First test works (and creates screen shots); Later tests will not work but throw a "URLError: <urlopen error [Errno 111] Connection refused>", maybe (guessing here) because they will not use the current (new) browser object, but the old one.

Probably I am misunderstanding some generic python concept or have created circular dependency or so, but ATM I am clueless why sst/, when updating the "global browser", the change won't reach my tests/shared/

Revision history for this message
Corey Goldberg (coreygoldberg) said :

Florian. why not use SST's 'take_screenshot()' action ?

Revision history for this message
Florian Sesser (fs-8) said :

Because it doesn't give us enough freedom on naming files/directories. Our "vd.take_snap()" method should take one argument (a snapshot name) and then create a directory with that name and save the screenshot as <pagename>/<BUILD_NUMBER>.png. We'd also like SST to not clear that directory at the next test run. This should give us a nice stop-motion movie over the lifetime of our project :)

Several workarounds are of course possible, like moving/renaming the files with shell scripts as a post-build action. But that's not as chique, and I'd like to understand what's the issue here.

We have another kind of workaround in place now: We changed the signature of take_snap(page) to take_snap(page, browser). The second argument takes the browser instance from the different tests. This made this work for us; Alas, I don't know why. Shouldn't the "global browser" update in also reach the helpers in our "shared" directory?

Revision history for this message
RĂ³bert Malovec (malovec) said :

I can't import "browser". Am I doing something wrong?
I have shared module called, its 1st line is:
from sst.actions import browser

importing * from sst.actions works fine.

When I run the test I am getting this error:

from sst.actions import browser
ImportError: cannot import name browser

$ sst-run -V
SST version: 0.2.4

Revision history for this message
Vincent Ladeuil (vila) said :

@malovec: Don't hijack questions please, this makes it harder to properly track them. There is no 'browser' symbol in the sst.actions module, there is a sst.browsers module and a *private* sst.actions._test_browser but since the later is private, you're not supposed to use it as there is no guarantee that it will remain available in future sst versions.