improved sikuli test case (login/logout)
authorPhilipp Schüle <p.schuele@metaways.de>
Fri, 10 Jan 2014 13:32:13 +0000 (14:32 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 10 Jan 2014 15:48:37 +0000 (16:48 +0100)
- uses Chromium class for simple browser management
- adds logout
- imports unittest
- uses testsuite

Change-Id: I3db9395b54ab3ef9201463048ba31ec38fdc4983
Reviewed-on: https://gerrit.tine20.org/tine20/2710
Tested-by: Philipp Schüle <p.schuele@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/sikuli/login.sikuli/1379932428118.png [deleted file]
tests/sikuli/login.sikuli/1379932466303.png [deleted file]
tests/sikuli/login.sikuli/1379934818634.png [deleted file]
tests/sikuli/login.sikuli/1389349522098.png [new file with mode: 0644]
tests/sikuli/login.sikuli/1389349732360.png [new file with mode: 0644]
tests/sikuli/login.sikuli/login.html
tests/sikuli/login.sikuli/login.py
tests/sikuli/login.sikuli/loginlogo.png [new file with mode: 0644]
tests/sikuli/login.sikuli/logout.png [new file with mode: 0644]
tests/sikuli/login.sikuli/password.png [new file with mode: 0644]
tests/sikuli/login.sikuli/username.png [new file with mode: 0644]

diff --git a/tests/sikuli/login.sikuli/1379932428118.png b/tests/sikuli/login.sikuli/1379932428118.png
deleted file mode 100644 (file)
index 8de8709..0000000
Binary files a/tests/sikuli/login.sikuli/1379932428118.png and /dev/null differ
diff --git a/tests/sikuli/login.sikuli/1379932466303.png b/tests/sikuli/login.sikuli/1379932466303.png
deleted file mode 100644 (file)
index 9d4a1b5..0000000
Binary files a/tests/sikuli/login.sikuli/1379932466303.png and /dev/null differ
diff --git a/tests/sikuli/login.sikuli/1379934818634.png b/tests/sikuli/login.sikuli/1379934818634.png
deleted file mode 100644 (file)
index 4c2e029..0000000
Binary files a/tests/sikuli/login.sikuli/1379934818634.png and /dev/null differ
diff --git a/tests/sikuli/login.sikuli/1389349522098.png b/tests/sikuli/login.sikuli/1389349522098.png
new file mode 100644 (file)
index 0000000..9a656ef
Binary files /dev/null and b/tests/sikuli/login.sikuli/1389349522098.png differ
diff --git a/tests/sikuli/login.sikuli/1389349732360.png b/tests/sikuli/login.sikuli/1389349732360.png
new file mode 100644 (file)
index 0000000..e0d2668
Binary files /dev/null and b/tests/sikuli/login.sikuli/1389349732360.png differ
index 538ac18..9418f1b 100644 (file)
 <h2>login.sikuli</h2> <a href="login.zip">(Download this script)</a>
 </div>
 <pre class="sikuli-code">
-Region(<span class="dig">109</span>,<span class="dig">28</span>,<span class="dig">1022</span>,<span class="dig">712</span>)
-<span class="skw">click</span>(<img src="1379932428118.png" />)
-<span class="skw">type</span>(<span class="str">"unittest"</span>)
-<span class="skw">click</span>(<img src="1379932466303.png" />)
-<span class="skw">type</span>(<span class="str">"picola124"</span>)
-<span class="skw">click</span>(<img src="1379932483974.png" />)
+<span class="kw">from</span> __future__ <span class="kw">import</span> with_statement
+<span class="kw">import</span> unittest
+
+<span class="kw">from</span> sikuli.Sikuli <span class="kw">import</span> *
+
+<span class="kw">class</span> Chromium(object):
+
+    <span class="kw">def</span> __init__(self, url):
+        self.url = url
+
+    <span class="kw">def</span> __enter__(self):
+        Screen(<span class="dig">0</span>)
+        app = App.open(<span class="str">'chromium-browser'</span>)
+        <span class="skw">wait</span>(<span class="dig">2</span>)
+        <span class="skw">type</span>(<span class="str">"%s\n"</span> % self.url)
+        <span class="skw">wait</span>(<span class="dig">2</span>)
+
+    <span class="kw">def</span> __exit__(self, type_, value, traceback):
+        <span class="skw">type</span>(Key.F4, KEY_ALT)
+
+
+<span class="kw">class</span> TestBasicScenario(unittest.TestCase):
+
+    <span class="kw">def</span> test_01_login(self):
+        <span class="skw">click</span>(<img src="username.png" />)
+        <span class="skw">type</span>(<span class="str">"unittest"</span>)
+        <span class="skw">click</span>(<img src="password.png" />)
+        <span class="skw">type</span>(<span class="str">"password"</span>)
+        <span class="skw">click</span>(<img src="1379932483974.png" />)
+        <span class="skw">wait</span>(<span class="dig">3</span>)
+        <span class="kw">assert</span> exists(<img src="1389349522098.png" />)
+
+
+    <span class="kw">def</span> test_02_logout(self):
+        <span class="skw">click</span>(<img src="logout.png" />)
+        <span class="skw">click</span>(<img src="1389349732360.png" />)
+        <span class="skw">wait</span>(<span class="dig">3</span>)
+        <span class="kw">assert</span> exists(<img src="loginlogo.png" />)
+
+
+
+<span class="cmt"># Sikuli settings (no logs)
+</span>Settings.ActionLogs = False
+Settings.InfoLogs = False
+Settings.DebugLogs = False
+
+<span class="kw">with</span> Chromium(<span class="str">'localhost&amp;tine20'</span>):
+    suite = unittest.TestLoader().loadTestsFromTestCase(TestBasicScenario)
+    unittest.TextTestRunner(verbosity=<span class="dig">2</span>).run(suite)
 </pre>
 </body>
 </html>
index 19b90ae..e0e93fc 100644 (file)
@@ -1,6 +1,50 @@
-Region(109,28,1022,712)
-click("1379932428118.png")
-type("unittest")
-click("1379932466303.png")
-type("password")
-click("1379932483974.png")
+from __future__ import with_statement
+import unittest
+
+from sikuli.Sikuli import *
+
+class Chromium(object):
+
+    def __init__(self, url):
+        self.url = url
+    def __enter__(self):
+        Screen(0)
+        app = App.open('chromium-browser')
+        wait(2)
+        type("%s\n" % self.url)    
+        wait(2)
+        
+    def __exit__(self, type_, value, traceback):
+        type(Key.F4, KEY_ALT)
+
+        
+class TestBasicScenario(unittest.TestCase):
+    def test_01_login(self):
+        click("username.png")
+        type("unittest")
+        click("password.png")
+        type("password")
+        click("1379932483974.png")
+        wait(3)
+        assert exists("1389349522098.png")
+        
+
+    def test_02_logout(self):
+        click("logout.png")
+        click("1389349732360.png")
+        wait(3)       
+        assert exists("loginlogo.png")
+        
+
+
+# Sikuli settings (no logs)
+Settings.ActionLogs = False
+Settings.InfoLogs = False
+Settings.DebugLogs = False
+with Chromium('localhost&tine20'):
+    suite = unittest.TestLoader().loadTestsFromTestCase(TestBasicScenario)
+    unittest.TextTestRunner(verbosity=2).run(suite)
+
diff --git a/tests/sikuli/login.sikuli/loginlogo.png b/tests/sikuli/login.sikuli/loginlogo.png
new file mode 100644 (file)
index 0000000..a7bb2c0
Binary files /dev/null and b/tests/sikuli/login.sikuli/loginlogo.png differ
diff --git a/tests/sikuli/login.sikuli/logout.png b/tests/sikuli/login.sikuli/logout.png
new file mode 100644 (file)
index 0000000..99b25b8
Binary files /dev/null and b/tests/sikuli/login.sikuli/logout.png differ
diff --git a/tests/sikuli/login.sikuli/password.png b/tests/sikuli/login.sikuli/password.png
new file mode 100644 (file)
index 0000000..27bfa3b
Binary files /dev/null and b/tests/sikuli/login.sikuli/password.png differ
diff --git a/tests/sikuli/login.sikuli/username.png b/tests/sikuli/login.sikuli/username.png
new file mode 100644 (file)
index 0000000..3521045
Binary files /dev/null and b/tests/sikuli/login.sikuli/username.png differ