File: test_get_elements.py

package info (click to toggle)
python-pywebview 3.3.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 29,536 kB
  • sloc: python: 5,703; javascript: 888; cs: 130; sh: 55; makefile: 3
file content (58 lines) | stat: -rw-r--r-- 1,235 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pytest
import threading
from .util import run_test, get_test_name
import webview


html = """
  <html>
    <body>
      <h1 id="heading">Heading</h1>
      <div class="content">Content 1</div>
      <div class="content">Content 2</div>
    </body>
  </html>
"""

@pytest.fixture
def window():
    return webview.create_window('Get elements test', html=html)


def test_single(window):
    run_test(webview, window, single_test)


def test_multiple(window):
    run_test(webview, window, multiple_test)


def test_none(window):
    run_test(webview, window, none_test)


def single_test(window):
    try:
        elements = window.get_elements('#heading')
        assert len(elements) == 1
        assert elements[0]['innerHTML'] == 'Heading'
    except NotImplementedError:
        pass


def multiple_test(window):
    try:
        elements = window.get_elements('.content')
        assert len(elements) == 2
        assert elements[0]['innerHTML'] == 'Content 1'
        assert elements[1]['innerHTML'] == 'Content 2'
    except NotImplementedError:
        pass


def none_test(window):
    try:
        elements = window.get_elements('.adgdfg')
        assert len(elements) == 0
    except NotImplementedError:
        pass