facebookarchive / huxley

A testing system for catching visual regressions in Web applications.
Apache License 2.0
4.07k stars 286 forks source link

Improve the `window._getHuxleyEvents is not a function` exception #3

Closed ratpik closed 11 years ago

ratpik commented 11 years ago

I am trying to get Huxley to work on a simple login flow where I enter the username/password and the page redirects to a different url after login. While I can capture the screenshots, when I hit q+enter I get the below error. Can I use huxley to test scenarios like these?

Note that Huxley works otherwise when I am testing a single page like the toggle example included.

Press enter to take a screenshot, or type Q+enter if you're done
q
Traceback (most recent call last):
  File "/usr/local/bin/huxley", line 9, in <module>
    load_entry_point('Huxley==0.2', 'console_scripts', 'huxley')()
  File "/usr/local/lib/python2.7/dist-packages/huxley/cmdline.py", line 126, in main
    sys.exit(plac.call(_main))
  File "/usr/local/lib/python2.7/dist-packages/plac_core.py", line 309, in call
    cmd, result = parser_from(obj).consume(arglist)
  File "/usr/local/lib/python2.7/dist-packages/plac_core.py", line 195, in consume
    return cmd, self.func(*(args + varargs + extraopts), **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/huxley/cmdline.py", line 105, in _main
    record=True
  File "/usr/local/lib/python2.7/dist-packages/huxley/main.py", line 109, in main
    TestRun.record(local_d, d, (url, postdata), screensize, filename, diffcolor, sleepfactor, save_diff)
  File "/usr/local/lib/python2.7/dist-packages/huxley/run.py", line 127, in record
    events = d.execute_script('return window._getHuxleyEvents();')
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 397, in execute_script
    {'script': script, 'args':converted_args})['value']
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 165, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 152, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: u"window._getHuxleyEvents is not a function\nBuild info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:32:38'\nSystem info: os.name: 'Linux', os.arch: 'i386', os.version: '3.5.0-36-generic', java.version: '1.7.0_25'\nDriver info: driver.version: unknown" ; Screenshot: available via screen ; Stacktrace: Method anonymous threw an error in http://localhost:8000/<redirected-url>
petehunt commented 11 years ago

So the issue here is that you're trying to navigate to a new page and currently Huxley doesn't support it. We could build this feature though. Normally we set up test pages and don't require navigating from page to page. Does your use case require us to build this feature? We can, but it'll be a little ugly.

ratpik commented 11 years ago

Well navigation would be a good feature to have. More importantly, would Huxley work with urls that require authentication? My first use case was to test a new user signup/login flow which requires both authentication and re-direction.

This can all be done via configuration as long as Huxley respects cookie based sessions.

jacobangel commented 11 years ago

I have to disagree. I tried to add multiple steps to my tests the first time I popped up a script. I was a bit confused by the error, but after some reflection it made sense. I (speaking with limited experience) think I would be hesitant to provide the navigation feature, since doing so kind of attacks the 'soul' of the project.

Huxley is asking you to try to test your components independently, falling closer to unit tests side of things than integration test. Restricting navigation implicitly keep your tests 'more honest'. If anything, I think that it'd be better if Huxley threw a better error upon navigation, since this is probably going to be a common misconception, and the error is a bit unintuitive to understand.

ratpik commented 11 years ago

That does make sense. I might have confused Huxley with an integration testing tool as opposed to a unit testing one.

petehunt commented 11 years ago

@ratpik I think the difference between "unit testing" and "integration testing" tends to be simply characterized by the size of the unit being tested. I think Huxley probably qualifies as an integration test of the front-end unit of your project. Regardless, I'll make this error message better.

petehunt commented 11 years ago

Fixed in bbae0729e527f64eaa2f2656cb1f5346285a7dfe