~canonical-platform-qa/ubuntu-system-settings-online-accounts/launch_fixture

« back to all changes in this revision

Viewing changes to tests/autopilot/online_accounts_ui/tests/test_online_accounts_ui.py

  • Committer: CI bot
  • Author(s): Leo Arias
  • Date: 2014-07-08 11:05:26 UTC
  • mfrom: (128.2.4 clean_tests)
  • Revision ID: ps-jenkins@lists.canonical.com-20140708110526-k86rmxqu1qn4tam6
Refactored the autopilot tests to use the page object pattern. Added the method go to add account to be used in UX tests. 
Approved by: PS Jenkins bot, PS Jenkins bot, PS Jenkins bot, Víctor R. Ruiz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/env python3
2
 
# -*- coding: utf-8 -*-
 
2
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
3
#
4
 
# Copyright (C) 2013 Canonical Ltd.
 
4
# Copyright (C) 2013, 2014 Canonical Ltd.
5
5
# Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
6
6
#
7
 
# This program is free software: you can redistribute it and/or modify it
8
 
# under the terms of the GNU General Public License version 3, as published
9
 
# by the Free Software Foundation.
10
 
 
11
 
from autopilot.testcase import AutopilotTestCase
12
 
from autopilot.input import Mouse, Touch, Pointer
13
 
from autopilot.platform import model
14
 
from autopilot.matchers import Eventually
15
 
from subprocess import Popen
16
 
from testtools.matchers import Contains, Equals, NotEquals, GreaterThan
17
 
from time import sleep
18
 
import os
19
 
 
20
 
from online_accounts_ui.emulators.items import EmulatorBase
 
7
# This file is part of ubuntu-system-settings-online-accounts.
 
8
#
 
9
# ubuntu-system-settings-online-accounts is free software: you can
 
10
# redistribute it and/or modify it under the terms of the GNU General Public
 
11
# License as published by the Free Software Foundation; version 3.
 
12
#
 
13
# ubuntu-system-settings-online-accounts is distributed in the hope that it
 
14
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 
15
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 
 
21
from online_accounts_ui import tests
21
22
 
22
23
 
23
24
# You can find a couple of OAuth 1.0a and 2.0 tests in the repository history
29
30
# This issue will be solved when we move the signon-ui implementation in the
30
31
# same process as online-accounts-ui
31
32
 
32
 
 
33
 
class OnlineAccountsUiTests(AutopilotTestCase):
34
 
    if model() == 'Desktop':
35
 
        scenarios = [
36
 
                ('with mouse', dict(input_device_class=Mouse)),
37
 
                ]
38
 
    else:
39
 
        scenarios = [
40
 
                ('with touch', dict(input_device_class=Touch)),
41
 
                ]
42
 
 
43
 
    def setUp(self):
44
 
        super(OnlineAccountsUiTests, self).setUp()
45
 
 
46
 
        # On the phone, this fails because of https://bugs.launchpad.net/bugs/1252294
47
 
        if model() != 'Desktop':
48
 
            return
49
 
 
50
 
        self.pointer = Pointer(self.input_device_class.create())
51
 
        # Increase the timeout of online-accounts-ui, to make sure it won't
52
 
        # quit before the system settings panel asks it to open.
53
 
        self.patch_environment('OAU_DAEMON_TIMEOUT', '120')
54
 
        self.app = self.launch_test_application('online-accounts-ui',
55
 
                '--desktop_file_hint=/usr/share/applications/online-accounts-ui.desktop',
56
 
                app_type='qt',
57
 
                emulator_base=EmulatorBase,
58
 
                capture_output=True)
59
 
        self.system_settings = Popen(['system-settings', 'online-accounts',
60
 
            '--desktop_file_hint=/usr/share/applications/ubuntu-system-settings.desktop'])
61
 
        sleep(1)
62
 
        self.window = self.app.select_single("QQuickView")
63
 
        self.assertThat(self.window.visible, Eventually(Equals(True)))
64
 
 
65
 
    def tearDown(self):
66
 
        super(OnlineAccountsUiTests, self).tearDown()
67
 
        # This matches the logic in setUp()
68
 
        if model() != 'Desktop':
69
 
            return
70
 
        self.system_settings.terminate()
 
33
class MainViewTestCase(tests.BaseOnlineAccountsUITestCase):
71
34
 
72
35
    def test_title(self):
73
 
        """ Checks whether the Online Accounts window title is correct """
74
 
        # On the phone, this fails because of https://bugs.launchpad.net/bugs/1252294
75
 
        if model() != 'Desktop':
76
 
            return
77
 
 
78
 
        header = self.window.select_single('Header', visible=True)
79
 
        self.assertThat(header, NotEquals(None))
80
 
        self.assertThat(header.title, Eventually(Equals('Accounts')))
 
36
        """Checks whether the Online Accounts window title is correct."""
 
37
        # TODO turn this into a QML test. --elopio - 2014-07-03
 
38
        header = self.application.main_view.get_header()
 
39
        self.assertTrue(header.visible)
 
