bdd: Add "When I open ... in a new window" step.

This commit is contained in:
Florian Bruhin 2016-01-07 08:20:48 +01:00
parent f9645e447a
commit 18b5860584
2 changed files with 16 additions and 4 deletions

View File

@ -98,17 +98,24 @@ def fresh_instance(quteproc):
def open_path(quteproc, path):
"""Open a URL.
If used like "When I open ... in a new tab", the URL is opened ina new
tab.
If used like "When I open ... in a new tab", the URL is opened in a new
tab. With "... in a new window", it's opened in a new window.
"""
new_tab_suffix = ' in a new tab'
new_window_suffix = ' in a new window'
if path.endswith(new_tab_suffix):
path = path[:-len(new_tab_suffix)]
new_tab = True
new_window = False
elif path.endswith(new_window_suffix):
path = path[:-len(new_window_suffix)]
new_tab = False
new_window = True
else:
new_tab = False
new_window = False
quteproc.open_path(path, new_tab=new_tab)
quteproc.open_path(path, new_tab=new_tab, new_window=new_window)
@bdd.when(bdd.parsers.parse("I set {sect} -> {opt} to {value}"))

View File

@ -269,11 +269,16 @@ class QuteProc(testprocess.Process):
yield
self.set_setting(sect, opt, old_value)
def open_path(self, path, new_tab=False):
def open_path(self, path, new_tab=False, new_window=False):
"""Open the given path on the local webserver in qutebrowser."""
if new_tab and new_window:
raise ValueError("new_tab and new_window given!")
url = self.path_to_url(path)
if new_tab:
self.send_cmd(':open -t ' + url)
elif new_window:
self.send_cmd(':open -w ' + url)
else:
self.send_cmd(':open ' + url)
self.wait_for_load_finished(path)