मैं इस समस्या में भाग गया और यह भी ध्यान दिया कि परीक्षणों में एक एकल फ़ायरफ़ॉक्स सत्र जारी रखने से टेस्ट सूट के प्रदर्शन में काफी वृद्धि हुई।
मैंने अपने सेलेनियम परीक्षणों के लिए बेस क्लास बनाने के लिए क्या किया था जो केवल फ़ायरफ़ॉक्स को सक्रिय करेगा अगर यह पहले से शुरू नहीं हुआ था। आंसू के दौरान, यह वर्ग फ़ायरफ़ॉक्स को बंद नहीं करता है। फिर, मैंने एक अलग फ़ाइल में एक परीक्षण सूट बनाया जो मेरे सभी परीक्षणों को आयात करता है। जब मैं अपने सभी परीक्षणों को एक साथ चलाने के लिए चाहता हूं, तो मैं केवल परीक्षण सूट निष्पादित करता हूं। परीक्षण सूट के अंत में, फ़ायरफ़ॉक्स स्वचालित रूप से बंद हो जाता है।
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())
एक नुकसान यह है कि आप बस कमांड लाइन से एक भी परीक्षण चलाने यदि फ़ायरफ़ॉक्स स्वचालित रूप से बंद नहीं होगा। मैं आमतौर पर गिटूब को अपना कोड धक्का देने के हिस्से के रूप में एक साथ अपने सभी परीक्षण चलाता हूं, इसलिए, इसे ठीक करने के लिए मेरे लिए यह एक बड़ी प्राथमिकता नहीं है।
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", "[email protected]")
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()
:
यहां एक परीक्षण है कि इस प्रणाली में काम करता है का एक उदाहरण है