40
        self.assertEquals(header.title, 'Accounts')
 
41
 
 
42
 
 
43
class AvailableProvidersTestCase(tests.BaseOnlineAccountsUITestCase):
 
44
 
 
45
    required_providers = ['FakeOAuth', 'TestLogin']
 
46
    scenarios = [(provider, {'provider': provider})
 
47
                 for provider in required_providers]
81
48
 
82
49
    def test_available_providers(self):
83
 
        """ Checks whether all the expected providers are available """
84
 
        # On the phone, this fails because of https://bugs.launchpad.net/bugs/1252294
85
 
        if model() != 'Desktop':
86
 
            return
87
 
 
88
 
        required_providers = [
89
 
                'FakeOAuth',
90
 
                ]
91
 
        for provider in required_providers:
92
 
            provider_item = self.app.select_single('Standard', text=provider)
93
 
            self.assertThat(provider_item, NotEquals(None))
 
50
        """Checks whether all the expected providers are available."""
 
51
        no_accounts_page = self.application.main_view.no_accounts_page
 
52
        available_providers = no_accounts_page.get_providers()
 
53
        self.assertIn(self.provider, available_providers)
 
54
 
 
55
 
 
56
class CreateAccountTestCase(tests.BaseOnlineAccountsUITestCase):
94
57
 
95
58
    def test_create_account_with_form(self):
96
 
        """ Test the creation of an account using a username/password form"""
97
 
        # On the phone, this fails because of https://bugs.launchpad.net/bugs/1252294
98
 
        if model() != 'Desktop':
99
 
            return
100
 
        page = self.app.select_single('NoAccountsPage')
101
 
        self.assertThat(page, NotEquals(None))
102
 
 
103
 
        provider_item = self.app.select_single('Standard', text='TestLogin')
104
 
        self.assertThat(provider_item, NotEquals(None))
105
 
 
106
 
        # Depending on the number of installed providers, it may be that our
107
 
        # test provider is not visible; in that case, scroll the page
108
 
        self.pointer.move_to_object(page)
109
 
        (page_center_x, page_center_y) = self.pointer.position()
110
 
        page_bottom = page.globalRect[1] + page.globalRect[3]
111
 
        while provider_item.center[1] > page_bottom - 20:
112
 
            self.pointer.move(page_center_x, page_center_y)
113
 
            self.pointer.press()
114
 
            self.pointer.move(page_center_x, page_center_y - provider_item.height * 2)
115
 
            # wait some time before releasing, to avoid a flick
116
 
            sleep(0.2)
117
 
            self.pointer.release()
118
 
        self.pointer.move_to_object(provider_item)
119
 
        self.pointer.click()
120
 
 
121
 
        # Move to the username field
122
 
        username_field = self.app.select_single('TextField', objectName='usernameField')
123
 
        self.pointer.move_to_object(username_field)
124
 
        self.pointer.click()
125
 
        self.keyboard.type('pinkuser')
126
 
        self.keyboard.press_and_release('Tab')
127
 
        self.keyboard.type('lolcat')
128
 
        # Submit
129
 
        continue_btn = self.app.select_single('Button', objectName='continueButton')
130
 
        self.pointer.move_to_object(continue_btn)
131
 
        self.pointer.click()
132
 
 
133
 
        # The account should be created shortly
134
 
        sleep(5)
135
 
        account_item = self.app.select_single('AccountItem', text='TestLogin')
136
 
        self.assertThat(account_item, NotEquals(None))
137
 
        self.assertThat(account_item.subText, Equals('pinkuser'))
138
 
 
139
 
        # Delete it
140
 
        self.pointer.move_to_object(account_item)
141
 
        self.pointer.click()
142
 
 
143
 
        sleep(1)
144
 
        edit_page = self.app.select_single('AccountEditPage')
145
 
        self.assertThat(edit_page, NotEquals(None))
146
 
        remove_button = edit_page.select_single('Button')
147
 
        self.assertThat(remove_button, NotEquals(None))
148
 
        self.pointer.move_to_object(remove_button)
149
 
        self.pointer.click()
150
 
 
151
 
        sleep(1)
152
 
        removal_page = self.app.select_single('RemovalConfirmation')
153
 
        self.assertThat(removal_page, NotEquals(None))
154
 
        remove_button = removal_page.select_single('Button', text='Remove')
155
 
        self.assertThat(remove_button, NotEquals(None))
156
 
        self.pointer.move_to_object(remove_button)
157
 
        self.pointer.click()
158
 
 
159
 
        # Check that the account has been deleted
160
 
        account_item.wait_until_destroyed()
161
 
 
 
59
        """Test the creation of an account using a username/password form."""
 
60
        accounts_page = self.application.main_view.add_test_login_account(
 
61
            user_name='pinkuser', password='lolcat')
 
62
 
 
63
        self.assertIn(('TestLogin', 'pinkuser'), accounts_page.get_accounts())
 
64
 
 
65
        accounts_page.delete_account('TestLogin', 'pinkuser')