Not executing according to the set maximum number of times and Generate the same data repeatedly
import pytest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from hypothesis import given, settings, HealthCheck, example, seed, strategies as st
import re
def test_search(keyword):
driver = webdriver.Chrome()
try:
driver.get("https://www.google.com/")
search_box = driver.find_element("name", "q")
search_box.send_keys(keyword)
search_box.send_keys(Keys.RETURN)
assert f"{keyword} - Google Search" in driver.title
driver.quit()
finally:
driver.quit()
@settings(max_examples=3, database=None)
@seed(123)
@given(keyword=st.text(min_size=10, max_size=50))
def test_search_with_hypothesis(keyword):
print("\nkeyword:", keyword)
assert keyword is not None
test_search(keyword)
@pytest.mark.parametrize("keyword", ["python", "selenium", "hypothesis"])
def test_fixed_keywords(keyword):
test_search(keyword)
After execution:
demo\hy_selenium_pytest_demo.py E
keyword: 0000000000
keyword: ÄÖß=R
keyword: 9䔁116C
keyword: 9䔁116C
keyword: 䔁116C
keyword: 16C
Process finished with exit code -1
max_examples=3,Generate more than 3 timesThe generated data has duplicates
Hypothesis + playwright there are also similar issues
@settings(max_examples=3, database=None)
I hope it's a random character, not
@example(keyword="python")
@example(keyword="selenium")
@example(keyword="hypothesis")