Skip to content

Commit 701985e

Browse files
committed
Gadgets/Stdrev: Use single browser instance for all tests
1 parent 5b0b58f commit 701985e

12 files changed

Lines changed: 30 additions & 164 deletions
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
2727

28-
class LoginHtml(unittest.TestCase):
29-
def setUp(self):
30-
self.driver = webdriver.Firefox()
31-
self.driver.implicitly_wait(30)
28+
class CppTestCase(unittest.TestCase):
29+
@classmethod
30+
def setUpClass(self):
3231
self.base_url = "http://en.cppreference.com/"
33-
self.verificationErrors = []
3432

35-
def test_login_html(self):
36-
driver = self.driver
33+
driver = webdriver.Firefox()
34+
driver.implicitly_wait(30)
3735
driver.get(self.base_url + "/mwiki/index.php?title=Special:UserLogout&returnto=Main+Page")
3836
driver.find_element_by_link_text("Log in").click()
3937
driver.find_element_by_id("wpName1").clear()
@@ -42,10 +40,9 @@ def test_login_html(self):
4240
driver.find_element_by_id("wpPassword1").send_keys("test4")
4341
driver.find_element_by_id("wpLoginAttempt").click()
4442
self.assertEqual("Test5", driver.find_element_by_link_text("Test5").text)
43+
self.driver = driver
4544

46-
def tearDown(self):
45+
@classmethod
46+
def tearDownClass(self):
4747
self.driver.quit()
48-
self.assertEqual([], self.verificationErrors)
4948

50-
if __name__ == "__main__":
51-
unittest.main()

gadgets/standard_revisions-tests/hides-dcl-items-in-dcl-rev.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27+
from base import CppTestCase
2728

28-
class HidesDclItemsInDclRev(unittest.TestCase):
29-
def setUp(self):
30-
self.driver = webdriver.Firefox()
31-
self.driver.implicitly_wait(30)
32-
self.base_url = "http://en.cppreference.com/"
33-
self.verificationErrors = []
34-
29+
class HidesDclItemsInDclRev(CppTestCase):
3530
def test_hides_dcl_items_in_dcl_rev(self):
3631
driver = self.driver
3732
driver.get(self.base_url + "/w/test-gadget-stdrev/hides-dcl-items-in-dcl-rev")
@@ -55,10 +50,3 @@ def test_hides_dcl_items_in_dcl_rev(self):
5550
except AssertionError as e: self.verificationErrors.append(str(e))
5651
try: self.assertNotRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx11[\s\S]*$")
5752
except AssertionError as e: self.verificationErrors.append(str(e))
58-
59-
def tearDown(self):
60-
self.driver.quit()
61-
self.assertEqual([], self.verificationErrors)
62-
63-
if __name__ == "__main__":
64-
unittest.main()

gadgets/standard_revisions-tests/hides-dcl-items-in-member.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27+
from base import CppTestCase
2728

28-
class HidesDclItemsInMember(unittest.TestCase):
29-
def setUp(self):
30-
self.driver = webdriver.Firefox()
31-
self.driver.implicitly_wait(30)
32-
self.base_url = "http://en.cppreference.com/"
33-
self.verificationErrors = []
34-
29+
class HidesDclItemsInMember(CppTestCase):
3530
def test_hides_dcl_items_in_member(self):
3631
driver = self.driver
3732
driver.get(self.base_url + "/w/test-gadget-stdrev/hides-dcl-items-in-member")
@@ -55,10 +50,3 @@ def test_hides_dcl_items_in_member(self):
5550
except AssertionError as e: self.verificationErrors.append(str(e))
5651
try: self.assertNotRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*void not_visible_in_cxx11[\s\S]*$")
5752
except AssertionError as e: self.verificationErrors.append(str(e))
58-
59-
def tearDown(self):
60-
self.driver.quit()
61-
self.assertEqual([], self.verificationErrors)
62-
63-
if __name__ == "__main__":
64-
unittest.main()

gadgets/standard_revisions-tests/hides-dsc-items-with-explicit-mark.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27+
from base import CppTestCase
2728

