Merge lp:~abreu-alexandre/webapps-core/autopilot-tests into lp:webapps-core

Proposed by Alexandre Abreu
Status: Needs review
Proposed branch: lp:~abreu-alexandre/webapps-core/autopilot-tests
Merge into: lp:webapps-core
Diff against target: 370 lines (+297/-2)
11 files modified
CMakeLists.txt (+14/-0)
debian/control (+19/-2)
debian/webapps-core-autopilot.install (+1/-0)
tests/CMakeLists.txt (+2/-0)
tests/autopilot/CMakeLists.txt (+7/-0)
tests/autopilot/webapps_core/__init__.py (+8/-0)
tests/autopilot/webapps_core/tests/__init__.py (+119/-0)
tests/autopilot/webapps_core/tests/test_click_webapps_launch.py (+66/-0)
tests/autopilot/webapps_core/tests/test_facebook.py (+59/-0)
tests/unittests/CMakeLists.txt (+1/-0)
tests/unittests/flake8/CMakeLists.txt (+1/-0)
To merge this branch: bzr merge lp:~abreu-alexandre/webapps-core/autopilot-tests

Commit message

Add autopilot tests

Description of the change

Add autopilot tests

To post a comment you must log in.
112. By Alexandre Abreu

fixes

113. By Alexandre Abreu

add chromedriver deps

114. By Alexandre Abreu

fixes

Revision history for this message
Leo Arias (elopio) wrote :

I copied most of the things Alex did into https://code.launchpad.net/~canonical-platform-qa/webapps-core/x-test/+merge/249580
The difference is that my branch doesn't require the debian package, it runs the tests as click autopkgtests.
It has some downsides, like splitting the tests into each click app folder, which causes some code duplication.
Please take a look there.

Unmerged revisions

114. By Alexandre Abreu

fixes

113. By Alexandre Abreu

add chromedriver deps

112. By Alexandre Abreu

fixes

111. By Alexandre Abreu

fixes for desktop

110. By Alexandre Abreu

fixes

109. By Alexandre Abreu

cleanup

108. By Alexandre Abreu

add test; fix deps

107. By Alexandre Abreu

add oxide dep

106. By Alexandre Abreu

