~nskaggs/help-app/functional-test-template

« back to all changes in this revision

Viewing changes to internals/tests/functional/help_app/tests/__init__.py

  • Committer: nskaggs
  • Date: 2015-05-28 20:26:30 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20150528202630-ryv2q2sztwqlxkjv
initial modification to add helper and multiple testsuites for web and app

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import os
6
6
import subprocess
7
7
 
 
8
from help_app import HelpApp
 
9
 
8
10
from selenium import webdriver
9
11
from selenium.webdriver.chrome.options import Options
10
12
 
12
14
from ubuntuuitoolkit import fixture_setup
13
15
 
14
16
from autopilot import platform
15
 
 
16
17
from testtools.matchers import NotEquals, EndsWith
17
18
from autopilot.matchers import Eventually
18
 
 
19
19
from autopilot.testcase import AutopilotTestCase
20
20
 
21
21
CURRENT_ARCHITECTURE = subprocess.check_output(
29
29
 
30
30
class HTML5TestCaseBase(AutopilotTestCase):
31
31
    def setUp(self):
32
 
        self.driver = None
33
 
        self.app_proxy = None
34
 
        super().setUp()
 
32
        super(HTML5TestCaseBase, self).setUp()
35
33
        if platform.model() == 'Desktop':
36
34
            self.patch_environment(
37
35
                'UBUNTU_WEBVIEW_DEVTOOLS_HOST',
49
47
 
50
48
    def tearDown(self):
51
49
        if self.driver:
52
 
            self.page.close()
53
 
            self.page.quit()
 
50
            self.driver.close()
 
51
            self.driver.quit()
54
52
        # XXX: This should not be there but AP hangs
55
53
        # if we dont extra force the process to be killed
56
54
        # (although AP already tries to kill part of its teardown)
57
55
        if platform.model() == 'Desktop' \
58
 
           and self.app_proxy \
59
 
           and self.app_proxy.process:
60
 
            self.app_proxy.process.kill()
 
56
           and self.app.app \
 
57
           and self.app.app.process:
 
58
            self.app.app.process.kill()
61
59
        super(HTML5TestCaseBase, self).tearDown()
62
60
 
63
 
    def get_webview(self):
64
 
        return self.app_proxy.select_single('UbuntuWebView02')
65
 
 
66
61
    def launch_webdriver(self):
67
62
        options = Options()
68
63
        options.binary_location = ''
70
65
            DEFAULT_WEBVIEW_INSPECTOR_IP,
71
66
            DEFAULT_WEBVIEW_INSPECTOR_PORT)
72
67
 
73
 
        self.driver = webdriver.Chrome(
 
68
        return webdriver.Chrome(
74
69
            executable_path=CHROMEDRIVER_EXEC_PATH,
75
70
            chrome_options=options)
76
71
 
77
 
        self.assertThat(self.driver, NotEquals(None))
78
 
 
79
 
    @property
80
 
    def page(self):
81
 
        return self.driver
82
 
 
83
 
    def launch_html5_app_inline(self, args):
 
72
    def launch_html5_app(self, path):
84
73
        return self.launch_test_application(
85
74
            'ubuntu-html5-app-launcher',
86
 
            *args,
 
75
            '--www={}/{}'.format(
 
76
                os.path.dirname(
 
77
                    os.path.realpath(__file__)), path),
87
78
            emulator_base=uitk.UbuntuUIToolkitCustomProxyObjectBase)
88
79
 
89
 
    def launch_html5_app(self):
90
 
        self.app_proxy = self.launch_html5_app_inline(
91
 
            ['--www={}/{}'.format(
92
 
                os.path.dirname(
93
 
                    os.path.realpath(__file__)),
94
 
                '../../../../../build/app/www')])
95
 
        self.wait_for_app()
96
 
 
97
 
        self.launch_webdriver()
98
 
 
99
 
    def wait_for_app(self):
100
 
        self.assertThat(self.app_proxy, NotEquals(None))
101
 
        webview = self.get_webview()
102
 
        self.assertThat(
103
 
            lambda: webview.url,
104
 
            Eventually(EndsWith("/index.html")))
 
80
 
 
81
class HelpAppTest(HTML5TestCaseBase):
 
82
 
 
83
    """Testcase that launches the help app"""
 
84
 
 
85
    def setUp(self):
 
86
        super(HelpAppTest, self).setUp()
 
87
        self.app = HelpApp(self.launch_html5_app('../../../../../build/app/www'))
 
88
        self.driver = self.launch_webdriver()
 
89
 
 
90
 
 
91
class HelpWebTest(HTML5TestCaseBase):
 
92
 
 
93
    """Testcase that launches the help web version"""
 
94
 
 
95
    def setUp(self):
 
96
        super(HelpWebTest, self).setUp()
 
97
        self.app = HelpApp(self.launch_html5_app('../../../../../build/web/www'))
 
98
        self.driver = self.launch_webdriver()