28-
class HidesDscItemsWithExplicitMark(unittest.TestCase):
29-
def setUp(self):
30-
self.driver = webdriver.Firefox()
31-
self.driver.implicitly_wait(30)
32-
self.base_url = "http://en.cppreference.com/"
33-
self.verificationErrors = []
34-
29+
class HidesDscItemsWithExplicitMark(CppTestCase):
3530
def test_hides_dsc_items_with_explicit_mark(self):
3631
driver = self.driver
3732
driver.get(self.base_url + "/w/test-gadget-stdrev/hides-dsc-items-with-explicit-mark")
@@ -49,10 +44,3 @@ def test_hides_dsc_items_with_explicit_mark(self):
4944
except AssertionError as e: self.verificationErrors.append(str(e))
5045
try: self.assertNotRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*std::not_visible_in_cxx11[\s\S]*$")
5146
except AssertionError as e: self.verificationErrors.append(str(e))
52-
53-
def tearDown(self):
54-
self.driver.quit()
55-
self.assertEqual([], self.verificationErrors)
56-
57-
if __name__ == "__main__":
58-
unittest.main()

gadgets/standard_revisions-tests/hides-h3-when-section-contains-dsc-with-removed-elems.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27+
from base import CppTestCase
2728

28-
class HidesH3WhenSectionContainsDscWithRemovedElems(unittest.TestCase):
29-
def setUp(self):
30-
self.driver = webdriver.Firefox()
31-
self.driver.implicitly_wait(30)
32-
self.base_url = "http://en.cppreference.com/"
33-
self.verificationErrors = []
29+
class HidesH3WhenSectionContainsDscWithRemovedElems(CppTestCase):
3430

3531
def test_hides_h3_when_section_contains_dsc_with_removed_elems(self):
3632
driver = self.driver
@@ -43,10 +39,3 @@ def test_hides_h3_when_section_contains_dsc_with_removed_elems(self):
4339
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
4440
try: self.assertTrue(driver.find_element_by_id("Should_be_removed_when_c.2B.2B98").is_displayed())
4541
except AssertionError as e: self.verificationErrors.append(str(e))
46-
47-
def tearDown(self):
48-
self.driver.quit()
49-
self.assertEqual([], self.verificationErrors)
50-
51-
if __name__ == "__main__":
52-
unittest.main()

gadgets/standard_revisions-tests/hides-h3-when-section-contains-dsc-with-removed-until.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27+
from base import CppTestCase
2728

28-
class HidesH3WhenSectionContainsDscWithRemovedUntil(unittest.TestCase):
29-
def setUp(self):
30-
self.driver = webdriver.Firefox()
31-
self.driver.implicitly_wait(30)
32-
self.base_url = "http://en.cppreference.com/"
33-
self.verificationErrors = []
34-
29+
class HidesH3WhenSectionContainsDscWithRemovedUntil(CppTestCase):
3530
def test_hides_h3_when_section_contains_dsc_with_removed_until(self):
3631
driver = self.driver
3732
driver.get(self.base_url + "/w/test-gadget-stdrev/hides-h3-when-section-contains-dsc-with-removed-until")
@@ -43,10 +38,3 @@ def test_hides_h3_when_section_contains_dsc_with_removed_until(self):
4338
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
4439
try: self.assertFalse(driver.find_element_by_id("Should_be_removed_when_c.2B.2B11").is_displayed())
4540
except AssertionError as e: self.verificationErrors.append(str(e))
46-
47-
def tearDown(self):
48-
self.driver.quit()
49-
self.assertEqual([], self.verificationErrors)
50-
51-
if __name__ == "__main__":
52-
unittest.main()

gadgets/standard_revisions-tests/hides-h3-when-section-contains-only-stdrev.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27+
from base import CppTestCase
2728

28-
class HidesH3WhenSectionContainsOnlyStdrev(unittest.TestCase):
29-
def setUp(self):
30-
self.driver = webdriver.Firefox()
31-
self.driver.implicitly_wait(30)
32-
self.base_url = "http://en.cppreference.com/"
33-
self.verificationErrors = []
34-
29+
class HidesH3WhenSectionContainsOnlyStdrev(CppTestCase):
3530
def test_hides_h3_when_section_contains_only_stdrev(self):
3631
driver = self.driver
3732
driver.get(self.base_url + "/w/test-gadget-stdrev/hides-h3-when-section-contains-only-stdrev")
@@ -43,10 +38,3 @@ def test_hides_h3_when_section_contains_only_stdrev(self):
4338
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
4439
try: self.assertTrue(driver.find_element_by_id("Should_be_removed_in_cxx98").is_displayed())
4540
except AssertionError as e: self.verificationErrors.append(str(e))
46-
47-
def tearDown(self):
48-
self.driver.quit()
49-
self.assertEqual([], self.verificationErrors)
50-
51-
if __name__ == "__main__":
52-
unittest.main()