Add AP tests

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'CMakeLists.txt'
2--- CMakeLists.txt 1970-01-01 00:00:00 +0000
3+++ CMakeLists.txt 2015-02-10 20:44:29 +0000
4@@ -0,0 +1,14 @@
5+cmake_minimum_required(VERSION 2.8.9)
6+set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
7+
8+# Standard install paths
9+include(GNUInstallDirs)
10+
11+string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower)
12+
13+set(CMAKE_INCLUDE_CURRENT_DIR ON)
14+set(CMAKE_AUTOMOC ON)
15+
16+enable_testing()
17+add_subdirectory(tests)
18+
19
20=== modified file 'debian/control'
21--- debian/control 2013-09-27 13:51:02 +0000
22+++ debian/control 2015-02-10 20:44:29 +0000
23@@ -3,8 +3,10 @@
24 Priority: extra
25 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
26 XSBC-Original-Maintainer: Ricardo Mendoza <ricardo.mendoza@canonical.com>
27-Build-Depends: debhelper (>= 9.0.0),
28- click
29+Build-Depends: cmake (>= 2.8.9),
30+ debhelper (>= 9.0.0),
31+ click,
32+ python-flake8
33 Standards-Version: 3.9.3
34 Vcs-Bzr: lp:webapps-demo
35
36@@ -22,3 +24,18 @@
37 This package contains click packages that will are pre-installed
38 in the base image.
39
40+Package: webapps-core-autopilot
41+Architecture: all
42+Depends: ${shlibs:Depends},
43+ ${misc:Depends},
44+ dpkg-dev,
45+ autopilot-touch,
46+ libqt5test5,
47+ liboxideqt-qmlplugin (>= 1.4),
48+ oxideqt-chromedriver,
49+ python-selenium
50+Description: Autopilot tests for the Default web applications set (as click packages)
51+ Default web applications set, to demonstrate the integration
52+ of popuplar web services on Ubuntu.
53+ This package contains click packages that will are pre-installed
54+ in the base image.
55
56=== added file 'debian/webapps-core-autopilot.install'
57--- debian/webapps-core-autopilot.install 1970-01-01 00:00:00 +0000
58+++ debian/webapps-core-autopilot.install 2015-02-10 20:44:29 +0000
59@@ -0,0 +1,1 @@
60+usr/lib/python3/dist-packages/webapps_core
61
62=== added directory 'tests'
63=== added file 'tests/CMakeLists.txt'
64--- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
65+++ tests/CMakeLists.txt 2015-02-10 20:44:29 +0000
66@@ -0,0 +1,2 @@
67+add_subdirectory(autopilot)
68+add_subdirectory(unittests)
69
70=== added directory 'tests/autopilot'
71=== added file 'tests/autopilot/CMakeLists.txt'
72--- tests/autopilot/CMakeLists.txt 1970-01-01 00:00:00 +0000
73+++ tests/autopilot/CMakeLists.txt 2015-02-10 20:44:29 +0000
74@@ -0,0 +1,7 @@
75+project(autopilot-tests)
76+
77+execute_process(COMMAND python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
78+ OUTPUT_VARIABLE PYTHON_PACKAGE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
79+
80+install(DIRECTORY webapps_core DESTINATION ${PYTHON_PACKAGE_DIR})
81+
82
83=== added directory 'tests/autopilot/webapps_core'
84=== added file 'tests/autopilot/webapps_core/__init__.py'
85--- tests/autopilot/webapps_core/__init__.py 1970-01-01 00:00:00 +0000
86+++ tests/autopilot/webapps_core/__init__.py 2015-02-10 20:44:29 +0000
87@@ -0,0 +1,8 @@
88+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
89+# Copyright 2014 Canonical
90+#
91+# This program is free software: you can redistribute it and/or modify it
92+# under the terms of the GNU General Public License version 3, as published
93+# by the Free Software Foundation.
94+
95+""" webapps-core-autopilot autopilot tests - top level package."""
96
97=== added directory 'tests/autopilot/webapps_core/tests'
98=== added file 'tests/autopilot/webapps_core/tests/__init__.py'
99--- tests/autopilot/webapps_core/tests/__init__.py 1970-01-01 00:00:00 +0000
100+++ tests/autopilot/webapps_core/tests/__init__.py 2015-02-10 20:44:29 +0000
101@@ -0,0 +1,119 @@
102+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
103+# Copyright 2014 Canonical
104+#
105+# This program is free software: you can redistribute it and/or modify it
106+# under the terms of the GNU General Public License version 3, as published
107+# by the Free Software Foundation.
108+
109+""" webapps-core-autopilot autopilot tests - top level package."""
110+
111+import subprocess
112+
113+from selenium import webdriver
114+from selenium.webdriver.chrome.options import Options
115+
116+import ubuntuuitoolkit as uitk
117+
118+from testtools.matchers import Contains, NotEquals
119+from autopilot.matchers import Eventually
120+from autopilot.platform import model
121+from autopilot import platform
122+
123+from autopilot.testcase import AutopilotTestCase
124+
125+CURRENT_ARCHITECTURE = subprocess.check_output(
126+ ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip()
127+CHROMEDRIVER_EXEC_PATH = \
128+ "/usr/lib/{}/oxide-qt/chromedriver".format(CURRENT_ARCHITECTURE)
129+DEFAULT_WEBVIEW_INSPECTOR_IP = '127.0.0.1'
130+DEFAULT_WEBVIEW_INSPECTOR_PORT = 9221
131+
132+
133+class WebappsCoreTestCaseBase(AutopilotTestCase):
134+ def setUp(self):
135+ self.driver = None
136+ self.app_proxy = None
137+ super(WebappsCoreTestCaseBase, self).setUp()
138+
139+ def tearDown(self):
140+ if self.driver:
141+ self.page.close()
142+ self.page.quit()
143+ # XXX: This should not be there but AP hangs
144+ # if we dont extra force the process to be killed
145+ # (although AP already tries to kill part of its teardown)
146+ if platform.model() == 'Desktop' and self.app_proxy and self.app_proxy.process:
147+ self.app_proxy.process.kill()
148+ super(WebappsCoreTestCaseBase, self).tearDown()
149+
150+ def get_webview(self):
151+ return self.app_proxy.select_single(objectName="webview")
152+
153+ def get_oxide_webview(self):
154+ container = self.get_webview().select_single(
155+ objectName='containerWebviewLoader')
156+ return container.wait_select_single('WebViewImplOxide')
157+
158+ def launch_webdriver(self, ip, port):
159+ options = Options()
160+ options.binary_location = ''
161+ options.debugger_address = '{}:{}'.format(ip, port)
162+
163+ self.driver = webdriver.Chrome(
164+ executable_path=CHROMEDRIVER_EXEC_PATH,
165+ chrome_options=options)
166+ self.assertThat(self.driver, NotEquals(None))
167+
168+ @property
169+ def page(self):
170+ return self.driver
171+
172+ def launch_webcontainer_app(self, args):
173+ return self.launch_test_application(
174+ 'webapp-container',
175+ *args,
176+ emulator_base=uitk.UbuntuUIToolkitCustomProxyObjectBase)
177+
178+ def launch_webapp(
179+ self,
180+ package_id,
181+ app_name,
182+ with_chrome_driver=False,
183+ envvars={},
184+ ip=DEFAULT_WEBVIEW_INSPECTOR_IP,
185+ port=DEFAULT_WEBVIEW_INSPECTOR_PORT,
186+ homepage=''):
187+
188+ # setup devtools environment
189+ self.patch_environment(
190+ 'UBUNTU_WEBVIEW_DEVTOOLS_HOST',
191+ ip)
192+ self.patch_environment(
193+ 'UBUNTU_WEBVIEW_DEVTOOLS_PORT',
194+ str(port))
195+
196+ if envvars:
197+ for envvar_key in envvars:
198+ self.patch_environment(envvar_key, envvars[envvar_key])
199+
200+ if model() == 'Desktop':
201+ self.app_proxy = self.launch_webcontainer_app(
202+ [homepage])
203+ else:
204+ self.app_proxy = self.launch_click_package(
205+ package_id)
206+ self.validate_url_for_current_proxy()
207+
208+ if with_chrome_driver:
209+ self.launch_webdriver(ip, port)
210+
211+ def validate_url_for_current_proxy(self):
212+ self.assertThat(self.app_proxy, NotEquals(None))
213+ webview = self.get_webview()
214+ self.assertThat(webview.url, NotEquals(""))
215+
216+ def validate_title(self, title):
217+ window = self.get_webcontainer_window()
218+ self.assertThat(
219+ lambda: window.title.lower(),
220+ Eventually(Contains(title.lower())))
221
222=== added file 'tests/autopilot/webapps_core/tests/test_click_webapps_launch.py'
223--- tests/autopilot/webapps_core/tests/test_click_webapps_launch.py 1970-01-01 00:00:00 +0000
224+++ tests/autopilot/webapps_core/tests/test_click_webapps_launch.py 2015-02-10 20:44:29 +0000
225@@ -0,0 +1,66 @@
226+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
227+# Copyright 2014 Canonical
228+#
229+# This program is free software: you can redistribute it and/or modify it
230+# under the terms of the GNU General Public License version 3, as published
231+# by the Free Software Foundation.
232+
233+from webapps_core.tests import WebappsCoreTestCaseBase
234+
235+from autopilot import platform
236+from testtools import skipUnless
237+
238+
239+class ClickWebappsLaunchTestCaseBase(WebappsCoreTestCaseBase):
240+ def setUp(self):
241+ super(ClickWebappsLaunchTestCaseBase, self).setUp()
242+
243+ @skipUnless(
244+ platform.model() != 'Desktop',
245+ "UbuntuTouch only"
246+ )
247+ def test_launch_facebook(self):
248+ package_name = 'com.ubuntu.developer.webapps.webapp-facebook'
249+ app_name = 'webapp-facebook'
250+ self.launch_webapp(package_name, app_name)
251+ self.validate_title('facebook')
252+
253+ @skipUnless(
254+ platform.model() != 'Desktop',
255+ "UbuntuTouch only"
256+ )
257+ def test_launch_amazon(self):
258+ package_name = 'com.ubuntu.developer.webapps.webapp-amazon'
259+ app_name = 'webapp-amazon'
260+ self.launch_webapp(package_name, app_name)
261+ self.validate_title('amazon')
262+
263+ @skipUnless(
264+ platform.model() != 'Desktop',
265+ "UbuntuTouch only"
266+ )
267+ def test_launch_ebay(self):
268+ package_name = 'com.ubuntu.developer.webapps.webapp-ebay'
269+ app_name = 'webapp-ebay'
270+ self.launch_webapp(package_name, app_name)
271+ self.validate_title('ebay')
272+
273+ @skipUnless(
274+ platform.model() != 'Desktop',
275+ "UbuntuTouch only"
276+ )
277+ def test_launch_gmail(self):
278+ package_name = 'com.ubuntu.developer.webapps.webapp-gmail'
279+ app_name = 'webapp-gmail'
280+ self.launch_webapp(package_name, app_name)
281+ self.validate_title('gmail')
282+
283+ @skipUnless(
284+ platform.model() != 'Desktop',
285+ "UbuntuTouch only"
286+ )
287+ def test_launch_twitter(self):
288+ package_name = 'com.ubuntu.developer.webapps.webapp-twitter'
289+ app_name = 'webapp-twitter'
290+ self.launch_webapp(package_name, app_name)
291+ self.validate_title('twitter')
292
293=== added file 'tests/autopilot/webapps_core/tests/test_facebook.py'
294--- tests/autopilot/webapps_core/tests/test_facebook.py 1970-01-01 00:00:00 +0000
295+++ tests/autopilot/webapps_core/tests/test_facebook.py 2015-02-10 20:44:29 +0000
296@@ -0,0 +1,59 @@
297+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
298+# Copyright 2014 Canonical
299+#
300+# This program is free software: you can redistribute it and/or modify it
301+# under the terms of the GNU General Public License version 3, as published
302+# by the Free Software Foundation.
303+
304+from webapps_core.tests import WebappsCoreTestCaseBase
305+
306+from testtools.matchers import NotEquals, GreaterThan
307+from autopilot.matchers import Eventually
308+
309+
310+class ClickWebappsLaunchTestCaseBase(WebappsCoreTestCaseBase):
311+ def setUp(self):
312+ super(ClickWebappsLaunchTestCaseBase, self).setUp()
313+
314+ def test_click_photo(self):
315+ package_name = 'com.ubuntu.developer.webapps.webapp-facebook'
316+ app_name = 'webapp-facebook'
317+ self.launch_webapp(
318+ package_name,
319+ app_name,
320+ True,
321+ homepage='https://m.facebook.com')
322+ photo_button = self.page.find_element_by_css_selector(
323+ "button[data-sigil~='photo_link']")
324+ self.assertThat(photo_button, NotEquals(None))
325+
326+ photo_button.click()
327+
328+ post_button = self.page.find_element_by_css_selector(
329+ "button[type='submit']")
330+ self.assertThat(post_button, NotEquals(None))
331+
332+ def test_redirect_url(self):
333+ package_name = 'com.ubuntu.developer.webapps.webapp-facebook'
334+ app_name = 'webapp-facebook'
335+ self.launch_webapp(
336+ package_name,
337+ app_name,
338+ True,
339+ {'WEBAPP_CONTAINER_BLOCK_OPEN_URL_EXTERNALLY': '1'},
340+ homepage='https://m.facebook.com')
341+
342+ external_link = self.page.find_element_by_css_selector(
343+ "a[href^='http://lm.facebook.com/l.php?u='][target='_blank']")
344+ self.assertThat(external_link, NotEquals(None))
345+
346+ webview = self.get_webview()
347+ watcher = webview.watch_signal(
348+ 'openExternalUrlTriggered(QString)')
349+ previous = watcher.num_emissions
350+
351+ external_link.click()
352+
353+ self.assertThat(
354+ lambda: watcher.num_emissions,
355+ Eventually(GreaterThan(previous)))
356
357=== added directory 'tests/unittests'
358=== added file 'tests/unittests/CMakeLists.txt'
359--- tests/unittests/CMakeLists.txt 1970-01-01 00:00:00 +0000
360+++ tests/unittests/CMakeLists.txt 2015-02-10 20:44:29 +0000
361@@ -0,0 +1,1 @@
362+add_subdirectory(flake8)
363\ No newline at end of file
364
365=== added directory 'tests/unittests/flake8'
366=== added file 'tests/unittests/flake8/CMakeLists.txt'
367--- tests/unittests/flake8/CMakeLists.txt 1970-01-01 00:00:00 +0000
368+++ tests/unittests/flake8/CMakeLists.txt 2015-02-10 20:44:29 +0000
369@@ -0,0 +1,1 @@
370+add_test(flake8 flake8 ${autopilot-tests_SOURCE_DIR})

Subscribers

People subscribed via source and target branches

to all changes: