import functools


def newTab(func):
    """
        Runs the function in a new tab, then closes and 
        switches back context once it finishes.
    """
    @functools.wraps(func)
    def nt(driver, *args, **kwargs):
        driver.execute_script("window.open('', '_blank')")
        oldWindow = driver.current_window_handle
        driver.switch_to_window(driver.window_handles[-1])

        func(driver, *args, **kwargs)
        driver.close()
        driver.switch_to_window(oldWindow)
    return nt