gadgets/standard_revisions-tests/preserves-h3-when-section-visible.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27+
from base import CppTestCase
2728

28-
class PreservesH3WhenSectionVisible(unittest.TestCase):
29-
def setUp(self):
30-
self.driver = webdriver.Firefox()
31-
self.driver.implicitly_wait(30)
32-
self.base_url = "http://en.cppreference.com/"
33-
self.verificationErrors = []
34-
29+
class PreservesH3WhenSectionVisible(CppTestCase):
3530
def test_preserves_h3_when_section_visible(self):
3631
driver = self.driver
3732
driver.get(self.base_url + "/w/test-gadget-stdrev/preserves-h3-when-section-with-h5-visible")
@@ -43,10 +38,3 @@ def test_preserves_h3_when_section_visible(self):
4338
Select(driver.find_element_by_css_selector("select")).select_by_visible_text("C++11")
4439
try: self.assertTrue(driver.find_element_by_id("Should_always_be_visible").is_displayed())
4540
except AssertionError as e: self.verificationErrors.append(str(e))
46-
47-
def tearDown(self):
48-
self.driver.quit()
49-
self.assertEqual([], self.verificationErrors)
50-
51-
if __name__ == "__main__":
52-
unittest.main()

gadgets/standard_revisions-tests/preserves-h3-when-section-with-h5-visible.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27+
from base import CppTestCase
2728

28-
class PreservesH3WhenSectionWithH5Visible(unittest.TestCase):
29-
def setUp(self):
30-
self.driver = webdriver.Firefox()
31-
self.driver.implicitly_wait(30)
32-
self.base_url = "http://en.cppreference.com/"
33-
self.verificationErrors = []
34-
29+
class PreservesH3WhenSectionWithH5Visible(CppTestCase):
3530
def test_preserves_h3_when_section_with_h5_visible(self):
3631
driver = self.driver
3732
driver.get(self.base_url + "/w/test-gadget-stdrev/preserves-h3-when-section-with-h5-visible")
@@ -55,10 +50,3 @@ def test_preserves_h3_when_section_with_h5_visible(self):
5550
except AssertionError as e: self.verificationErrors.append(str(e))
5651
try: self.assertTrue(driver.find_element_by_id("Should_not_be_visible_in_cxx98").is_displayed())
5752
except AssertionError as e: self.verificationErrors.append(str(e))
58-
59-
def tearDown(self):
60-
self.driver.quit()
61-
self.assertEqual([], self.verificationErrors)
62-
63-
if __name__ == "__main__":
64-
unittest.main()

gadgets/standard_revisions-tests/rev-inl-works-in-text.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
from selenium.common.exceptions import NoSuchElementException
2525
from selenium.common.exceptions import NoAlertPresentException
2626
import unittest, time, re
27+
from base import CppTestCase
2728

28-
class RevInlWorksInText(unittest.TestCase):
29-
def setUp(self):
30-
self.driver = webdriver.Firefox()
31-
self.driver.implicitly_wait(30)
32-
self.base_url = "http://en.cppreference.com/"
33-
self.verificationErrors = []
34-
29+
class RevInlWorksInText(CppTestCase):
3530
def test_rev_inl_works_in_text(self):
3631
driver = self.driver
3732
driver.get(self.base_url + "/w/test-gadget-stdrev/rev-inl-works-in-text")
@@ -49,10 +44,3 @@ def test_rev_inl_works_in_text(self):
4944
except AssertionError as e: self.verificationErrors.append(str(e))
5045
try: self.assertNotRegexpMatches(driver.find_element_by_xpath("//body").text, r"^[\s\S]*not_visible_in_cxx11[\s\S]*$")
5146
except AssertionError as e: self.verificationErrors.append(str(e))
52-
53-
def tearDown(self):
54-
self.driver.quit()
55-
self.assertEqual([], self.verificationErrors)
56-
57-
if __name__ == "__main__":
58-
unittest.main()

0 commit comments

Comments
 (0)