-2

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.

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?

Will Beauchamp
  • 579
  • 2
  • 7
  • 18

1 Answers1

0

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 screen_shot function there.

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())
saurabh baid
  • 1,819
  • 1
  • 14
  • 26
  • How be sure a exception raised ? Maybe a security chain broken or got missing ACK query. – dsgdfg Sep 26 '16 at 05:50
  • I did not understand your question/concern completely – saurabh baid Sep 26 '16 at 05:54
  • Mean , most webbot error is `None` values / RPC triggers . Webbots are illegal ! Can't explain on public area ! – dsgdfg Sep 26 '16 at 06:01
  • Its just the events, so the way I am using it taking screen shot on alomost every event like click, find and not only at the exception. So that way I would get screen shot recording of my entire execution. This would cost some disk space though. – saurabh baid Sep 26 '16 at 06:05
  • This really doesn't address the issue of debugging/ testing. I need to capture the entire state of the webpage. – Will Beauchamp Sep 27 '16 at 09:22
  • Do you want to record HTTP transactions? – saurabh baid Sep 27 '16 at 10:33
  • If you wan to record http transactions then take a look at https://eveningsamurai.wordpress.com/2013/06/29/capturing-network-traffic-using-selenium-webdriverfirebug/ – saurabh baid Sep 27 '16 at 10:44