Пример #1
0
 def _long_press_key(self, key_rect, pointer=None):
     if pointer is None:
         pointer = Pointer(Touch.create())
     pointer.move(key_rect.x + key_rect.w / 2.0,
                  key_rect.y + key_rect.h / 2.0)
     pointer.press()
     sleep(0.5)
     pointer.release()
Пример #2
0
 def _long_press_key(self, key_rect, pointer=None):
     if pointer is None:
         pointer = Pointer(Touch.create())
     pointer.move(
         key_rect.x + key_rect.w / 2.0, key_rect.y + key_rect.h / 2.0)
     pointer.press()
     sleep(0.5)
     pointer.release()
Пример #3
0
class UbuntuTouchAppTestCase(AutopilotTestCase):
    """A common test case class that provides several useful methods for the tests."""

    if model() == 'Desktop':
        scenarios = [
        ('with mouse', dict(input_device_class=Mouse))
        ]
    else:
        scenarios = [
        ('with touch', dict(input_device_class=Touch))
        ]

    @property
    def main_window(self):
        return MainWindow(self.app)


    def setUp(self):
        self.pointing_device = Pointer(self.input_device_class.create())
        super(UbuntuTouchAppTestCase, self).setUp()
        self.launch_test_qml()


    def launch_test_qml(self):
        # If the test class has defined a 'test_qml' class attribute then we
        # write it to disk and launch it inside the QML Scene. If not, then we
        # silently do nothing (presumably the test has something else planned).
        arch = subprocess.check_output(["dpkg-architecture",
        "-qDEB_HOST_MULTIARCH"]).strip()
        if hasattr(self, 'test_qml') and isinstance(self.test_qml, basestring):
            qml_path = mktemp(suffix='.qml')
            open(qml_path, 'w').write(self.test_qml)
            self.addCleanup(remove, qml_path)

            self.app = self.launch_test_application(
                "/usr/lib/" + arch + "/qt5/bin/qmlscene",
                "-I", get_module_include_path(),
                qml_path,
                app_type='qt')

        if hasattr(self, 'test_qml_file') and isinstance(self.test_qml_file, basestring):
            qml_path = self.test_qml_file
            self.app = self.launch_test_application(
                "/usr/lib/" + arch + "/qt5/bin/qmlscene",
                "-I", get_module_include_path(),
                qml_path,
                app_type='qt')

        self.assertThat(self.get_qml_view().visible, Eventually(Equals(True)))


    def get_qml_view(self):
        """Get the main QML view"""

        return self.app.select_single("QQuickView")

    def get_mainview(self):
        """Get the QML MainView"""

        mainView = self.app.select_single("MainView")
        self.assertThat(mainView, Not(Is(None)))
        return mainView


    def get_object(self,objectName):
        """Get a object based on the objectName"""

        obj = self.app.select_single(objectName=objectName)
        self.assertThat(obj, Not(Is(None)))
        return obj


    def mouse_click(self,objectName):
        """Move mouse on top of the object and click on it"""

        obj = self.get_object(objectName)
        self.pointing_device.move_to_object(obj)
        self.pointing_device.click()


    def mouse_press(self,objectName):
        """Move mouse on top of the object and press mouse button (without releasing it)"""

        obj = self.get_object(objectName)
        self.pointing_device.move_to_object(obj)
        self.pointing_device.press()


    def mouse_release(self):
        """Release mouse button"""

        self.pointing_device.release()     


    def type_string(self, string):
        """Type a string with keyboard"""

        self.keyboard.type(string)


    def type_key(self, key):
        """Type a single key with keyboard"""

        self.keyboard.key(key)
