~aleteoryx/muditaos

ref: b95894a8abc10cddf0b58dda4b2569b01eec0d7e muditaos/test/pytest/service-bluetooth/bt_fixtures.py -rw-r--r-- 2.5 KiB
b95894a8 — Lefucjusz [MOS-1064] Fix no input language selected for French/Spanish 1 year, 9 months ago
                                                                                
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
59
60
61
62
63
64
65
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

import pytest
from harness import log
from harness.interface.defs import key_codes, status
from harness.dom_parser_utils import *
import time
from bt_utils import *

@pytest.fixture(scope='function')
def bt_main_window(harness):
    current_window_content = get_window_content(harness, 1)
    assert item_contains_recursively(current_window_content, 'WindowName', 'MainWindow' )
    harness.connection.send_key_code(key_codes["enter"])

    log.info("Navigating to ApplicationSettings")
    harness.open_application("settings")
    if harness.connection.get_application_name() != "ApplicationSettings":
        time.sleep(5)
        assert harness.connection.get_application_name() == "ApplicationSettings"

    log.info("Opening Bluetooth")
    harness.connection.send_key_code(key_codes["down"])
    harness.connection.send_key_code(key_codes["enter"])

@pytest.fixture(scope='function')
def bt_reset(harness):
    current_window_content = get_window_content(harness, 1)
    assert item_contains_recursively(current_window_content, 'WindowName', 'Bluetooth' )

    parent_of_list_items = find_parent(current_window_content, 'ListItem')
    if item_has_child_that_contains_recursively( parent_of_list_items, [('TextValue','Bluetooth'), ('TextValue', 'ON')] ) :
        log.info("Bluetooth is ON, turing OFF...")
        harness.connection.send_key_code(key_codes["enter"])

    current_window_content = get_window_content(harness, 1)
    parent_of_list_items = find_parent(current_window_content, 'ListItem')
    assert item_has_child_that_contains_recursively( parent_of_list_items, [('TextValue','Bluetooth'), ('TextValue', 'OFF')] )

    log.info("Turing Bluetooth ON...")
    harness.connection.send_key_code(key_codes["enter"])

@pytest.fixture(scope='function')
def bt_all_devices(harness):
    log.info("Navigating to AllDevices window...")
    time.sleep(1)
    harness.connection.send_key_code(key_codes["down"])
    harness.connection.send_key_code(key_codes["enter"])

    current_window_content = get_window_content(harness, 1)
    assert item_contains_recursively(current_window_content, 'WindowName', 'AllDevices')

@pytest.fixture(scope='function')
def bt_state_on(harness):
    status = bt_get_state(harness)
    if status["power"] == "off":
        bt_set_status(harness, "on")


@pytest.fixture(scope='function')
def bt_state_off(harness):
    status = bt_get_state(harness)
    if status["power"] == "on":
        bt_set_status(harness, "off")