improved sikuli test case (login/logout)
[tine20] / tests / sikuli / login.sikuli / login.html
1
2 <html>
3    <head>
4       <style type="text/css">
5          .sikuli-code {
6             font-size: 20px;
7             font-family: "Osaka-mono", Monospace;
8             line-height: 1.5em;
9             display:table-cell;
10             white-space: pre-wrap;       /* css-3 */
11             white-space: -moz-pre-wrap !important;  /* Mozilla, since 1999 */
12             white-space: -pre-wrap;      /* Opera 4-6 */
13             white-space: -o-pre-wrap;    /* Opera 7 */
14             word-wrap: break-word;       /* Internet Explorer 5.5+ */
15             width: 99%;   /* remove horizontal scroll-bar when viewing in IE7 */
16          }
17          .sikuli-code img {
18             vertical-align: middle;
19             margin: 2px;
20             border: 1px solid #ccc;
21             padding: 2px;
22             -moz-border-radius: 5px;
23             -webkit-border-radius: 5px;
24             -moz-box-shadow: 1px 1px 1px gray;
25             -webkit-box-shadow: 1px 1px 2px gray;
26          }
27          .kw {
28             color: blue;
29          }
30          .skw {
31             color: rgb(63, 127, 127);
32          }
33
34          .str {
35             color: rgb(128, 0, 0);
36          }
37
38          .dig {
39             color: rgb(128, 64, 0);
40          }
41
42          .cmt {
43             color: rgb(200, 0, 200);
44          }
45
46          h2 {
47             display: inline;
48             font-weight: normal;
49          }
50
51          .info {
52             border-bottom: 1px solid #ddd;
53             padding-bottom: 5px;
54             margin-bottom: 20px;
55             display: none;
56          }
57
58          a {
59             color: #9D2900;
60          }
61
62          body {
63             font-family: "Trebuchet MS", Arial, Sans-Serif;
64          }
65
66       </style>
67    </head>
68 <body>
69 <div class="info">
70 <h2>login.sikuli</h2> <a href="login.zip">(Download this script)</a>
71 </div>
72 <pre class="sikuli-code">
73 <span class="kw">from</span> __future__ <span class="kw">import</span> with_statement
74 <span class="kw">import</span> unittest
75
76 <span class="kw">from</span> sikuli.Sikuli <span class="kw">import</span> *
77
78 <span class="kw">class</span> Chromium(object):
79
80     <span class="kw">def</span> __init__(self, url):
81         self.url = url
82
83     <span class="kw">def</span> __enter__(self):
84         Screen(<span class="dig">0</span>)
85         app = App.open(<span class="str">'chromium-browser'</span>)
86         <span class="skw">wait</span>(<span class="dig">2</span>)
87         <span class="skw">type</span>(<span class="str">"%s\n"</span> % self.url)
88         <span class="skw">wait</span>(<span class="dig">2</span>)
89
90     <span class="kw">def</span> __exit__(self, type_, value, traceback):
91         <span class="skw">type</span>(Key.F4, KEY_ALT)
92
93
94 <span class="kw">class</span> TestBasicScenario(unittest.TestCase):
95
96     <span class="kw">def</span> test_01_login(self):
97         <span class="skw">click</span>(<img src="username.png" />)
98         <span class="skw">type</span>(<span class="str">"unittest"</span>)
99         <span class="skw">click</span>(<img src="password.png" />)
100         <span class="skw">type</span>(<span class="str">"password"</span>)
101         <span class="skw">click</span>(<img src="1379932483974.png" />)
102         <span class="skw">wait</span>(<span class="dig">3</span>)
103         <span class="kw">assert</span> exists(<img src="1389349522098.png" />)
104
105
106     <span class="kw">def</span> test_02_logout(self):
107         <span class="skw">click</span>(<img src="logout.png" />)
108         <span class="skw">click</span>(<img src="1389349732360.png" />)
109         <span class="skw">wait</span>(<span class="dig">3</span>)
110         <span class="kw">assert</span> exists(<img src="loginlogo.png" />)
111
112
113
114 <span class="cmt"># Sikuli settings (no logs)
115 </span>Settings.ActionLogs = False
116 Settings.InfoLogs = False
117 Settings.DebugLogs = False
118
119 <span class="kw">with</span> Chromium(<span class="str">'localhost&amp;tine20'</span>):
120     suite = unittest.TestLoader().loadTestsFromTestCase(TestBasicScenario)
121     unittest.TextTestRunner(verbosity=<span class="dig">2</span>).run(suite)
122 </pre>
123 </body>
124 </html>