Пример #4
0
class UbuntuTouchAppTestCase(AutopilotTestCase):
    """A common test case class that provides several useful methods for the tests."""

    if model() == 'Desktop':
        scenarios = [('with mouse', dict(input_device_class=Mouse))]
    else:
        scenarios = [('with touch', dict(input_device_class=Touch))]

    @property
    def main_window(self):
        return MainWindow(self.app)

    def setUp(self):
        self.pointing_device = Pointer(self.input_device_class.create())
        super(UbuntuTouchAppTestCase, self).setUp()
        self.launch_test_qml()

    def launch_test_qml(self):
        # If the test class has defined a 'test_qml' class attribute then we
        # write it to disk and launch it inside the QML Scene. If not, then we
        # silently do nothing (presumably the test has something else planned).
        arch = subprocess.check_output(
            ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip()
        if hasattr(self, 'test_qml') and isinstance(self.test_qml, basestring):
            qml_path = mktemp(suffix='.qml')
            open(qml_path, 'w').write(self.test_qml)
            self.addCleanup(remove, qml_path)

            self.app = self.launch_test_application("/usr/lib/" + arch +
                                                    "/qt5/bin/qmlscene",
                                                    "-I",
                                                    get_module_include_path(),
                                                    qml_path,
                                                    app_type='qt')

        if hasattr(self, 'test_qml_file') and isinstance(
                self.test_qml_file, basestring):
            qml_path = self.test_qml_file
            self.app = self.launch_test_application("/usr/lib/" + arch +
                                                    "/qt5/bin/qmlscene",
                                                    "-I",
                                                    get_module_include_path(),
                                                    qml_path,
                                                    app_type='qt')

        self.assertThat(self.get_qml_view().visible, Eventually(Equals(True)))

    def get_qml_view(self):
        """Get the main QML view"""

        return self.app.select_single("QQuickView")

    def get_mainview(self):
        """Get the QML MainView"""

        mainView = self.app.select_single("MainView")
        self.assertThat(mainView, Not(Is(None)))
        return mainView

    def get_object(self, objectName):
        """Get a object based on the objectName"""

        obj = self.app.select_single(objectName=objectName)
        self.assertThat(obj, Not(Is(None)))
        return obj

    def mouse_click(self, objectName):
        """Move mouse on top of the object and click on it"""

        obj = self.get_object(objectName)
        self.pointing_device.move_to_object(obj)
        self.pointing_device.click()

    def mouse_press(self, objectName):
        """Move mouse on top of the object and press mouse button (without releasing it)"""

        obj = self.get_object(objectName)
        self.pointing_device.move_to_object(obj)
        self.pointing_device.press()

    def mouse_release(self):
        """Release mouse button"""

        self.pointing_device.release()

    def type_string(self, string):
        """Type a string with keyboard"""

        self.keyboard.type(string)

    def type_key(self, key):
        """Type a single key with keyboard"""

        self.keyboard.key(key)
Пример #5
0
class UbuntuHTML5TestCaseBase(AutopilotTestCase):
    BROWSER_CONTAINER_PATH = "{}/{}".format(
        os.path.dirname(os.path.realpath(__file__)),
        '../../tools/qml/webview.qml')
    INSTALLED_BROWSER_CONTAINER_PATH = \
        '/usr/share/ubuntu-html5-ui-toolkit/tests/tools/qml/webview.qml'
    BROWSER_QML_APP_LAUNCHER = "/usr/lib/{}/qt5/bin/qmlscene".format(
        subprocess.check_output(
            ["dpkg-architecture",
             "-qDEB_HOST_MULTIARCH"]).strip().decode('utf-8'))

    # TODO: fix version
    LOCAL_HTML_EXAMPLES_PATH = os.path.abspath(
        "{}/{}".format(
            os.path.dirname(os.path.realpath(__file__)),
            '../../../../tests'))
    INSTALLED_HTML_EXAMPLES_PATH = \
        '/usr/share/ubuntu-html5-ui-toolkit/tests/'

    APPS_SUBFOLDER_NAME = 'apps'

    BASE_PATH = ''

    def get_browser_container_path(self):
        if os.path.exists(self.BROWSER_CONTAINER_PATH):
            return self.BROWSER_CONTAINER_PATH
        return self.INSTALLED_BROWSER_CONTAINER_PATH

    def create_file_url_from(self, filepath):
        return 'file://' + filepath

    def setup_base_path(self):
        if os.path.exists(self.LOCAL_HTML_EXAMPLES_PATH):
            self.BASE_PATH = self.LOCAL_HTML_EXAMPLES_PATH
        else:
            self.BASE_PATH = self.INSTALLED_HTML_EXAMPLES_PATH

    def setUp(self):
        self.setup_base_path()
        if platform.model() == "Desktop":
            self.pointer = Pointer(Mouse.create())
        else:
            self.pointer = Pointer(Touch.create())

        params = [self.BROWSER_QML_APP_LAUNCHER,
                  self.get_browser_container_path()]
        if (platform.model() != 'Desktop'):
            params.append(
                '--desktop_file_hint=/usr/share/" \
                + "applications/unitywebappsqmllauncher.desktop')

        self.app = self.launch_test_application(
            *params,
            app_type='qt')

        self.webviewContainer = self.get_webviewContainer()
        self.watcher = self.webviewContainer.watch_signal(
            'resultUpdated(QString)')
        super(UbuntuHTML5TestCaseBase, self).setUp()

    def tearDown(self):
        super(UbuntuHTML5TestCaseBase, self).tearDown()

    def pick_app_launcher(self, app_path):
        # force Qt app introspection:
        from autopilot.introspection.qt import QtApplicationLauncher
        return QtApplicationLauncher()

    def get_webviewContainer(self):
        return self.app.select_single(objectName="webviewContainer")

    def get_webview(self):
        return self.app.select_single(objectName="webview")

    def get_addressbar(self):
        return self.app.select_single(objectName="addressbar")

    def get_button(self):
        return self.app.select_single(objectName="browseButton")

    def get_title(self):
        return self.get_webview().title

    def assert_url_eventually_loaded(self, url):
        webview = self.get_webview()
        self.assertThat(
            webview.loadProgress,
            Eventually(Equals(100)))
        self.assertThat(
            webview.loading,
            Eventually(Equals(False)))
        self.assertThat(
            webview.url,
            Eventually(Equals(url)))

    def click_dom_node_with_id(self, id):
        webview = self.get_webviewContainer()
        webview.slots.clickElementById(id)
        self.assertThat(
            lambda: self.watcher.num_emissions,
            Eventually(Equals(1)))

    def click_any_dom_node_by_selector(self, selector):
        webview = self.get_webviewContainer()
        webview.slots.clickAnyElementBySelector(selector)
        self.assertThat(
            lambda: self.watcher.num_emissions,
            Eventually(Equals(1)))

    def is_dom_node_visible(self, id):
        webview = self.get_webviewContainer()
        prev_emissions = self.watcher.num_emissions
        webview.slots.isNodeWithIdVisible(id)
        self.assertThat(
            lambda: self.watcher.num_emissions,
            Eventually(GreaterThan(prev_emissions)))
        return json.loads(
            webview.get_signal_emissions(
                'resultUpdated(QString)')[-1][0])['result']

    def eval_expression_in_page_unsafe(self, expr):
        webview = self.get_webviewContainer()
        prev_emissions = self.watcher.num_emissions
        webview.slots.evalInPageUnsafe(expr)
        self.assertThat(
            lambda: self.watcher.num_emissions,
            Eventually(GreaterThan(prev_emissions)))
        return webview.get_signal_emissions('resultUpdated(QString)')[-1][0]

    def get_dom_node_id_attribute(self, id, attribute):
        webview = self.get_webviewContainer()
        prev_emissions = self.watcher.num_emissions
        webview.slots.getAttributeForElementWithId(id, attribute)
        self.assertThat(
            lambda: self.watcher.num_emissions,
            Eventually(GreaterThan(prev_emissions)))
        return json.loads(
            webview.get_signal_emissions(
                'resultUpdated(QString)')[-1][0])['result']

    def get_address_bar_action_button(self):
        addressbar = self.get_addressbar()
        return addressbar.select_single(objectName="browseButton")

    def browse_to_url(self, url):
        import time
        addressbar = self.get_addressbar()
        self.assertThat(
            addressbar.activeFocus,
            Eventually(Equals(True)))

        self.keyboard.type(url, 0.001)

        self.pointer.click_object(self.get_webview())

        # XXX: very bad, but wont fix
        time.sleep(1)

        button = self.get_address_bar_action_button()
        self.pointer.move_to_object(button)
        self.pointer.press()
        # XXX: very bad, but wont fix
        time.sleep(1)
        self.pointer.release()

        self.assert_url_eventually_loaded(url)

    def browse_to_app(self, appname):
        appfilepath = os.path.abspath(
            self.BASE_PATH +
            '/data/html/' +
            self.APPS_SUBFOLDER_NAME +
            '/' +
            appname +
            '/index.html')

        APP_HTML_PATH = self.create_file_url_from(appfilepath)

        self.browse_to_url(APP_HTML_PATH)

    def browse_to_test_html(self, html_filename):
        self.browse_to_url(
            self.create_file_url_from(
                os.path.abspath(
                    '{}/data/html/{}'.format(
                        self.BASE_PATH,
                        html_filename))))
Пример #6
0
class SaucyBaconTestCase(AutopilotTestCase):
    """A common test case class that provides several useful methods for the tests."""

    if model() == 'Desktop':
        scenarios = [
        ('with mouse', dict(input_device_class=Mouse))
        ]
    else:
        scenarios = [
        ('with touch', dict(input_device_class=Touch))
        ]
    
    local_location = get_qml_location() + "/saucybacon.qml"

    @property
    def main_window(self):
        return MainWindow(self.app)

    def setUp(self):
        self.pointing_device = Pointer(self.input_device_class.create())
        super(SaucyBaconTestCase, self).setUp()
        
        print self.local_location
        print get_module_include_path()
        if os.path.exists(self.local_location):
            self.launch_test_local()
        elif os.path.exists('/usr/share/saucybacon/app/saucybacon.qml'):
            self.launch_test_installed()
        else:
            self.launch_test_click()

    def launch_test_local(self):
        self.app = self.launch_test_application(
            "qmlscene",
            self.local_location,
            "-I",
            get_module_include_path(),
            app_type='qt',
            emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)

    def launch_test_installed(self):
        self.app = self.launch_test_application(
            "qmlscene",
            "/usr/share/postino/postino.qml",
            "--desktop_file_hint=/usr/share/applications/saucybacon.desktop",
            app_type='qt',
            emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)

    def launch_test_click(self):
        self.app = self.launch_click_package(
            'com.ubuntu.developers.gcollura.saucybacon',
            emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)


    def get_qml_view(self):
        """Get the main QML view"""

        return self.app.select_single("QQuickView")

    def get_mainview(self):
        """Get the QML MainView"""

        mainView = self.app.select_single("MainView")
        self.assertThat(mainView, Not(Is(None)))
        return mainView


    def get_object(self,objectName):
        """Get a object based on the objectName"""

        obj = self.app.select_single(objectName=objectName)
        self.assertThat(obj, Not(Is(None)))
        return obj


    def mouse_click(self,objectName):
        """Move mouse on top of the object and click on it"""

        obj = self.get_object(objectName)
        self.pointing_device.move_to_object(obj)
        self.pointing_device.click()


    def mouse_press(self,objectName):
        """Move mouse on top of the object and press mouse button (without releasing it)"""

        obj = self.get_object(objectName)
        self.pointing_device.move_to_object(obj)
        self.pointing_device.press()


    def mouse_release(self):
        """Release mouse button"""

        self.pointing_device.release()     


    def type_string(self, string):
        """Type a string with keyboard"""

        self.keyboard.type(string)


    def type_key(self, key):
        """Type a single key with keyboard"""

        self.keyboard.key(key)
        
    @property
    def main_view(self):
        return self.app.select_single(emulators.MainView)