aboutsummaryrefslogtreecommitdiffstats
path: root/test/data/common_steps/dialogs.py
blob: 2679cf0881029fdd98e720c7c7dee14a83418aa0 (plain) (blame)
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
# -*- coding: UTF-8 -*-
from behave import step
from dogtail.rawinput import keyCombo
from dogtail.predicate import GenericPredicate
import pyatspi


@step(u'folder select dialog with name "{name}" is displayed')
def has_folder_select_dialog_with_name(context, name):
    has_files_select_dialog_with_name(context, name)


@step(u'folder select dialog is displayed')
def has_folder_select_dialog(context):
    context.execute_steps(
        u'Then folder select dialog with name "Select Folder" is displayed')


@step(u'in folder select dialog I choose "{name}"')
def select_folder_in_dialog(context, name):
    select_file_in_dialog(context, name)


@step(u'file select dialog with name "{name}" is displayed')
def has_files_select_dialog_with_name(context, name):
    context.app.dialog = context.app.instance.child(name=name, roleName='file chooser')


@step(u'file select dialog is displayed')
def has_files_select_dialog(context):
    context.execute_steps(
        u'Then file select dialog with name "Select Files" is displayed')


@step(u'in file select dialog I select "{name}"')
def select_file_in_dialog(context, name):
    # Find an appropriate button to click
    # It will be either 'Home' or 'File System'

    home_folder = context.app.dialog.findChild(GenericPredicate(name='Home'), retry=False, requireResult=False)
    if home_folder:
        home_folder.click()
    else:
        context.app.dialog.childNamed('File System').click()
    location_button = context.app.dialog.child('Type a file name')
    if not pyatspi.STATE_ARMED in location_button.getState().getStates():
        location_button.click()

    context.app.dialog.childLabelled('Location:').set_text_contents(name)
    context.app.dialog.childLabelled('Location:').grab_focus()
    keyCombo('<Enter>')


@step(u'in file save dialog I save file to "{path}" clicking "{button}"')
def file_save_to_path(context, path, button):
    context.app.dialog.childLabelled('Name:').set_text_contents(path)
    context.app.dialog.childNamed(button).click()