SeleniumBase/examples/test_repeat_tests.py

37 lines
1.2 KiB
Python
Raw Normal View History

2021-10-19 11:52:04 +08:00
""" Tests to demonstrate how to repeat the same test multiple times.
The 1st example uses the "parameterized" library.
The 2nd example uses "pytest.mark.parametrize()". (NO class)
The 3rd example uses "pytest.mark.parametrize()". (in class) """
import pytest
from parameterized import parameterized
from seleniumbase import BaseCase
2023-11-09 13:06:51 +08:00
BaseCase.main(__name__, __file__, "-n6")
2021-10-19 11:52:04 +08:00
2023-10-27 15:34:25 +08:00
url = "data:text/html,<h2>Hello</h2><p><input />&nbsp;<button>OK!</button></p>"
2021-10-19 11:52:04 +08:00
class RepeatTests(BaseCase):
@parameterized.expand([[]] * 2)
def test_repeat_this_test_with_parameterized(self):
2023-10-27 15:34:25 +08:00
self.open(url)
self.type("input", "SeleniumBase is fun")
self.click('button:contains("OK!")')
self.assert_text("Hello", "h2")
2021-10-19 11:52:04 +08:00
@pytest.mark.parametrize("", [[]] * 2)
def test_repeat_this_test_with_pytest_parametrize(sb):
2023-10-27 15:34:25 +08:00
sb.open(url)
sb.type("input", "SeleniumBase is fun")
sb.click('button:contains("OK!")')
sb.assert_text("Hello", "h2")
2021-10-19 11:52:04 +08:00
2022-04-14 01:40:01 +08:00
class RepeatTestsWithPytest:
2021-10-19 11:52:04 +08:00
@pytest.mark.parametrize("", [[]] * 2)
def test_repeat_test_with_pytest_parametrize(self, sb):
2023-10-27 15:34:25 +08:00
sb.open(url)
sb.type("input", "SeleniumBase is fun")
sb.click('button:contains("OK!")')
sb.assert_text("Hello", "h2")