Plays a Bootstrap tour on the current website.

def play_bootstrap_tour(
        driver, tour_steps, browser, msg_dur, name=None, interval=0):
    """ Plays a Bootstrap tour on the current website. """
    instructions = ""
    for tour_step in tour_steps[name]:
        instructions += tour_step
    instructions += (
        """]);
        // Initialize the tour
        tour.init();
        // Start the tour
        tour.start();
        // Fix timing issue by restarting tour immediately
        tour.restart();
        // Save for later
        $tour = tour;""")

    if interval and interval > 0:
        if interval < 1:
            interval = 1
        interval = str(float(interval) * 1000.0)
        instructions = instructions.replace(
            'duration: 0,', 'duration: %s,' % interval)

    if not is_bootstrap_activated(driver):
        activate_bootstrap(driver)

    if len(tour_steps[name]) > 1:
        try:
            if "element: " in tour_steps[name][1]:
                selector = re.search(
                    r"[\S\s]+element: '([\S\s]+)',[\S\s]+title: '",
                    tour_steps[name][1]).group(1)
                selector = selector.replace('\\', '').replace(':first', '')
                page_actions.wait_for_element_present(
                    driver, selector, by=By.CSS_SELECTOR,
                    timeout=settings.SMALL_TIMEOUT)
            else:
                selector = "html"
        except Exception:
            js_utils.post_messenger_error_message(
                driver, "Tour Error: {'%s'} was not found!" % selector,
                msg_dur)
            raise Exception(
                "Tour Error: {'%s'} was not found! "
                "Exiting due to failure on first tour step!"
                "" % selector)

    driver.execute_script(instructions)
    tour_on = True
    while tour_on:
        try:
            time.sleep(0.01)
            if browser != "firefox":
                result = driver.execute_script(
                    "return $tour.ended()")
            else:
                page_actions.wait_for_element_present(
                    driver, ".tour-tour", by=By.CSS_SELECTOR, timeout=0.4)
                result = False
        except Exception:
            tour_on = False
            result = None
        if result is False:
            tour_on = True
        else:
            try:
                time.sleep(0.01)
                if browser != "firefox":
                    result = driver.execute_script(
                        "return $tour.ended()")
                else:
                    page_actions.wait_for_element_present(
                        driver, ".tour-tour", by=By.CSS_SELECTOR, timeout=0.4)
                    result = False
                if result is False:
                    time.sleep(0.1)
                    continue
                else:
                    return
            except Exception:
                tour_on = False
                time.sleep(0.1)