|
4 | 4 | from datetime import datetime |
5 | 5 | from pathlib import Path |
6 | 6 |
|
| 7 | +import playwright |
7 | 8 | import pytest |
8 | 9 |
|
9 | 10 | from widgetastic.browser import BrowserParentWrapper |
10 | 11 | from widgetastic.exceptions import LocatorNotImplemented |
11 | 12 | from widgetastic.exceptions import NoSuchElementException |
12 | 13 | from widgetastic.widget import Text |
13 | 14 | from widgetastic.widget import View |
14 | | -from playwright.sync_api import Locator |
15 | 15 |
|
16 | 16 |
|
17 | 17 | @pytest.fixture() |
@@ -273,7 +273,10 @@ def test_wait_for_element_visible(browser): |
273 | 273 | # Click on the button |
274 | 274 | browser.click("#invisible_appear_button") |
275 | 275 | try: |
276 | | - assert isinstance(browser.wait_for_element("#invisible_appear_p", visible=True), Locator) |
| 276 | + assert isinstance( |
| 277 | + browser.wait_for_element("#invisible_appear_p", visible=True), |
| 278 | + playwright.sync_api.Locator, |
| 279 | + ) |
277 | 280 | except NoSuchElementException: |
278 | 281 | pytest.fail("NoSuchElementException raised when webelement expected") |
279 | 282 |
|
@@ -603,7 +606,7 @@ def test_click_with_ignore_ajax(browser): |
603 | 606 |
|
604 | 607 | def test_click_with_invalid_button(browser): |
605 | 608 | """Test click method with invalid button parameter raises ValueError.""" |
606 | | - with pytest.raises(ValueError, match="Invalid button 'invalid'"): |
| 609 | + with pytest.raises(playwright._impl._errors.Error): |
607 | 610 | browser.click("#a_button", button="invalid") |
608 | 611 |
|
609 | 612 |
|
@@ -655,19 +658,85 @@ def test_mouse_click(browser, button): |
655 | 658 | assert result == expected_result |
656 | 659 |
|
657 | 660 |
|
| 661 | +def test_click_with_click_count(browser): |
| 662 | + """Test click method with click_count=<number> parameter.""" |
| 663 | + for click_count in [1, 2, 3]: |
| 664 | + # Reset first |
| 665 | + browser.execute_script("resetClickCount()") |
| 666 | + |
| 667 | + browser.click("#a_button", click_count=click_count) |
| 668 | + |
| 669 | + # Verify click count was detected |
| 670 | + result = browser.text("#click_count_result") |
| 671 | + assert f"Clicks: {click_count}" in result |
| 672 | + assert "clicked" in browser.classes("#a_button").pop() |
| 673 | + |
| 674 | + |
| 675 | +def test_click_with_delay_parameter(browser): |
| 676 | + """Test click method with delay parameter between mousedown and mouseup.""" |
| 677 | + for delay_ms in [100, 0]: |
| 678 | + browser.execute_script("resetClickDelay()") |
| 679 | + |
| 680 | + browser.click("#multi_button", delay=delay_ms) |
| 681 | + # Give a moment for the handler to process |
| 682 | + time.sleep(0.05) |
| 683 | + |
| 684 | + # Verify delay was applied (allow some tolerance for execution time) |
| 685 | + result = browser.text("#click_delay_result") |
| 686 | + assert "Delay:" in result |
| 687 | + |
| 688 | + # Extract the delay value from result |
| 689 | + delay_value = int(result.split(":")[1].strip().replace("ms", "")) |
| 690 | + print(delay_value) |
| 691 | + # Allow 10ms tolerance for browser timing variations |
| 692 | + assert delay_value >= delay_ms |
| 693 | + assert delay_value <= delay_ms + 10 |
| 694 | + |
| 695 | + |
| 696 | +def test_click_with_force_parameter(browser): |
| 697 | + """Test click method with force parameter (True and False).""" |
| 698 | + # force parameter bypasses Playwright's actionability checks |
| 699 | + # We test that the parameter is properly passed through |
| 700 | + browser.execute_script("resetClickCount()") |
| 701 | + |
| 702 | + # Test force=True works |
| 703 | + browser.click("#a_button", force=True) |
| 704 | + assert "clicked" in browser.classes("#a_button") |
| 705 | + |
| 706 | + browser.refresh() |
| 707 | + browser.execute_script("resetClickCount()") |
| 708 | + |
| 709 | + # Test force=False works (default behavior) |
| 710 | + browser.click("#a_button", force=False) |
| 711 | + assert "clicked" in browser.classes("#a_button") |
| 712 | + |
| 713 | + |
| 714 | +def test_click_with_timeout_parameter(browser): |
| 715 | + """Test click method with timeout parameter.""" |
| 716 | + # Test that timeout parameter is accepted and doesn't break normal clicks |
| 717 | + browser.click("#a_button", timeout=0) |
| 718 | + assert "clicked" in browser.classes("#a_button") |
| 719 | + |
| 720 | + browser.refresh() |
| 721 | + browser.execute_script("resetClickCount()") |
| 722 | + |
| 723 | + browser.click("#a_button", timeout=100) |
| 724 | + assert "clicked" in browser.classes("#a_button") |
| 725 | + |
| 726 | + |
658 | 727 | def test_double_click_method(browser): |
659 | 728 | """Test double_click method.""" |
660 | 729 | initial_classes = browser.classes("#a_button") |
661 | 730 | browser.double_click("#a_button") |
662 | 731 | final_classes = browser.classes("#a_button") |
663 | | - assert "clicked" in final_classes |
| 732 | + assert "double-clicked" in final_classes |
664 | 733 | assert "clicked" not in initial_classes |
665 | 734 |
|
666 | 735 |
|
667 | 736 | def test_double_click_with_ignore_ajax(browser): |
668 | 737 | """Test double_click method with ignore_ajax parameter.""" |
669 | 738 | browser.double_click("#a_button", ignore_ajax=True) |
670 | | - assert "clicked" in browser.classes("#a_button") |
| 739 | + assert "double-clicked" in browser.classes("#a_button") |
671 | 740 |
|
672 | 741 |
|
673 | 742 | def test_double_click_with_timed_out_error_in_ensure_page_safe(browser, monkeypatch): |
@@ -703,7 +772,7 @@ def mock_after_click_safe_timeout(el, locator): |
703 | 772 |
|
704 | 773 | # Verify the timeout handler was called |
705 | 774 | assert timeout_called is True |
706 | | - assert "clicked" in browser.classes("#a_button") |
| 775 | + assert "double-clicked" in browser.classes("#a_button") |
707 | 776 |
|
708 | 777 |
|
709 | 778 | def test_raw_click(browser): |
|
0 commit comments