First work-in-progress feature test.
This commit is contained in:
parent
7d17957e90
commit
ffc465e863
1
tests/integration/data/backforward/1.txt
Normal file
1
tests/integration/data/backforward/1.txt
Normal file
@ -0,0 +1 @@
|
||||
Hello
|
1
tests/integration/data/backforward/2.txt
Normal file
1
tests/integration/data/backforward/2.txt
Normal file
@ -0,0 +1 @@
|
||||
World
|
15
tests/integration/features/backforward.feature
Normal file
15
tests/integration/features/backforward.feature
Normal file
@ -0,0 +1,15 @@
|
||||
Feature: Going back and forward.
|
||||
Testing the :back/:forward commands.
|
||||
|
||||
Scenario: Going back/forward
|
||||
Given I open data/backforward/1.txt
|
||||
When I open data/backforward/2.txt
|
||||
And I run :back
|
||||
And I run :reload
|
||||
And I run :forward
|
||||
And I run :reload
|
||||
Then the requests should be:
|
||||
data/backforward/1.txt
|
||||
data/backforward/2.txt
|
||||
data/backforward/1.txt
|
||||
data/backforward/2.txt
|
54
tests/integration/features/test_features.py
Normal file
54
tests/integration/features/test_features.py
Normal file
@ -0,0 +1,54 @@
|
||||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||
|
||||
# Copyright 2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||
#
|
||||
# This file is part of qutebrowser.
|
||||
#
|
||||
# qutebrowser is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# qutebrowser is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest_bdd as bdd
|
||||
|
||||
bdd.scenarios('.')
|
||||
|
||||
|
||||
@bdd.given(bdd.parsers.parse("I set {sect} -> {opt} to {value}"))
|
||||
def set_setting(quteproc, sect, opt, value):
|
||||
quteproc.set_setting(sect, opt, value)
|
||||
|
||||
|
||||
@bdd.given(bdd.parsers.parse("I open {path}"))
|
||||
def open_path(quteproc, path):
|
||||
quteproc.open_path(path)
|
||||
|
||||
|
||||
@bdd.when(bdd.parsers.parse("I open {path}"))
|
||||
def open_path_when(quteproc, path):
|
||||
quteproc.open_path(path)
|
||||
|
||||
|
||||
@bdd.when(bdd.parsers.parse("I run {command}"))
|
||||
def run_command(quteproc, command):
|
||||
quteproc.send_cmd(command)
|
||||
|
||||
|
||||
@bdd.then(bdd.parsers.parse("{path} should be loaded"))
|
||||
def path_should_be_loaded(httpbin, path):
|
||||
requests = httpbin.get_requests()
|
||||
assert requests[-1] == ('GET', '/' + path)
|
||||
|
||||
|
||||
@bdd.then(bdd.parsers.parse("The requests should be:\n{pages}"))
|
||||
def lost_of_loaded_pages(httpbin, pages):
|
||||
requests = [('GET', '/' + path.strip()) for path in pages.split('\n')]
|
||||
assert httpbin.get_requests() == requests
|
@ -46,6 +46,7 @@ class QuteProc(testprocess.Process):
|
||||
|
||||
Attributes:
|
||||
_ipc_socket: The IPC socket of the started instance.
|
||||
_httpbin: The HTTPBin webserver.
|
||||
"""
|
||||
|
||||
LOG_RE = re.compile(r"""
|
||||
@ -57,9 +58,12 @@ class QuteProc(testprocess.Process):
|
||||
""", re.VERBOSE)
|
||||
|
||||
executing_command = pyqtSignal()
|
||||
setting_done = pyqtSignal()
|
||||
url_loaded = pyqtSignal()
|
||||
|
||||
def __init__(self, parent=None):
|
||||
def __init__(self, httpbin, parent=None):
|
||||
super().__init__(parent)
|
||||
self._httpbin = httpbin
|
||||
self._ipc_socket = None
|
||||
|
||||
def _parse_line(self, line):
|
||||
@ -78,6 +82,10 @@ class QuteProc(testprocess.Process):
|
||||
"<qutebrowser.browser.webview.WebView tab_id=0 "
|
||||
"url='about:blank'>: LoadStatus.success")
|
||||
|
||||
url_loaded_pattern = re.compile(
|
||||
r"load status for <qutebrowser.browser.webview.WebView tab_id=\d+ "
|
||||
r"url='[^']+'>: LoadStatus.success")
|
||||
|
||||
if (log_line.category == 'ipc' and
|
||||
log_line.message.startswith("Listening as ")):
|
||||
self._ipc_socket = log_line.message.split(' ', maxsplit=2)[2]
|
||||
@ -88,6 +96,12 @@ class QuteProc(testprocess.Process):
|
||||
log_line.module == 'command' and log_line.function == 'run' and
|
||||
log_line.message.startswith('Calling ')):
|
||||
self.executing_command.emit()
|
||||
elif (log_line.category == 'config' and log_line.message.startswith(
|
||||
'Config option changed: ')):
|
||||
self.setting_done.emit()
|
||||
elif (log_line.category == 'webview' and
|
||||
url_loaded_pattern.match(log_line.message)):
|
||||
self.url_loaded.emit()
|
||||
|
||||
return log_line
|
||||
|
||||
@ -115,16 +129,25 @@ class QuteProc(testprocess.Process):
|
||||
def send_cmd(self, command):
|
||||
assert self._ipc_socket is not None
|
||||
with self._wait_signal(self.executing_command):
|
||||
ipc.send_to_running_instance(self._ipc_socket, [':' + command],
|
||||
ipc.send_to_running_instance(self._ipc_socket, [command],
|
||||
target_arg='')
|
||||
# Wait a bit in cause the command triggers any error.
|
||||
time.sleep(0.5)
|
||||
|
||||
def set_setting(self, sect, opt, value):
|
||||
with self._wait_signal(self.setting_done):
|
||||
self.send_cmd(':set "{}" "{}" "{}"'.format(sect, opt, value))
|
||||
|
||||
def open_path(self, path):
|
||||
url = 'http://localhost:{}/{}'.format(self._httpbin.port, path)
|
||||
with self._wait_signal(self.url_loaded):
|
||||
self.send_cmd(':open ' + url)
|
||||
|
||||
|
||||
@pytest.yield_fixture(scope='session', autouse=True)
|
||||
def quteproc(qapp):
|
||||
def quteproc(qapp, httpbin):
|
||||
"""Fixture for qutebrowser process."""
|
||||
proc = QuteProc()
|
||||
proc = QuteProc(httpbin)
|
||||
proc.start()
|
||||
yield proc
|
||||
proc.cleanup()
|
||||
|
Loading…
Reference in New Issue
Block a user