import pytest
from selenium.common.exceptions import TimeoutException, WebDriverException

from src.driver_factory import WebDriverUnavailableError
from src.examples import bing_search_example


def test_bing_search_example():
    try:
        title = bing_search_example.run(keyword="runoob")
    except WebDriverUnavailableError as exc:
        pytest.skip(str(exc))
    except TimeoutException as exc:
        pytest.skip(f"Bing 页面加载/元素等待超时：{exc}")
    except WebDriverException as exc:
        pytest.skip(f"Bing 用例执行异常：{exc}")

    assert "runoob" in title.lower()
