Python: Reproduce Splinter/ Selenium Behaviour for Testing a Website That Uses Javascript
<p>I have a bot which interacts with a website using Splinter and Selenium. The website uses Javascript and updates in real time. The bot works well 90% of the time, but due to random events it will sometimes raise an Exception. It is very hard for me to debug these events, by the time I am in the debugger the website has changed. </p>

<p>Is there anyway I can record the website data and play it back, like with vcrpy? Or is there anyway I can record the behaviour so I can debug and test? </p>

<p>Closest thing you can do is to take screen shots of web page on various events. You will have to use EventFiringWebDriver. Whichever even you want to take screen shot call <code>screen_shot</code> function there.</p>

<pre><code>from selenium.webdriver.support.events import EventFiringWebDriver
from selenium.webdriver.support.events import AbstractEventListener
import os
import time
class ScreenShotListener(AbstractEventListener):
    DIR_NAME = None
    def screen_shot(self, driver):
        dir = os.path.curdir
        unique_filename = str(int(time.time() * 1000)) + ".png"
        fpath = os.path.join(dir, unique_filename)
        driver.get_screenshot_as_file(fpath)

    def before_navigate_to(self, url, driver):
        pass

    def after_navigate_to(self, url, driver):
        pass

    def before_navigate_back(self, driver):
        pass

    def after_navigate_back(self, driver):
        pass

    def before_navigate_forward(self, driver):
        pass

    def after_navigate_forward(self, driver):
        pass

    def before_find(self, by, value, driver):
        pass

    def after_find(self, by, value, driver):
        pass

    def before_click(self, element, driver):
        pass

    def after_click(self, element, driver):
        pass

    def before_change_value_of(self, element, driver):
        pass

    def after_change_value_of(self, element, driver):
        pass

    def before_execute_script(self, script, driver):
        pass

    def after_execute_script(self, script, driver):
        pass

    def before_close(self, driver):
        pass

    def after_close(self, driver):
        pass

    def before_quit(self, driver):
        pass

    def after_quit(self, driver):
        pass

    def on_exception(self, exception, driver):
        pass

driver = EventFiringWebDriver(driver, ScreenShotListener())
</code></pre>

javascript python selenium splinter