aboutsummaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/hob-dogtail/gedit-test-utf8-procedural-api.py
blob: ae9b338dd102d6cb0354751aef436ed2788f9f2f (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
# Dogtail demo script

from dogtail.config import config
#config.debugSleep = True
#config.debugSearching = True
#config.debugTranslation = True

import dogtail.tc
from dogtail.procedural import *
from dogtail.utils import screenshot

# These next two lines get us translations for free. To see the script run
# translated, run it like this:
#  LANG=ja_JP.UTF-8 ./gedit-test-utf8-procedural-api.py
# You might also want to set config.debugTranslation and
# config.debugSearching to True, just for fun.
import dogtail.i18n
dogtail.i18n.loadTranslationsFromPackageMoFiles('gedit')

from os import environ, path, remove

# Load our persistent Dogtail objects
TestString = dogtail.tc.TCString()

# Remove the output file, if it's still there from a previous run
if path.isfile(path.join(path.expandvars("$HOME"), "Desktop", "UTF8demo.txt")):
    remove(path.join(path.expandvars("$HOME"), "Desktop", "UTF8demo.txt"))

# Start gedit.
run('gedit')

# Set focus on gedit
focus.application('gedit')

# Focus gedit's text buffer.
focus.text()

# Load the UTF-8 demo file. Use codecs.open() instead of open().
from codecs import open
from sys import path
utfdemo = open(path[0] + '/data/UTF-8-demo.txt')

# Load the UTF-8 demo file into the text buffer.
focus.widget.text = utfdemo.read()

# Take a screenshot of the window
screenshot()

# Click gedit's Save button.
click.button('Save')

# Focus gedit's Save As... dialog
try:
    # This string changed somewhere around gedit 2.13.2.
    # This is the new string
    focus.dialog(u'Save As\u2026')
except FocusError:
    # Fall back to the old string.
    focus.dialog('Save as...')

# click the Browse for other folders widget
focus.widget('Browse for other folders')
if not focus.widget.checked: click()

# Click the Desktop widget
click('Desktop', roleName = 'table cell')

# We want to save to the file name 'UTF8demo.txt'.
focus.text()
focus.widget.text = 'UTF8demo.txt'

# Click the Save button.
click('Save')

# Let's quit now.
click('File')
click('Quit')

# We have driven gedit now lets check to see if the saved file is the same as
# the baseline file

# Read in the "gold" file
import codecs
try:
    # When reading the file, we have to make sure and tell codecs.open() which
    # encoding we're using, otherwise python gets confused later.
    gold = open(path[0] + '/data/UTF-8-demo.txt', encoding='utf-8').readlines()
except IOError:
    print "File open failed"

# Read the test file for comparison
filepath = environ['HOME'] + '/Desktop/UTF8demo.txt'
# When reading the file, we have to make sure and tell codecs.open() which
# encoding we're using, otherwise python gets confused later.
testfile = open(filepath, encoding='utf-8').readlines()

# We now have the original and saved files as lists. Let's compare them line
# by line to see if they are the same
i = 0
for baseline in gold:
    label = "line test " + str(i + 1)
    TestString.compare(label, baseline, testfile[i], encoding='utf-8')
    i = i + 1