Saving a Firefox profile in multiple Selenium tests without specifying a profile

Attempt to achieve:

  • same firefox profile during tests

Problem:

  • Tests are distributed to 30 different files, creating an instance of the selenium object and thus creating a firefox profile, the next test will not be saved in the first test, because the objects die once the script ends with IIRC

  • It is not possible to specify a profile because I am writing a test package that must be run on different machines.

Possible solutions:

  • Creating a selenium object in some common code that remains in memory during tests. I run each test, creating a new python process and waiting for it to complete. I'm not sure how to send objects to memory on a new python object.

Any help is appreciated, thanks.

edit: , , python , , IDE , setUp tearDown 30 , , , .

+5
2

, Firefox .

, Selenium, Firefox, . , Firefox. , . , . Firefox .

:

from selenium.selenium import selenium
import unittest, time, re
import BRConfig

class BRTestCase(unittest.TestCase):
    selenium = None

    @classmethod
    def getSelenium(cls):
        if (None == cls.selenium):
            cls.selenium = selenium("localhost", 4444, "*chrome", BRConfig.WEBROOT)
            cls.selenium.start()
        return cls.selenium

    @classmethod
    def restartSelenium(cls):
        cls.selenium.stop()
        cls.selenium.start()

    @classmethod
    def stopSelenium(cls):
        cls.selenium.stop()

    def setUp(self):
        self.verificationErrors = []
        self.selenium = BRTestCase.getSelenium()

    def tearDown(self):
        self.assertEqual([], self.verificationErrors)

:

import unittest, sys
import BRConfig, BRTestCase

# The following imports are my test cases
import exception_on_signup
import timezone_error_on_checkout
import ...

def suite():
    return unittest.TestSuite((\
        unittest.makeSuite(exception_on_signup.ExceptionOnSignup),
        unittest.makeSuite(timezone_error_on_checkout.TimezoneErrorOnCheckout),
        ...
    ))

if __name__ == "__main__":
    result = unittest.TextTestRunner(verbosity=2).run(suite())
    BRTestCase.BRTestCase.stopSelenium()
    sys.exit(not result.wasSuccessful())

, , Firefox . , , Github, .

, :

from selenium.selenium import selenium
import unittest, time, re
import BRConfig
from BRTestCase import BRTestCase

class Signin(BRTestCase):
    def test_signin(self):
        sel = self.selenium
        sel.open("/signout")
        sel.open("/")
        sel.open("signin")
        sel.type("email", "test@test.com")
        sel.type("password", "test")
        sel.click("//div[@id='signInControl']/form/input[@type='submit']")
        sel.wait_for_page_to_load("30000")
        self.assertEqual(BRConfig.WEBROOT, sel.get_location())

if __name__ == "__main__":
    unittest.main()
+2

firefox .

java -jar selenium-server.jar -firefoxProfileTemplate "C:\Selenium\Profiles", "C:\Selenium\Profiles" , Firefox.

0

All Articles