public
Description: Dissertacao de mestrado
Homepage:
Clone URL: git://github.com/briglia/dissertacao.git
Anderson Briglia (author)
Tue Apr 28 17:36:53 -0700 2009
dissertacao / utilities / test-browser.py
100644 89 lines (76 sloc) 2.95 kb
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
#!/usr/bin.python
#
# Copyright (c) 2009 - Anderson Farias Briglia
# <anderson.briglia@gmail.com>
#
# This file is part of carman-python.
#
# carman-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# carman-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
 
import time
from os import system
 
class TestBrowser:
 
    def __init__(self):
 
        self.send_url_cmd = 'run-standalone.sh dbus-send --type=method_call --dest=com.nokia.osso_browser /com/nokia/osso_browser com.nokia.osso_browser.load_url string:'
        self.urls = ['www.uol.com.br', 'www.acritica.com.br', 'www.kibeloco.com.br',
                'www.wikipedia.org', 'www.humortadela.com.br', 'www.google.com',
                'www.ufam.edu.br', 'www.gmail.com',
                'sanguedelpredador.briglia.net', 'techblog.briglia.net']
        self.wcount = 0
        self.__steps = []
 
    def close_window(self):
        cmd = ("xte -x :0.0 'mousemove 776 25' 'mouseclick 1'", 2)
        self.add_step(cmd)
 
    def open_new_browser(self):
        '''
        This is necessary to open first browser window.
        '''
        if self.wcount == 0:
            self.add_step((self.send_url_cmd, 5))
        else:
            cmd = ("xte -x :0.0 'mousemove 150 30' 'mouseclick 1'", 1)
            self.add_step(cmd)
            cmd = ("xte -x :0.0 'mousemove 150 85' 'mouseclick 1'", 1)
            self.add_step(cmd)
            cmd = ("xte -x :0.0 'key Page_Down' 'key Page_Down' 'key Down' 'key Return'", 10)
            self.add_step(cmd)
        self.wcount = self.wcount + 1
 
    def open_url(self, url):
        self.open_new_browser()
        cmd = self.send_url_cmd + url
        self.add_step((cmd, 20))
 
    def add_step(self, cmd):
        self.__steps.append(cmd)
 
    def close_all(self):
        for i in xrange(0, self.wcount):
            self.close_window()
 
    def play_steps(self):
        '''
        Run each command stored in self.__steps.
        Uses time.sleep() to make an interval between each command.
        '''
        for cmd in self.__steps:
            #print 'CMD: ', cmd[0]
            system(cmd[0])
            time.sleep(cmd[1])
 
    def begin_test(self):
        for url in self.urls:
            self.open_url(url)
        self.close_all()
        self.play_steps()
 
if __name__ == '__main__':
    print 'Initiating tests...'
    test = TestBrowser()
    test.begin_test()
    print 'Test Finished...'